app: replace driver.Close with Perform(ActionClose)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-06-23 14:31:44 +02:00
parent 43116400d0
commit 371de3462b
9 changed files with 26 additions and 45 deletions
-2
View File
@@ -162,8 +162,6 @@ type driver interface {
Configure([]Option) Configure([]Option)
// SetCursor updates the current cursor to name. // SetCursor updates the current cursor to name.
SetCursor(cursor pointer.Cursor) SetCursor(cursor pointer.Cursor)
// Close the window.
Close()
// Wakeup wakes up the event loop and sends a WakeupEvent. // Wakeup wakes up the event loop and sends a WakeupEvent.
Wakeup() Wakeup()
// Perform actions on the window. // Perform actions on the window.
-3
View File
@@ -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. // runOnMain runs a function on the Java main thread.
func runOnMain(f func(env *C.JNIEnv)) { func runOnMain(f func(env *C.JNIEnv)) {
go func() { go func() {
-3
View File
@@ -346,9 +346,6 @@ func (w *window) ShowTextInput(show bool) {
func (w *window) SetInputHint(_ key.InputHint) {} func (w *window) SetInputHint(_ key.InputHint) {}
// Close the window. Not implemented for iOS.
func (w *window) Close() {}
func newWindow(win *callbacks, options []Option) error { func newWindow(win *callbacks, options []Option) error {
mainWindow.in <- windowAndConfig{win, options} mainWindow.in <- windowAndConfig{win, options}
return <-mainWindow.errs return <-mainWindow.errs
-3
View File
@@ -597,9 +597,6 @@ func (w *window) SetInputHint(mode key.InputHint) {
w.keyboard(mode) w.keyboard(mode)
} }
// Close the window. Not implemented for js.
func (w *window) Close() {}
func (w *window) resize() { func (w *window) resize() {
w.scale = float32(w.window.Get("devicePixelRatio").Float()) w.scale = float32(w.window.Get("devicePixelRatio").Float())
+3 -4
View File
@@ -375,6 +375,9 @@ func (w *window) Perform(acts system.Action) {
C.raiseWindow(w.window) C.raiseWindow(w.window)
} }
}) })
if acts&system.ActionClose != 0 {
C.closeWindow(w.window)
}
} }
func (w *window) SetCursor(cursor pointer.Cursor) { 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) { func (w *window) setStage(stage system.Stage) {
if stage == w.stage { if stage == w.stage {
return return
+2 -5
View File
@@ -1034,6 +1034,8 @@ func (w *window) Perform(actions system.Action) {
switch action { switch action {
case system.ActionMove: case system.ActionMove:
w.move() w.move()
case system.ActionClose:
w.dead = true
default: default:
w.resize(action) w.resize(action)
} }
@@ -1627,11 +1629,6 @@ func (w *window) SetInputHint(_ key.InputHint) {}
func (w *window) EditorStateChanged(old, new editorState) {} func (w *window) EditorStateChanged(old, new editorState) {}
// Close the window.
func (w *window) Close() {
w.dead = true
}
func (w *window) NewContext() (context, error) { func (w *window) NewContext() (context, error) {
var firstErr error var firstErr error
if f := newWaylandVulkanContext; f != nil { if f := newWaylandVulkanContext; f != nil {
+2 -4
View File
@@ -753,10 +753,6 @@ func (w *window) HWND() (syscall.Handle, int, int) {
return w.hwnd, w.config.Size.X, w.config.Size.Y 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) { func (w *window) Perform(acts system.Action) {
walkActions(acts, func(a system.Action) { walkActions(acts, func(a system.Action) {
switch a { 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) windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOOWNERZORDER|windows.SWP_FRAMECHANGED)
case system.ActionRaise: case system.ActionRaise:
w.raise() w.raise()
case system.ActionClose:
windows.PostMessage(w.hwnd, windows.WM_CLOSE, 0, 0)
} }
}) })
} }
+5 -2
View File
@@ -266,6 +266,9 @@ func (w *x11Window) Perform(acts system.Action) {
w.raise() w.raise()
} }
}) })
if acts&system.ActionClose != 0 {
w.close()
}
} }
func (w *x11Window) center() { func (w *x11Window) center() {
@@ -331,8 +334,8 @@ func (w *x11Window) SetInputHint(_ key.InputHint) {}
func (w *x11Window) EditorStateChanged(old, new editorState) {} func (w *x11Window) EditorStateChanged(old, new editorState) {}
// Close the window. // close the window.
func (w *x11Window) Close() { func (w *x11Window) close() {
var xev C.XEvent var xev C.XEvent
ev := (*C.XClientMessageEvent)(unsafe.Pointer(&xev)) ev := (*C.XClientMessageEvent)(unsafe.Pointer(&xev))
*ev = C.XClientMessageEvent{ *ev = C.XClientMessageEvent{
+14 -19
View File
@@ -456,25 +456,10 @@ func (c *callbacks) Event(e event.Event) bool {
c.waitEvents = c.waitEvents[:len(c.waitEvents)-1] c.waitEvents = c.waitEvents[:len(c.waitEvents)-1]
handled = c.w.processEvent(c.d, e) handled = c.w.processEvent(c.d, e)
} }
closing := false select {
if _, iswakeup := e.(wakeupEvent); iswakeup { case <-c.w.dead:
select { default:
case opts := <-c.w.options: c.w.updateState(c.d)
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()
} }
return handled return handled
} }
@@ -867,6 +852,16 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
w.out <- e2 w.out <- e2
w.waitAck(d) w.waitAck(d)
case wakeupEvent: case wakeupEvent:
select {
case opts := <-w.options:
d.Configure(opts)
default:
}
select {
case acts := <-w.actions:
d.Perform(acts)
default:
}
case ConfigEvent: case ConfigEvent:
w.decorations.Config = e2.Config w.decorations.Config = e2.Config
if !w.fallbackDecorate() { if !w.fallbackDecorate() {