Repository navigation
fix(linux): commit the Ctrl-Tab session switch on Ctrl release - #37
Merged
Merged
Conversation
Linux Ctrl+Tab cycling felt random because `quickSwitchSession` called
`selectSession` on every begin/advance step. Each step pushed the session
onto `RecencyStack`, so a cycle longer than two reordered the MRU
differently from macOS: with MRU [A,B,C], cycling to C left macOS at
[C,A,B] — the next Ctrl+Tab toggles back to A — but Linux at [C,B,A],
where the next Ctrl+Tab lands on B instead.
macOS (`agterm/Views/SessionSwitcher.swift`) moves only an index during
the cycle and selects once on Ctrl release. That was already the
documented contract in `.claude/rules/menu-actions.md` ("Ctrl-Tab
snapshots `sessionRecency` and cycles without reordering until commit");
the Linux implementation violated it.
Cycling now moves the overlay highlight only. `commitSessionSwitch`
selects once when the Ctrl modifier clears, so a cycle pushes recency
exactly once and a second Ctrl+Tab toggles back. Ending the model before
selecting is load-bearing: `selectSession` grabs focus, and that blur
reaches `cancelSessionSwitch`, which must find the cycle already over.
Where macOS uses app-wide event monitors, the fork relies on the focused
surface's key controller, which needs three things macOS gets for free:
- `HeldControlKeys` tracks held Ctrl keycodes so the commit waits for the
last one, matching macOS's `.control`-cleared test. A GDK release
carries the modifier state from before it, so the event alone cannot
tell whether the other Ctrl key is still down. Keycodes rather than
keyvals, since a Caps-remapped Control_L reports the same keyval. Any
press arriving with Ctrl clear resyncs the set, so a release lost to a
blur or a grab heals instead of stranding a phantom.
- The window's own controller carries a Ctrl-release handler for the
sessionless case. A restore that drops a dangling selected id leaves
`activeSession == nil` over live sessions, so a cycle could begin there
with no surface focused and nothing would ever commit it.
- A terminal blur cancels the cycle, since the release reaches only the
surface holding the keyboard. This is deliberately broader than that
reason and is why the overlay card is never focusable.
Esc cancels ahead of the leader abort, mirroring macOS. Opening the
dashboard cancels rather than commits.
Companion change: the Recent Sessions popover and its button move from
whole-tree `recentSessions` to `navigableRecentSessions`, matching
`agterm/Views/WindowContentView+RecentSessions.swift`. This is visible in
flagged/filtered mode — a shorter list, and the button disables when the
scope is empty. The rules file said the button "enables only with at
least two sessions", which was wrong for both platforms.
`AppController` was at 1011 lines with the new code, over the 1000-line
SwiftLint limit, so the switcher block moved verbatim into
`AppControllerSessionPicker.swift`, which already owned the switcher's
scroller helper and is documented as the switcher's mouse twin.
Tests: `AppController` is not constructible in unit tests, so the commit
decision is extracted into the pure `SessionSwitcherModel.commitTarget`
and `HeldControlKeys`, and the wiring is covered end to end by a new
AT-SPI `session-switch-commit` scenario — mid-cycle non-selection, the
[C,A,B] toggle-back, reverse cycling, Esc abort, blur cancel, dashboard
cancel, a two-Ctrl hold, and a plain Ctrl+C negative for the invariant
that a release with no cycle in flight selects nothing. The existing
`session-pickers` scenario gains a flagged-mode leg for the scope change.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011GdLJpdGdL4xqQeWoFj7v3
melonamin
force-pushed
the
linux-ctrl-tab-commit
branch
from
September 3, 2026 13:14
c6baedc to
e4bb1c4
Compare
melonamin
force-pushed
the
linux-ctrl-tab-commit
branch
from
September 3, 2026 13:50
e4bb1c4 to
68fc611
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linux Ctrl+Tab cycling feels random because
quickSwitchSessioncallsselectSessionon every begin/advance step. Each step pushes the session ontoRecencyStack, so a cycle longer than two reorders the MRU differently from macOS:[A,B,C], cycle to C[C,A,B][C,B,A]macOS (
agterm/Views/SessionSwitcher.swift) moves only an index during the cycle and selects once on Ctrl release. That was already the documented contract in.claude/rules/menu-actions.md— "Ctrl-Tab snapshotssessionRecencyand cycles without reordering until commit" — so this is the Linux side catching up to a rule the repo already states.What changed
Cycling now moves the overlay highlight only.
commitSessionSwitchselects once when the Ctrl modifier clears, so a cycle pushes recency exactly once and a second Ctrl+Tab toggles back.Ending the model before selecting is load-bearing:
selectSessiongrabs focus, and that blur reachescancelSessionSwitch, which must find the cycle already over. macOS gets this fromcommit()'sdefer { reset() }.Three things macOS gets free from app-wide monitors
The fork dispatches through the focused surface's key controller instead, which needs:
HeldControlKeys— the commit waits for the last held Ctrl keycode, matching macOS's.control-cleared test. A GDK release carries the modifier state from before it, so the event alone cannot tell whether the other Ctrl key is still down. Keycodes rather than keyvals, since a Caps-remapped Control_L reports the same keyval. Any press arriving with Ctrl clear resyncs the set, so a release lost to a blur or a keyboard grab heals on the next keystroke instead of stranding a phantom that would block every later commit.activeSession == nilover live sessions, so a cycle could begin there with no surface focused and nothing would ever commit it.Esc cancels ahead of the leader abort, mirroring macOS. Opening the dashboard cancels rather than commits.
Companion change
The Recent Sessions popover and its button move from whole-tree
recentSessionstonavigableRecentSessions, matchingagterm/Views/WindowContentView+RecentSessions.swift. User-visible in flagged/filtered mode: a shorter list, and the button disables when the scope is empty. The rules file claimed the button "enables only with at least two sessions", which was wrong for macOS too — both sides enable on a non-empty navigable list.File move
AppController.swifthit 1011 lines with the new code, over the 1000-line SwiftLint limit. Rather than raise the limit, the switcher block moved verbatim intoAppControllerSessionPicker.swift, which already owned the switcher's scroller helper and is documented as the switcher's mouse twin.AppController.swiftis now 947 lines.Tests
AppControlleris not constructible in unit tests, so the commit decision is extracted into the pureSessionSwitcherModel.commitTarget(liveIDs:)andHeldControlKeysand unit-tested there. The wiring is covered end to end by a new AT-SPIsession-switch-commitscenario:[C,A,B]toggle-backThe existing
session-pickersscenario gains a flagged-mode leg for the scope change.HeldControlKeyswas added in review after an external reviewer found that releasing one of two held Ctrl keys committed early. It is genuine scope growth beyond the original plan, but on-subject: macOS parity is the point of the change.Docs
The Linux-specific contract lives in a new
agterm-linux/docs/menu-actions.md, next tomain-loop.md/sidebar.md/x11-wayland.md, rather than in the shared rules file alongside the macOS monitors it replaces..claude/rules/main-loop.md's blur bullet points at it.Verification
swift testinagterm-linux/: 335 tests, one pre-existing unrelated failure (Flatpak process environments do not offer a host launcher,IntegrationServiceTests.swift:765— it trips on a real deployedagtermctlon the host's PATH)AgtermLinuxandagtermctl-linuxboth buildswiftlint lint --strict: 0 violations in 485 filesscripts/test-linux-ui.sh: 28 scenarios greenNo files under
agterm/,agtermCore/, oragtermUITests/are touched —navigableRecentSessions(limit:)already existed in core.🤖 Generated with Claude Code
https://claude.ai/code/session_011GdLJpdGdL4xqQeWoFj7v3