Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shiny/x11driver: handle the case of X server connection closed #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions shiny/driver/x11driver/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package x11driver

import (
"errors"
"fmt"
"image"
"image/color"
Expand All @@ -28,6 +29,8 @@ import (
// For example, its Conn.WaitForEvent concept is a method, not a channel, so
// it's not obvious how to interrupt it to service a NewWindow request.

var XConnectionClosed = errors.New("x11driver: X server connection closed")

type screenImpl struct {
xc *xgb.Conn
xsi *xproto.ScreenInfo
Expand Down Expand Up @@ -125,6 +128,11 @@ func (s *screenImpl) run() {

noWindowFound := false
switch ev := ev.(type) {
case nil:
s.xc = nil
log.Printf("x11driver: X server connection closed")
return

case xproto.DestroyNotifyEvent:
s.mu.Lock()
delete(s.windows, ev.Window)
Expand Down Expand Up @@ -284,6 +292,9 @@ const (
)

func (s *screenImpl) NewBuffer(size image.Point) (retBuf screen.Buffer, retErr error) {
if s.xc == nil {
return nil, XConnectionClosed
}

w, h := int64(size.X), int64(size.Y)
if w < 0 || maxShmSide < w || h < 0 || maxShmSide < h || maxShmSize < 4*w*h {
Expand Down Expand Up @@ -354,6 +365,9 @@ func (s *screenImpl) NewBuffer(size image.Point) (retBuf screen.Buffer, retErr e
}

func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) {
if s.xc == nil {
return nil, XConnectionClosed
}
w, h := int64(size.X), int64(size.Y)
if w < 0 || maxShmSide < w || h < 0 || maxShmSide < h || maxShmSize < 4*w*h {
return nil, fmt.Errorf("x11driver: invalid texture size %v", size)
Expand Down Expand Up @@ -391,6 +405,10 @@ func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) {
}

func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
if s.xc == nil {
return nil, XConnectionClosed
}

width, height := 1024, 768
if opts != nil {
if opts.Width > 0 {
Expand Down Expand Up @@ -654,6 +672,10 @@ func (s *screenImpl) setProperty(xw xproto.Window, prop xproto.Atom, values ...x
}

func (s *screenImpl) drawUniform(xp render.Picture, src2dst *f64.Aff3, src color.Color, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) {
if s.xc == nil {
return
}

if sr.Empty() {
return
}
Expand Down