diff --git a/app/os.go b/app/os.go index 012153c0..8979ee33 100644 --- a/app/os.go +++ b/app/os.go @@ -162,8 +162,6 @@ type driver interface { Configure([]Option) // SetCursor updates the current cursor to name. SetCursor(cursor pointer.Cursor) - // Close the window. - Close() // Wakeup wakes up the event loop and sends a WakeupEvent. Wakeup() // Perform actions on the window. diff --git a/app/os_android.go b/app/os_android.go index 163927eb..4845fd3e 100644 --- a/app/os_android.go +++ b/app/os_android.go @@ -1414,9 +1414,6 @@ func setNavigationColor(env *C.JNIEnv, view C.jobject, color color.NRGBA) { ) } -// Close the window. Not implemented for Android. -func (w *window) Close() {} - // runOnMain runs a function on the Java main thread. func runOnMain(f func(env *C.JNIEnv)) { go func() { diff --git a/app/os_ios.go b/app/os_ios.go index c381dc1c..f88c2c3a 100644 --- a/app/os_ios.go +++ b/app/os_ios.go @@ -346,9 +346,6 @@ func (w *window) ShowTextInput(show bool) { func (w *window) SetInputHint(_ key.InputHint) {} -// Close the window. Not implemented for iOS. -func (w *window) Close() {} - func newWindow(win *callbacks, options []Option) error { mainWindow.in <- windowAndConfig{win, options} return <-mainWindow.errs diff --git a/app/os_js.go b/app/os_js.go index 23e68ff9..614441d3 100644 --- a/app/os_js.go +++ b/app/os_js.go @@ -597,9 +597,6 @@ func (w *window) SetInputHint(mode key.InputHint) { w.keyboard(mode) } -// Close the window. Not implemented for js. -func (w *window) Close() {} - func (w *window) resize() { w.scale = float32(w.window.Get("devicePixelRatio").Float()) diff --git a/app/os_macos.go b/app/os_macos.go index d606617f..b1ddf661 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -375,6 +375,9 @@ func (w *window) Perform(acts system.Action) { C.raiseWindow(w.window) } }) + if acts&system.ActionClose != 0 { + C.closeWindow(w.window) + } } func (w *window) SetCursor(cursor pointer.Cursor) { @@ -413,10 +416,6 @@ func (w *window) runOnMain(f func()) { }) } -func (w *window) Close() { - C.closeWindow(w.window) -} - func (w *window) setStage(stage system.Stage) { if stage == w.stage { return diff --git a/app/os_wayland.go b/app/os_wayland.go index b2115db8..c795e089 100644 --- a/app/os_wayland.go +++ b/app/os_wayland.go @@ -1034,6 +1034,8 @@ func (w *window) Perform(actions system.Action) { switch action { case system.ActionMove: w.move() + case system.ActionClose: + w.dead = true default: w.resize(action) } @@ -1627,11 +1629,6 @@ func (w *window) SetInputHint(_ key.InputHint) {} func (w *window) EditorStateChanged(old, new editorState) {} -// Close the window. -func (w *window) Close() { - w.dead = true -} - func (w *window) NewContext() (context, error) { var firstErr error if f := newWaylandVulkanContext; f != nil { diff --git a/app/os_windows.go b/app/os_windows.go index 704aa6b8..c05f36c2 100644 --- a/app/os_windows.go +++ b/app/os_windows.go @@ -753,10 +753,6 @@ func (w *window) HWND() (syscall.Handle, int, int) { return w.hwnd, w.config.Size.X, w.config.Size.Y } -func (w *window) Close() { - windows.PostMessage(w.hwnd, windows.WM_CLOSE, 0, 0) -} - func (w *window) Perform(acts system.Action) { walkActions(acts, func(a system.Action) { switch a { @@ -774,6 +770,8 @@ func (w *window) Perform(acts system.Action) { windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOOWNERZORDER|windows.SWP_FRAMECHANGED) case system.ActionRaise: w.raise() + case system.ActionClose: + windows.PostMessage(w.hwnd, windows.WM_CLOSE, 0, 0) } }) } diff --git a/app/os_x11.go b/app/os_x11.go index cc753084..6d5cb3a0 100644 --- a/app/os_x11.go +++ b/app/os_x11.go @@ -266,6 +266,9 @@ func (w *x11Window) Perform(acts system.Action) { w.raise() } }) + if acts&system.ActionClose != 0 { + w.close() + } } func (w *x11Window) center() { @@ -331,8 +334,8 @@ func (w *x11Window) SetInputHint(_ key.InputHint) {} func (w *x11Window) EditorStateChanged(old, new editorState) {} -// Close the window. -func (w *x11Window) Close() { +// close the window. +func (w *x11Window) close() { var xev C.XEvent ev := (*C.XClientMessageEvent)(unsafe.Pointer(&xev)) *ev = C.XClientMessageEvent{ diff --git a/app/window.go b/app/window.go index 641e7c01..fbe43ad1 100644 --- a/app/window.go +++ b/app/window.go @@ -456,25 +456,10 @@ func (c *callbacks) Event(e event.Event) bool { c.waitEvents = c.waitEvents[:len(c.waitEvents)-1] handled = c.w.processEvent(c.d, e) } - closing := false - if _, iswakeup := e.(wakeupEvent); iswakeup { - select { - case opts := <-c.w.options: - c.d.Configure(opts) - default: - } - select { - case acts := <-c.w.actions: - // Pospone closing to last. - closing = (acts & system.ActionClose) != 0 - acts &^= system.ActionClose - c.d.Perform(acts) - default: - } - } - c.w.updateState(c.d) - if closing { - c.d.Close() + select { + case <-c.w.dead: + default: + c.w.updateState(c.d) } return handled } @@ -867,6 +852,16 @@ func (w *Window) processEvent(d driver, e event.Event) bool { w.out <- e2 w.waitAck(d) case wakeupEvent: + select { + case opts := <-w.options: + d.Configure(opts) + default: + } + select { + case acts := <-w.actions: + d.Perform(acts) + default: + } case ConfigEvent: w.decorations.Config = e2.Config if !w.fallbackDecorate() {