app: [android] remove redundant ConfigEvent in onStop and onSurfaceDestroyed

Config.Focused represents window interaction focus, which should only
change when the window gains or loses user interaction capability.

The focus state is already correctly handled in:
- onResume → focused = true  (window gains interaction focus)
- onPause  → focused = false (window loses interaction focus)

Therefore, sending additional ConfigEvent in onStop and onSurfaceDestroyed
is redundant because:
- onStop is always preceded by onPause
- onSurfaceDestroyed is a low-level surface event unrelated to focus

This cleanup aligns the Android implementation with the correct semantic
that Config.Focused = window interaction focus, not view focus or
surface state.

Signed-off-by: CoyAce <akeycoy@gmail.com>
This commit is contained in:
CoyAce
2026-03-10 17:13:49 +08:00
committed by Elias Naur
parent 760369174d
commit 47ab4c97b2
+6 -14
View File
@@ -121,7 +121,6 @@ import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"gioui.org/io/transfer"
"image" "image"
"image/color" "image/color"
"io" "io"
@@ -137,6 +136,8 @@ import (
"unicode/utf16" "unicode/utf16"
"unsafe" "unsafe"
"gioui.org/io/transfer"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
"gioui.org/op" "gioui.org/op"
@@ -162,7 +163,6 @@ type window struct {
insets pixelInsets insets pixelInsets
visible bool visible bool
focused bool
started bool started bool
animating bool animating bool
@@ -527,7 +527,6 @@ func Java_org_gioui_GioView_onStopView(env *C.JNIEnv, class C.jclass, handle C.j
w := cgo.Handle(handle).Value().(*window) w := cgo.Handle(handle).Value().(*window)
w.started = false w.started = false
w.visible = false w.visible = false
w.sendConfigEvent()
} }
//export Java_org_gioui_GioView_onStartView //export Java_org_gioui_GioView_onStartView
@@ -544,7 +543,6 @@ func Java_org_gioui_GioView_onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, ha
w := cgo.Handle(handle).Value().(*window) w := cgo.Handle(handle).Value().(*window)
w.win = nil w.win = nil
w.visible = false w.visible = false
w.sendConfigEvent()
} }
//export Java_org_gioui_GioView_onSurfaceChanged //export Java_org_gioui_GioView_onSurfaceChanged
@@ -590,8 +588,8 @@ func Java_org_gioui_GioView_onBack(env *C.JNIEnv, class C.jclass, view C.jlong)
//export Java_org_gioui_GioView_onFocusChange //export Java_org_gioui_GioView_onFocusChange
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) { 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 := cgo.Handle(view).Value().(*window)
w.focused = focus == C.JNI_TRUE w.config.Focused = focus == C.JNI_TRUE
w.sendConfigEvent() w.processEvent(ConfigEvent{Config: w.config})
} }
//export Java_org_gioui_GioView_onWindowInsets //export Java_org_gioui_GioView_onWindowInsets
@@ -817,15 +815,9 @@ func (w *window) setVisible(env *C.JNIEnv) {
return return
} }
w.visible = true w.visible = true
w.sendConfigEvent()
w.draw(env, true) 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 { func (w *window) setVisual(visID int) error {
if C.ANativeWindow_setBuffersGeometry(w.win, 0, 0, C.int32_t(visID)) != 0 { if C.ANativeWindow_setBuffersGeometry(w.win, 0, 0, C.int32_t(visID)) != 0 {
return errors.New("ANativeWindow_setBuffersGeometry failed") return errors.New("ANativeWindow_setBuffersGeometry failed")
@@ -868,7 +860,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))) size := image.Pt(int(C.ANativeWindow_getWidth(w.win)), int(C.ANativeWindow_getHeight(w.win)))
if size != w.config.Size { if size != w.config.Size {
w.config.Size = size w.config.Size = size
w.sendConfigEvent() w.processEvent(ConfigEvent{Config: w.config})
} }
if size.X == 0 || size.Y == 0 { if size.X == 0 || size.Y == 0 {
return return
@@ -1404,7 +1396,7 @@ func (w *window) setConfig(env *C.JNIEnv, cnf Config) {
if cnf.Decorated != prev.Decorated { if cnf.Decorated != prev.Decorated {
w.config.Decorated = cnf.Decorated w.config.Decorated = cnf.Decorated
} }
w.sendConfigEvent() w.processEvent(ConfigEvent{Config: w.config})
} }
func (w *window) Perform(system.Action) {} func (w *window) Perform(system.Action) {}