mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app: [Android] Send focus lost event when the window is backgrounded
Fixes: https://todo.sr.ht/~eliasnaur/gio/679 Signed-off-by: CoyAce <AkeyCoy@gmail.com> Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+13
-4
@@ -162,6 +162,7 @@ type window struct {
|
||||
insets pixelInsets
|
||||
|
||||
visible bool
|
||||
focused bool
|
||||
started bool
|
||||
animating bool
|
||||
|
||||
@@ -529,6 +530,7 @@ func Java_org_gioui_GioView_onStopView(env *C.JNIEnv, class C.jclass, handle C.j
|
||||
w := cgo.Handle(handle).Value().(*window)
|
||||
w.started = false
|
||||
w.visible = false
|
||||
w.sendConfigEvent()
|
||||
}
|
||||
|
||||
//export Java_org_gioui_GioView_onStartView
|
||||
@@ -545,6 +547,7 @@ func Java_org_gioui_GioView_onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, ha
|
||||
w := cgo.Handle(handle).Value().(*window)
|
||||
w.win = nil
|
||||
w.visible = false
|
||||
w.sendConfigEvent()
|
||||
}
|
||||
|
||||
//export Java_org_gioui_GioView_onSurfaceChanged
|
||||
@@ -590,8 +593,8 @@ func Java_org_gioui_GioView_onBack(env *C.JNIEnv, class C.jclass, view C.jlong)
|
||||
//export Java_org_gioui_GioView_onFocusChange
|
||||
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
|
||||
w := cgo.Handle(view).Value().(*window)
|
||||
w.config.Focused = focus == C.JNI_TRUE
|
||||
w.processEvent(ConfigEvent{Config: w.config})
|
||||
w.focused = focus == C.JNI_TRUE
|
||||
w.sendConfigEvent()
|
||||
}
|
||||
|
||||
//export Java_org_gioui_GioView_onWindowInsets
|
||||
@@ -817,9 +820,15 @@ func (w *window) setVisible(env *C.JNIEnv) {
|
||||
return
|
||||
}
|
||||
w.visible = true
|
||||
w.sendConfigEvent()
|
||||
w.draw(env, true)
|
||||
}
|
||||
|
||||
func (w *window) sendConfigEvent() {
|
||||
w.config.Focused = w.visible && w.focused
|
||||
w.processEvent(ConfigEvent{Config: w.config})
|
||||
}
|
||||
|
||||
func (w *window) setVisual(visID int) error {
|
||||
if C.ANativeWindow_setBuffersGeometry(w.win, 0, 0, C.int32_t(visID)) != 0 {
|
||||
return errors.New("ANativeWindow_setBuffersGeometry failed")
|
||||
@@ -862,7 +871,7 @@ func (w *window) draw(env *C.JNIEnv, sync bool) {
|
||||
size := image.Pt(int(C.ANativeWindow_getWidth(w.win)), int(C.ANativeWindow_getHeight(w.win)))
|
||||
if size != w.config.Size {
|
||||
w.config.Size = size
|
||||
w.processEvent(ConfigEvent{Config: w.config})
|
||||
w.sendConfigEvent()
|
||||
}
|
||||
if size.X == 0 || size.Y == 0 {
|
||||
return
|
||||
@@ -1398,7 +1407,7 @@ func (w *window) setConfig(env *C.JNIEnv, cnf Config) {
|
||||
if cnf.Decorated != prev.Decorated {
|
||||
w.config.Decorated = cnf.Decorated
|
||||
}
|
||||
w.processEvent(ConfigEvent{Config: w.config})
|
||||
w.sendConfigEvent()
|
||||
}
|
||||
|
||||
func (w *window) Perform(system.Action) {}
|
||||
|
||||
Reference in New Issue
Block a user