feat: add linux switch to terminal#10
Conversation
- SwitchToTerminalCommand works on Linux via xdotool - terminal window stack with dead-window pruning - SUBLIME_TERMINAL_OPENER_WID env var for bidirectional switching - terminal_class setting for WM_CLASS override
… Mac - also mention that windows does not work atm - also "Switch to application" is imprecise; better use "Switch to terminal" because this is what the command does - fix typo: keybinding -> key binding (match Sublime Text convention)
a6b8c91 to
570491e
Compare
FichteFoll
left a comment
There was a problem hiding this comment.
Thanks for the changes. I did not try them out but left some comments on your code that you might want to consider and address.
| [xdotool](https://github.com/jordansissel/xdotool)). | ||
| Not currently supported on Windows. | ||
|
|
||
| On Linux, xdotool must be installed: |
There was a problem hiding this comment.
It is kind of self-explanatory, but this also means it will only work for Xorg and not Wayland.
There was a problem hiding this comment.
well yes; I can only do hyperland/wayland tests atm. the last commit should work
| wid = subprocess.check_output( | ||
| ['xdotool', 'getactivewindow'], | ||
| timeout=2, stderr=subprocess.DEVNULL | ||
| ).decode().strip() | ||
| if wid not in _terminal_wid_stack: | ||
| _terminal_wid_stack.append(wid) |
There was a problem hiding this comment.
Alternatively, you could remember the pid of the spawned terminal process and use the --pid filter of xdotool to select a window of that pid. That seems less fragile than this timeout based approach.
| ['xdotool', 'getwindowname', wid], | ||
| timeout=2, stderr=subprocess.DEVNULL) | ||
| # Window exists -- activate it | ||
| subprocess.Popen(['xdotool', 'windowactivate', wid]) |
There was a problem hiding this comment.
You should always check the return code of a subprocess.Popen object or directly use the check_output or run methods because otherwise you will leave zombie processes around.
| // terminal's WM_CLASS differs from its executable name (e.g. gnome-terminal | ||
| // uses "gnome-terminal-server"). | ||
| // Find yours with: xdotool getactivewindow getwindowclassname | ||
| "terminal_class": "" |
There was a problem hiding this comment.
I suggest using null to indicate an unset value rather than an empty string.
There was a problem hiding this comment.
yes, but part of the other code had this behavior with the terminal setting; I changed both then to make the code consistent
- use subprocess.run() for xdotool calls - also update macOS for consistency
|
thanks for the feedback ! I addressed the things you mentioned; I need a test for the final commit on my arch setup with hyperland , try to get this done by the end of this week, cheers |
- detect backend via HYPRLAND_INSTANCE_SIGNATURE env var - add backend-dispatching helpers for window operations - refactor xdotool calls out of main code into shared helpers - document Hyprland in readme with bashrc snippet
e236fb0 to
7b02b24
Compare
|
@FichteFoll ok works on my arch setup with wayland/hyprland and ghostty or alacritty; so everything should be fine now i hope |
Fix #9
extends the "Switch to Terminal" command to work on Linux via xdotool (fcb4a82)
enables bidirectional switching between Sublime Text and the terminal for linux (fcb4a82)
documents the command for both macOS and Linux (previously undocumented) (3f43a01 and 570491e)
adds example configurations for modern GPU-accelerated terminals (8ae532d)
Testing
Tested with Ghostty, Kitty, Alacritty, WezTerm, and gnome-terminal locally on Linux Mint 21.1 (Cinnamon/X11). Its quite simple so should work whenever xdotool is installed (which can be installed everhwywhere)
regarding the error message, it looks like so if xdotool is not install but a keybinding is nevertheless set: