Skip to content

feat(linux): precise terminal focus via WINDOWID + custom terminal support#177

Merged
vakovalskii merged 1 commit intovakovalskii:mainfrom
tearfu1:feat/linux-terminal-focus-and-custom-terminal
Apr 16, 2026
Merged

feat(linux): precise terminal focus via WINDOWID + custom terminal support#177
vakovalskii merged 1 commit intovakovalskii:mainfrom
tearfu1:feat/linux-terminal-focus-and-custom-terminal

Conversation

@tearfu1
Copy link
Copy Markdown
Contributor

@tearfu1 tearfu1 commented Apr 16, 2026

Summary

  • Precise window focus on Linux: Read WINDOWID from /proc/<pid>/environ instead of matching by terminal server PID. This fixes the issue where Focus Terminal would activate the wrong window/tab when multiple terminal windows are open.
  • Kitty remote control: Tab-level focus via kitty @ focus-window --match pid:<pid> for kitty users.
  • Custom terminal binary: Replace hardcoded terminal dropdown in Settings with a text input + datalist suggestions. Users can specify any terminal binary name or full path (e.g. ghostty, /usr/bin/alacritty).
  • System default detection: Auto-detect x-terminal-emulator symlink target on Debian/Ubuntu.
  • Smart launch flags: Detect terminal type by basename — gnome-terminal gets --, wezterm gets start --, everything else gets generic -e.

What was broken

  1. focusTerminalByPid() on Linux walked the parent chain to find the terminal server PID, then matched it against wmctrl -l -p. Since terminal servers (e.g. gnome-terminal-server) own ALL windows with a single PID, it always focused the first window — not the one with the active session.
  2. The terminal selector was a fixed dropdown with 5 terminals. Users of ghostty, wezterm, terminator, tilix, foot, etc. had no way to configure their terminal.
  3. The default launch terminal was hardcoded to gnome-terminal.

How it works now

Focus (WINDOWID approach)

agent PID → read /proc/<pid>/environ → find WINDOWID=12345
  → xdotool windowactivate 12345 (or wmctrl -ia 0x00003039)
  → falls back to PID chain matching if WINDOWID not found

Custom terminal

Settings now shows a text input with autocomplete suggestions from detected binaries. The value is sent as-is to the server, which determines launch flags by path.basename().

Test plan

  • Linux: Focus Terminal with multiple terminal windows open → correct window activates
  • Linux: Focus Terminal with tabs → correct window activates (tab-level for kitty with remote control enabled)
  • Settings: type custom terminal path → Resume opens in that terminal
  • Settings: datalist shows detected terminals as suggestions
  • macOS: no regressions (darwin code path unchanged)

…nal support

- Read WINDOWID from /proc/<pid>/environ for accurate window matching
  instead of matching first window by terminal server PID
- Add kitty remote control support for tab-level focus
- Support arbitrary terminal binary path in settings (text input with
  datalist suggestions instead of hardcoded dropdown)
- Auto-detect system default terminal via x-terminal-emulator symlink
- Handle gnome-terminal (--) and wezterm (start --) special flags,
  generic -e for all other terminals
- Add wmctrl hex conversion and xdotool decimal fallbacks
@vakovalskii vakovalskii merged commit 7194223 into vakovalskii:main Apr 16, 2026
vakovalskii added a commit that referenced this pull request Apr 16, 2026
Merged PRs:
- #169 (@buriy): Running card titles white for visibility
- #170 (@buriy): Makefile for easy service management
- #177 (@tearfu1): Linux precise terminal focus via WINDOWID
- #172 (@vbp1): WSL browser UI (launch, focus, IDE)
- #150 (@dum3r): WSL agent homes discovery on Windows
- #165 (@tpitsunov): Kilo CLI agent support (SQLite backend)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
vakovalskii added a commit that referenced this pull request Apr 16, 2026
Merged PRs:
- #169 (@buriy): Running card titles white for visibility
- #170 (@buriy): Makefile for easy service management
- #177 (@tearfu1): Linux precise terminal focus via WINDOWID
- #172 (@vbp1): WSL browser UI (launch, focus, IDE)
- #150 (@dum3r): WSL agent homes discovery on Windows
- #165 (@tpitsunov): Kilo CLI agent support (SQLite backend)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants