Skip to content

Commit 47ab4c9

Browse files
CoyAceeliasnaur
authored andcommitted
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>
1 parent 7603691 commit 47ab4c9

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

app/os_android.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ import "C"
121121
import (
122122
"errors"
123123
"fmt"
124-
"gioui.org/io/transfer"
125124
"image"
126125
"image/color"
127126
"io"
@@ -137,6 +136,8 @@ import (
137136
"unicode/utf16"
138137
"unsafe"
139138

139+
"gioui.org/io/transfer"
140+
140141
"gioui.org/internal/f32color"
141142
"gioui.org/op"
142143

@@ -162,7 +163,6 @@ type window struct {
162163
insets pixelInsets
163164

164165
visible bool
165-
focused bool
166166
started bool
167167
animating bool
168168

@@ -527,7 +527,6 @@ func Java_org_gioui_GioView_onStopView(env *C.JNIEnv, class C.jclass, handle C.j
527527
w := cgo.Handle(handle).Value().(*window)
528528
w.started = false
529529
w.visible = false
530-
w.sendConfigEvent()
531530
}
532531

533532
//export Java_org_gioui_GioView_onStartView
@@ -544,7 +543,6 @@ func Java_org_gioui_GioView_onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, ha
544543
w := cgo.Handle(handle).Value().(*window)
545544
w.win = nil
546545
w.visible = false
547-
w.sendConfigEvent()
548546
}
549547

550548
//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)
590588
//export Java_org_gioui_GioView_onFocusChange
591589
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
592590
w := cgo.Handle(view).Value().(*window)
593-
w.focused = focus == C.JNI_TRUE
594-
w.sendConfigEvent()
591+
w.config.Focused = focus == C.JNI_TRUE
592+
w.processEvent(ConfigEvent{Config: w.config})
595593
}
596594

597595
//export Java_org_gioui_GioView_onWindowInsets
@@ -817,15 +815,9 @@ func (w *window) setVisible(env *C.JNIEnv) {
817815
return
818816
}
819817
w.visible = true
820-
w.sendConfigEvent()
821818
w.draw(env, true)
822819
}
823820

824-
func (w *window) sendConfigEvent() {
825-
w.config.Focused = w.visible && w.focused
826-
w.processEvent(ConfigEvent{Config: w.config})
827-
}
828-
829821
func (w *window) setVisual(visID int) error {
830822
if C.ANativeWindow_setBuffersGeometry(w.win, 0, 0, C.int32_t(visID)) != 0 {
831823
return errors.New("ANativeWindow_setBuffersGeometry failed")
@@ -868,7 +860,7 @@ func (w *window) draw(env *C.JNIEnv, sync bool) {
868860
size := image.Pt(int(C.ANativeWindow_getWidth(w.win)), int(C.ANativeWindow_getHeight(w.win)))
869861
if size != w.config.Size {
870862
w.config.Size = size
871-
w.sendConfigEvent()
863+
w.processEvent(ConfigEvent{Config: w.config})
872864
}
873865
if size.X == 0 || size.Y == 0 {
874866
return
@@ -1404,7 +1396,7 @@ func (w *window) setConfig(env *C.JNIEnv, cnf Config) {
14041396
if cnf.Decorated != prev.Decorated {
14051397
w.config.Decorated = cnf.Decorated
14061398
}
1407-
w.sendConfigEvent()
1399+
w.processEvent(ConfigEvent{Config: w.config})
14081400
}
14091401

14101402
func (w *window) Perform(system.Action) {}

0 commit comments

Comments
 (0)