app/internal/window: [Wayland] move notification channel to wlDisplay

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-15 19:23:18 +02:00
parent 55881fc09c
commit 26641344bc
+32 -32
View File
@@ -73,6 +73,11 @@ type wlDisplay struct {
outputMap map[C.uint32_t]*C.struct_wl_output outputMap map[C.uint32_t]*C.struct_wl_output
outputConfig map[*C.struct_wl_output]*wlOutput outputConfig map[*C.struct_wl_output]*wlOutput
// Notification pipe fds.
notify struct {
read, write int
}
repeat repeatState repeat repeatState
} }
@@ -105,16 +110,12 @@ type repeatState struct {
} }
type window struct { type window struct {
w Callbacks w Callbacks
disp *wlDisplay disp *wlDisplay
surf *C.struct_wl_surface surf *C.struct_wl_surface
wmSurf *C.struct_xdg_surface wmSurf *C.struct_xdg_surface
topLvl *C.struct_xdg_toplevel topLvl *C.struct_xdg_toplevel
decor *C.struct_zxdg_toplevel_decoration_v1 decor *C.struct_zxdg_toplevel_decoration_v1
// Notification pipe fds.
notify struct {
read, write int
}
ppdp, ppsp float32 ppdp, ppsp float32
scroll struct { scroll struct {
time time.Duration time time.Duration
@@ -195,11 +196,6 @@ func newWLWindow(window Callbacks, opts *Options) error {
} }
func (d *wlDisplay) createNativeWindow(opts *Options) (*window, error) { func (d *wlDisplay) createNativeWindow(opts *Options) (*window, error) {
pipe := make([]int, 2)
if err := syscall.Pipe2(pipe, syscall.O_NONBLOCK|syscall.O_CLOEXEC); err != nil {
return nil, fmt.Errorf("createNativeWindow: failed to create pipe: %v", err)
}
var scale int var scale int
for _, conf := range d.outputConfig { for _, conf := range d.outputConfig {
if s := conf.scale; s > scale { if s := conf.scale; s > scale {
@@ -215,8 +211,6 @@ func (d *wlDisplay) createNativeWindow(opts *Options) (*window, error) {
ppdp: ppdp, ppdp: ppdp,
ppsp: ppdp, ppsp: ppdp,
} }
w.notify.read = pipe[0]
w.notify.write = pipe[1]
w.surf = C.wl_compositor_create_surface(d.compositor) w.surf = C.wl_compositor_create_surface(d.compositor)
if w.surf == nil { if w.surf == nil {
w.destroy() w.destroy()
@@ -652,7 +646,7 @@ func (w *window) flushFling() {
w.fling.dir.X = estx.Velocity * invDist w.fling.dir.X = estx.Velocity * invDist
w.fling.dir.Y = esty.Velocity * invDist w.fling.dir.Y = esty.Velocity * invDist
// Wake up the window loop. // Wake up the window loop.
w.wakeup() w.disp.wakeup()
} }
//export gio_onPointerAxisSource //export gio_onPointerAxisSource
@@ -762,7 +756,7 @@ func (r *repeatState) Start(w *window, keyCode uint32, t time.Duration) {
return return
} }
r.Advance(delay) r.Advance(delay)
w.wakeup() w.disp.wakeup()
delay = time.Second / time.Duration(rate) delay = time.Second / time.Duration(rate)
timer.Reset(delay) timer.Reset(delay)
} }
@@ -827,7 +821,7 @@ func (w *window) loop() {
// Poll for events and notifications. // Poll for events and notifications.
pollfds := []syscall.PollFd{ pollfds := []syscall.PollFd{
{Fd: int32(dispfd), Events: syscall.POLLIN | syscall.POLLERR}, {Fd: int32(dispfd), Events: syscall.POLLIN | syscall.POLLERR},
{Fd: int32(w.notify.read), Events: syscall.POLLIN | syscall.POLLERR}, {Fd: int32(w.disp.notify.read), Events: syscall.POLLIN | syscall.POLLERR},
} }
dispFd := &pollfds[0] dispFd := &pollfds[0]
// Plenty of room for a backlog of notifications. // Plenty of room for a backlog of notifications.
@@ -855,7 +849,7 @@ loop:
redraw := false redraw := false
// Clear notifications. // Clear notifications.
for { for {
_, err := syscall.Read(w.notify.read, buf) _, err := syscall.Read(w.disp.notify.read, buf)
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
break break
} }
@@ -886,27 +880,19 @@ func (w *window) SetAnimating(anim bool) {
animating := w.isAnimating() animating := w.isAnimating()
w.mu.Unlock() w.mu.Unlock()
if animating { if animating {
w.wakeup() w.disp.wakeup()
} }
} }
// Wakeup wakes up the event loop through the notification pipe. // Wakeup wakes up the event loop through the notification pipe.
func (w *window) wakeup() { func (d *wlDisplay) wakeup() {
oneByte := make([]byte, 1) oneByte := make([]byte, 1)
if _, err := syscall.Write(w.notify.write, oneByte); err != nil && err != syscall.EAGAIN { if _, err := syscall.Write(d.notify.write, oneByte); err != nil && err != syscall.EAGAIN {
panic(fmt.Errorf("failed to write to pipe: %v", err)) panic(fmt.Errorf("failed to write to pipe: %v", err))
} }
} }
func (w *window) destroy() { func (w *window) destroy() {
if w.notify.write != 0 {
syscall.Close(w.notify.write)
w.notify.write = 0
}
if w.notify.read != 0 {
syscall.Close(w.notify.read)
w.notify.read = 0
}
if w.topLvl != nil { if w.topLvl != nil {
C.xdg_toplevel_destroy(w.topLvl) C.xdg_toplevel_destroy(w.topLvl)
} }
@@ -1140,6 +1126,12 @@ func newWLDisplay() (*wlDisplay, error) {
outputMap: make(map[C.uint32_t]*C.struct_wl_output), outputMap: make(map[C.uint32_t]*C.struct_wl_output),
outputConfig: make(map[*C.struct_wl_output]*wlOutput), outputConfig: make(map[*C.struct_wl_output]*wlOutput),
} }
pipe := make([]int, 2)
if err := syscall.Pipe2(pipe, syscall.O_NONBLOCK|syscall.O_CLOEXEC); err != nil {
return nil, fmt.Errorf("wayland: failed to create pipe: %v", err)
}
d.notify.read = pipe[0]
d.notify.write = pipe[1]
xkb, err := xkb.New() xkb, err := xkb.New()
if err != nil { if err != nil {
d.destroy() d.destroy()
@@ -1202,6 +1194,14 @@ func newWLDisplay() (*wlDisplay, error) {
} }
func (d *wlDisplay) destroy() { func (d *wlDisplay) destroy() {
if d.notify.write != 0 {
syscall.Close(d.notify.write)
d.notify.write = 0
}
if d.notify.read != 0 {
syscall.Close(d.notify.read)
d.notify.read = 0
}
d.repeat.Stop(0) d.repeat.Stop(0)
if d.xkb != nil { if d.xkb != nil {
d.xkb.Destroy() d.xkb.Destroy()