diff --git a/app/os_unix.go b/app/os_unix.go index c834b6e1..258f9e24 100644 --- a/app/os_unix.go +++ b/app/os_unix.go @@ -10,13 +10,33 @@ import ( "unsafe" ) -type ViewEvent struct { +// ViewEvent provides handles to the underlying window objects for the +// current display protocol. +type ViewEvent interface { + implementsViewEvent() + ImplementsEvent() +} + +type X11ViewEvent struct { // Display is a pointer to the X11 Display created by XOpenDisplay. Display unsafe.Pointer // Window is the X11 window ID as returned by XCreateWindow. Window uintptr } +func (X11ViewEvent) implementsViewEvent() {} +func (X11ViewEvent) ImplementsEvent() {} + +type WaylandViewEvent struct { + // Display is the *wl_display returned by wl_display_connect. + Display unsafe.Pointer + // Surface is the *wl_surface returned by wl_compositor_create_surface. + Surface unsafe.Pointer +} + +func (WaylandViewEvent) implementsViewEvent() {} +func (WaylandViewEvent) ImplementsEvent() {} + func osMain() { select {} } @@ -46,5 +66,3 @@ func newWindow(window *callbacks, options []Option) error { } return errors.New("app: no window driver available") } - -func (_ ViewEvent) ImplementsEvent() {} diff --git a/app/os_wayland.go b/app/os_wayland.go index 840aa006..30be4ce1 100644 --- a/app/os_wayland.go +++ b/app/os_wayland.go @@ -248,12 +248,19 @@ func newWLWindow(callbacks *callbacks, options []Option) error { defer w.destroy() w.w.SetDriver(w) + // Finish and commit setup from createNativeWindow. w.Configure(options) C.wl_surface_commit(w.surf) - if err := w.loop(); err != nil { - panic(err) - } + + w.w.Event(WaylandViewEvent{ + Display: unsafe.Pointer(w.display()), + Surface: unsafe.Pointer(w.surf), + }) + defer w.w.Event(WaylandViewEvent{}) + + err := w.loop() + w.w.Event(system.DestroyEvent{Err: err}) }() return nil } @@ -1308,7 +1315,6 @@ func (w *window) loop() error { default: } if w.dead { - w.w.Event(system.DestroyEvent{}) break } w.draw() diff --git a/app/os_x11.go b/app/os_x11.go index 90e1c394..0e26c795 100644 --- a/app/os_x11.go +++ b/app/os_x11.go @@ -813,10 +813,10 @@ func newX11Window(gioWin *callbacks, options []Option) error { // make the window visible on the screen C.XMapWindow(dpy, win) w.Configure(options) - w.w.Event(ViewEvent{Display: unsafe.Pointer(dpy), Window: uintptr(win)}) + w.w.Event(X11ViewEvent{Display: unsafe.Pointer(dpy), Window: uintptr(win)}) w.setStage(system.StageRunning) w.loop() - w.w.Event(ViewEvent{}) + w.w.Event(X11ViewEvent{}) w.destroy() }() return nil