mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-27 19:02:47 +01:00
00aec79ee44767aa573f5eda67c8b8eedf394223
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2f61b62276 |
feat(kwin): survive restarts of the daemon and KWin
kglobalaccel keeps the actions of a client that died, and their keys: a daemon that is killed leaves its keys swallowed and running nothing until they are unregistered. And kglobalaccel runs inside KWin, so a KWin that restarts forgets every key komorebi registered. Neither should leave a user without keys. kwin::hotkeys::release unregisters every action of the component, whatever registered it, and komorebic hotkeys release runs it, with or without a daemon. The NixOS module's unit runs it after the daemon stops (ExecStopPost), however it stops, and a start already takes over what is left. The KWin backend's NameOwnerChanged watch now also follows org.kde.kglobalaccel: when it has an owner again, kwin::hotkeys::rebind loads the key bindings into the new one, trying for 15 seconds. Loading moves from the daemon's main into kwin::hotkeys::load, which keeps its settings (Keybindings: file, format, plan mode, engine options), so that reload can read the file again: the message ReloadHotkeys, komorebic hotkeys reload. A new engine replaces the running one without unregistering its keys, and takes them over as a start does, so the keys both files have stay grabbed. The message HotkeysState answers with the engine's mode, the combos it holds and whether a chain is pending (null without an engine); komorebic hotkeys state prints it with the actions kglobalaccel has for the component. komorebic now depends on komorebi for the two calls to kglobalaccel, and on serde_json for the state. Tests: the socket messages without key bindings, state and release without a session bus, reload without a daemon, and a nixos-module-eval check of ExecStopPost. The VM test vm-restart-survival runs the module's unit in a Plasma session: a key works, hotkeys state shows it; with the daemon stopped by SIGSTOP the key runs nothing until hotkeys release gives it back; after SIGKILL the unit's journal shows the release and the restarted daemon has the key; after the KWin process is killed, the daemon registers the key with the new KWin; and a reload of a changed file swaps the key. vm-keys-engine asks the engine and does not sleep. A key that is not grabbed yet reaches the focused window, which showed as a binding that does not run, so the suite presses one once komorebic hotkeys state answers, which it does when the engine has made the calls of its last event: for a mode, for a chord chain beginning and ending, and for the keys of the application that takes the focus. It waits for the old daemon to exit before it starts the next (a daemon started meanwhile failed to load its KWin script), and activates a window until KWin has it (KWin lists a window before it can have the focus). The last check reloads the key bindings with komorebic hotkeys reload while wev has the focus and every binding is for the terminal, a start with no key to grab. |
||
|
|
47d3a471d7 |
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. |
||
|
|
260d8ff03e |
feat(kwin): end a chord chain at its timeout
An sxhkd chain (alt + w ; h) is realized by the engine: after the prefix only the keys that can come next and Escape are grabbed, because KWin 6.8's own key sequences never fire. What ends a chain that nobody finishes is the chord timeout, and the engine has no clock: it is told the time with on_tick. Rather than ticking on a timer forever, the engine now says when its pending chain times out (Engine::deadline, in komorebi-hotkeys) and the transport sleeps until then, calls on_tick, and grabs the keys of the mode again. With no chain pending it does not wake up at all. The daemon takes --chord-timeout in milliseconds, 3000 by default, the engine's default and the module's chordTimeout to come. A unit test follows the calls of a chain from its prefix to its deadline. The VM test vm-keys-engine grows a section with an sxhkdrc passed as --keybindings and a timeout of 1.5 s: Alt+W, H runs the binding and H does not reach wev; Alt+W, Escape lets the next H reach wev; Alt+W and two seconds later L reaches wev and runs nothing. |
||
|
|
3f72eb84d1 |
feat(kwin): realize the modes of a key binding file in the daemon
skhd's modes, and sxhkd's chains that stay open, are sets of keys that are active together; a static shortcut cannot be in one. The engine already computes the keys a mode wants. What the daemon adds is that a mode switch reaches kglobalaccel as it should: the keys of the mode left are let go with setInactive, so that they reach the focused window again, and those of the mode entered are grabbed, bare keys included, before the next key arrives. It logs the mode after each change, which is the one way to see from outside which mode the engine is in. A unit test follows the calls of entering a mode and leaving it with Escape. The VM test vm-keys-engine grows a section with wev focused: in the default mode a bare H reaches wev; Alt+R enters the mode resize and runs its command, after which H runs its binding and does not reach wev; Escape goes back, and H reaches wev again. That turns "a key the engine does not want reaches the application" from a convention into a proved rule. |
||
|
|
b49c4fab0a |
feat(kwin): the daemon registers with KGlobalAccel
A static shortcut can only be one combo, pressed, the same in every application. Modes, chord chains, release bindings and per-application bindings need komorebi to hold the keys and decide what each press does: the engine of komorebi-hotkeys, a state machine with no I/O. This commit runs it against KWin's global shortcut daemon, which KWin 6.8 runs inside itself on the session bus. kwin::hotkeys owns the component komorebi in kglobalaccel, with one action per combo, named after the combo (Alt+H). An activation of the engine is setShortcutKeys(id, [[combo]], 6), with a doRegister the first time; a deactivation is setInactive, after which the key reaches the focused window again. The calls of one event are sent without waiting for each other's answers, which Phase 0 measured at 60 calls in 2.4 ms. globalShortcutPressed and globalShortcutReleased of /component/komorebi feed the engine; globalShortcutRepeated is ignored, so a held key runs its binding once. A komorebic command runs the komorebic next to the daemon with its words when they need no shell, anything else runs through sh -c. The calls are computed by Registry, which is pure and tested; the D-Bus part is proved by the VM test. The engine hears the presses at the path /component/komorebi and does not ask kglobalaccel for the object with getComponent. kglobalaccel makes the object when the component gets its first action, so a start with no key to grab (every binding is for an application other than the one with the focus) has none to ask for: getComponent fails with NoSuchComponent, and an engine that asked would never start. A signal is matched by the path it comes from, so the presses are heard as soon as there is an object. PLATFORM.md says so. kglobalaccel keeps the actions and the grabs of a client that was killed, so a start is an idempotent reconcile: the actions of the component that the keymap names are taken over and released unless the default mode wants them, the others are unregistered. A stop releases and unregisters everything, from KWinBackend::shutdown, which SIGINT, SIGTERM and the Stop message all go through. The daemon takes --keybindings FILE, --keybindings-format skhd|whkd|sxhkd (by default from the file's name) and --keybindings-mode (the mode komorebic hotkeys compile wrote the static shortcuts in, so that the daemon leaves those to KDE); without --keybindings it reads the first of skhdrc, whkdrc and sxhkdrc in the config directory (HOME_DIR, KOMOREBI_CONFIG_HOME). It logs one line about the file and the diagnostics at debug level. An engine that cannot start is logged and the window manager runs without keys; the fake backend runs none. The VM test vm-keys-engine starts the daemon in a Plasma session with an skhdrc in the config directory, presses its keys (a command, one through a shell, komorebic retile reaching the daemon), kills the daemon and sees its keys stay registered, starts it with another file and sees the old keys unregistered and the new ones work, and stops it with komorebic stop, after which no key is registered and none runs. The library gains spawn_komorebi, kill_spawned_komorebi and shortcut_actions, and Checks.finish names the checks that failed, since nix build shows only the last lines of a failed run. The suite's node turns the module's unit off: the test runs daemons of its own. |