feat(kwin): per-application key bindings follow the focus

skhd and whkd can give one key a different action in each application, or none
(skhd's ~, whkd's Ignore), and skhd has a blacklist of applications in which no
key is taken. The engine decides from the focused application whether such a key
is active: inactive, it reaches the application, which is how a key passes
through. What it needs is to be told which application has the focus.

The bridge reports the desktop entry of every window with its class, and the
table now keeps it. Table::focused_application returns the executable, the app
id (or X11 class) and the desktop entry of the window KWin activated last, a
dialog included, or nothing once that window is gone. The KWin backend hands it
to kwin::hotkeys::focus after every event of the bridge; only a change reaches
the engine's thread, and an engine that starts begins with the focus as it was
last seen. The engine matches the names of the file against the three, ignoring
case.

The names in an skhdrc or a whkdrc are those of macOS and Windows applications,
so the daemon takes --app-alias NAME=ALIAS[,ALIAS]..., more than once, for the
engine's app_aliases.

Unit tests cover the focus of the table and the calls of a scoped key as the
focus moves, an alias included. The VM test vm-keys-engine grows a section with
wev and foot open and --app-alias terminal=foot: in wev, Alt+G (for the terminal
only) and Alt+N (which wev ignores) reach wev and run nothing; in foot both run
their bindings; back in wev, Alt+G reaches wev again.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:39:49 -07:00
1 parent 260d8ff03e
commit 47d3a471d7
7 files changed
+258 -7

No files matched your search

+7
View File
@@ -1678,6 +1678,11 @@ plan needs no engine. A failure to start is logged, and the window manager runs
are grabbed. The transport sleeps until `Engine::deadline` (the chord timeout after the last
combo of the chain, `--chord-timeout`, 3 seconds by default) and calls `Engine::on_tick`
then, which abandons the chain; there is no timer otherwise.
- **Focus**: after every event of the bridge, the KWin backend gives the engine the
application of the window KWin activated (`Table::focused_application`: its executable, app id
and desktop entry), and a change makes the engine grab the keys of the bindings that do
something there and let the others go. The aliases of `--app-alias` are names of an
application too.
- **Start**: the component's actions that the keymap names are taken over, and released
unless the default mode wants them; the others are unregistered. The engine starts in the
default mode.
@@ -1717,6 +1722,8 @@ plan needs no engine. A failure to start is logged, and the window manager runs
| A press of a grabbed key runs its binding's command, `komorebic` without a shell where it needs none | test, of the process; VM test | `command` doctest, `a_press_runs_the_command_and_changes_no_key`, `vm-keys-engine` | none |
| Entering a mode lets go of the keys of the mode it leaves and grabs its own, a bare key among them | test, of the calls; VM test | `entering_a_mode_lets_the_keys_of_the_other_go_and_grabs_its_own`, `vm-keys-engine` | none |
| After the prefix of a chain only its next keys and Escape are grabbed, until a key ends the chain or its deadline passes, and the keys of the mode come back then | test, of the calls; VM test | `a_chain_grabs_its_next_keys_until_its_deadline`, the `Engine::deadline` doctest, `vm-keys-engine` | none |
| The application of the focus is the one of the window KWin activated, a dialog included, and none once that window is gone | test | `the_focused_application_is_the_one_of_the_window_kwin_activated` | none |
| A per-application key is grabbed only while the focused application (or an alias of it) has an action for it, and reaches the application otherwise | test, of the calls; VM test | `a_scoped_key_is_grabbed_only_while_its_application_has_the_focus`, `vm-keys-engine` | none |
| Holding a key runs its binding once | convention only: the transport listens to `globalShortcutPressed` and not to `globalShortcutRepeated` | none (measured in PLATFORM.md) | none |
## Where to look in the code