detached d2d9ad1

fix(focus): deduplicate GTK focus events with timestamp tracking

WebKitGTK nested widgets fire multiple focus enter/leave events in the
same millisecond, causing duplicate logging and potential state issues.

Changes:
- focus_state_machine.go: Add timestamp-based deduplication in GTK
  controller callbacks. Skip events with same millisecond timestamp.
- workspace_types.go: Add lastFocusEnterTime and lastFocusLeaveTime
  fields to paneNode for tracking.

This prevents duplicate GTK focus events without losing real focus changes.
commit
d2d9ad1c612af9ccda855e620655cfa764b40684
author
bamen · · 2025-10-13 18:14 UTC
committer
bamen · · 2025-10-13 21:36 UTC
parent
9a95d24
signature
unsigned
2 files · +17 -1
M internal/app/browser/focus_state_machine.go +15 -1
@@ -956,14 +956,28 @@ func (fsm *FocusStateMachine) attachGTKController(node *paneNode) {
956956 // GTK_PHASE_TARGET means we only get events for this specific widget, not bubbled events
957957 controller.SetPropagationPhase(gtk.PhaseTarget)
958958
959- // Connect focus enter/leave callbacks for this specific node
959+ // Connect focus enter/leave callbacks with timestamp-based deduplication
960960 controller.ConnectEnter(func() {
961+ // Deduplicate: WebKitGTK nested widgets can fire multiple events in same millisecond
962+ now := time.Now().UnixMilli()
963+ if node.lastFocusEnterTime == now {
964+ return // Duplicate event in same millisecond
965+ }
966+ node.lastFocusEnterTime = now
967+
961968 log.Printf("[FSM] GTK focus enter: %p", node)
962969 // Don't automatically change focus on GTK enter - let user interactions drive this
963970 // This prevents infinite loops with our own focus changes
964971 })
965972
966973 controller.ConnectLeave(func() {
974+ // Deduplicate: WebKitGTK nested widgets can fire multiple events in same millisecond
975+ now := time.Now().UnixMilli()
976+ if node.lastFocusLeaveTime == now {
977+ return // Duplicate event in same millisecond
978+ }
979+ node.lastFocusLeaveTime = now
980+
967981 log.Printf("[FSM] GTK focus leave: %p", node)
968982 // Similarly, don't react to GTK leave events automatically
969983 })
@@ -956,14 +956,28 @@ func (fsm *FocusStateMachine) attachGTKController(node *paneNode) {
956 // GTK_PHASE_TARGET means we only get events for this specific widget, not bubbled events956 // GTK_PHASE_TARGET means we only get events for this specific widget, not bubbled events
957 controller.SetPropagationPhase(gtk.PhaseTarget)957 controller.SetPropagationPhase(gtk.PhaseTarget)
958 958
959- // Connect focus enter/leave callbacks for this specific node959+ // Connect focus enter/leave callbacks with timestamp-based deduplication
960 controller.ConnectEnter(func() {960 controller.ConnectEnter(func() {
961+ // Deduplicate: WebKitGTK nested widgets can fire multiple events in same millisecond
962+ now := time.Now().UnixMilli()
963+ if node.lastFocusEnterTime == now {
964+ return // Duplicate event in same millisecond
965+ }
966+ node.lastFocusEnterTime = now
967+
961 log.Printf("[FSM] GTK focus enter: %p", node)968 log.Printf("[FSM] GTK focus enter: %p", node)
962 // Don't automatically change focus on GTK enter - let user interactions drive this969 // Don't automatically change focus on GTK enter - let user interactions drive this
963 // This prevents infinite loops with our own focus changes970 // This prevents infinite loops with our own focus changes
964 })971 })
965 972
966 controller.ConnectLeave(func() {973 controller.ConnectLeave(func() {
974+ // Deduplicate: WebKitGTK nested widgets can fire multiple events in same millisecond
975+ now := time.Now().UnixMilli()
976+ if node.lastFocusLeaveTime == now {
977+ return // Duplicate event in same millisecond
978+ }
979+ node.lastFocusLeaveTime = now
980+
967 log.Printf("[FSM] GTK focus leave: %p", node)981 log.Printf("[FSM] GTK focus leave: %p", node)
968 // Similarly, don't react to GTK leave events automatically982 // Similarly, don't react to GTK leave events automatically
969 })983 })
M internal/app/browser/workspace_types.go +2 -0
@@ -70,6 +70,8 @@ type paneNode struct {
7070 pendingHoverReattach bool // Needs hover reattachment after reparent
7171 pendingFocusReattach bool // Needs focus reattachment after reparent
7272 lastHoverTime int64 // Timestamp of last hover event (for debouncing)
73+ lastFocusEnterTime int64 // Timestamp of last focus enter event (for deduplication)
74+ lastFocusLeaveTime int64 // Timestamp of last focus leave event (for deduplication)
7375
7476 // Stacked panes support - terminal branch nodes
7577 isStacked bool // Whether this node contains stacked panes
@@ -70,6 +70,8 @@ type paneNode struct {
70 pendingHoverReattach bool // Needs hover reattachment after reparent70 pendingHoverReattach bool // Needs hover reattachment after reparent
71 pendingFocusReattach bool // Needs focus reattachment after reparent71 pendingFocusReattach bool // Needs focus reattachment after reparent
72 lastHoverTime int64 // Timestamp of last hover event (for debouncing)72 lastHoverTime int64 // Timestamp of last hover event (for debouncing)
73+ lastFocusEnterTime int64 // Timestamp of last focus enter event (for deduplication)
74+ lastFocusLeaveTime int64 // Timestamp of last focus leave event (for deduplication)
73 75
74 // Stacked panes support - terminal branch nodes76 // Stacked panes support - terminal branch nodes
75 isStacked bool // Whether this node contains stacked panes77 isStacked bool // Whether this node contains stacked panes

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close