mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-20 15:41:38 +01:00
komorebi users keep their bindings to komorebic in a file of skhd, whkd or sxhkd. On Plasma under Wayland no client sees the keys of another, and the program that runs a command on a key is KDE's global shortcut daemon, which runs inside KWin. A binding that is one combo, pressed, the same in every application, in a file without modes, can be a static shortcut: a .desktop file that KWin reads by itself, that shows in System Settings and that works with no komorebi process at all. komorebic hotkeys compile reads a file of any of the three formats, plans it with komorebi-hotkeys in the mode it is given (auto, engine or static; the default is the crate's), prints the diagnostics of reading and planning, and writes the static shortcuts to $XDG_DATA_HOME/kglobalaccel or --output, replacing the files it wrote before and no other. --strict refuses a file with a warning or an error before writing anything, --dry-run says what a write would change, and --reload hands each new file to the running KWin. komorebic export-kde-shortcuts keeps the spike's interface for an skhdrc, in the static mode. Both are thin: the reading, the plan and the files are the crate's. The bindings that need the engine are counted; the daemon does not run them yet. docgen gives a subcommand of a subcommand a page of its own (hotkeys-compile.md). KOMOREBI_CONFIG_HOME, or ~/.config/komorebi, is where komorebic looks for a file it is not given. komorebic check gains a section for the key bindings, between the configuration and the desktop: the first key binding file of the config home, how many bindings it has and where they go, the lines that cannot be read (a warning, and the first five) and the bindings not realized as their own daemon would (a note), and whether the generated files in the shortcut directory are the ones hotkeys compile would write now (a warning with how many to add, to change and to remove). --configuration-only keeps it, as it looks at files. The VM test vm-keys-static boots a Plasma session with shortcut files that hotkeys compile wrote into the system profile at build time, presses their keys through QEMU's keyboard, and sees each command run, a % in one of them included; then it writes a binding in the middle of the session with export-kde-shortcuts --reload and presses it. The library gains Keys, which sends a combo as KDE writes it through QEMU's sendkey.
50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
# Static shortcuts in a real Plasma session: what `komorebic hotkeys compile` and
|
|
# `komorebic export-kde-shortcuts` write is run by KWin itself, with no komorebi
|
|
# process. The Rust tests check the files; only a KWin can say that it reads them
|
|
# and runs their commands on a key: the files in the system profile when the
|
|
# session starts, and a file written later once `--reload` has handed it over.
|
|
from komorebi_vm import Checks, Kde, Keys
|
|
|
|
start_all()
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
checks = Checks()
|
|
kde = Kde.session(machine, scale=SCALE)
|
|
keys = Keys(machine)
|
|
|
|
|
|
def ran(marker: str) -> bool:
|
|
return machine.execute(f"test -e /tmp/{marker}")[0] == 0
|
|
|
|
|
|
def press(combo: str, marker: str) -> bool:
|
|
keys.send(combo)
|
|
return kde.wait_for(lambda: ran(marker), timeout=10)
|
|
|
|
|
|
print(kde.sh("ls /run/current-system/sw/share/kglobalaccel"))
|
|
checks.check("Alt+J runs its command", press("alt-j", "keys-static-alt-j"))
|
|
checks.check(
|
|
"Alt+Shift+K runs a command that needs a shell",
|
|
press("alt-shift-k", "keys-static-alt-shift-k"),
|
|
)
|
|
checks.check("Alt+P runs a command with a %", press("alt-p", "keys-static-alt-p"))
|
|
date = machine.succeed("cat /tmp/keys-static-alt-p").strip()
|
|
checks.check(f"the % reached the command as one % ({date!r})", date.isdigit())
|
|
|
|
# a binding written in the middle of the session, into the user's directory
|
|
kde.sh("mkdir -p ~/.config/komorebi")
|
|
kde.sh("echo 'alt - u : touch /tmp/keys-static-alt-u' > ~/.config/komorebi/skhdrc")
|
|
print(kde.sh("komorebic export-kde-shortcuts --reload"))
|
|
written = "/home/komorebi/.local/share/kglobalaccel/komorebi-touch-tmp-keys-static-alt-u.desktop"
|
|
checks.check(
|
|
"the file is in the user's kglobalaccel directory",
|
|
machine.execute(f"test -e {written}")[0] == 0,
|
|
)
|
|
checks.check(
|
|
"Alt+U runs its command once --reload has handed it over",
|
|
press("alt-u", "keys-static-alt-u"),
|
|
)
|
|
|
|
checks.finish()
|