vibe_desktop_shortcut 0.1.1
vibe_desktop_shortcut: ^0.1.1 copied to clipboard
Registers a system-wide keyboard shortcut that runs a command on Linux desktops (KDE Plasma, GNOME, Hyprland), with conflict check and read-back verification.
vibe_desktop_shortcut #
Registers a system-wide keyboard shortcut that runs a command on Linux desktops: KDE Plasma, GNOME and Hyprland.
A Wayland app cannot grab keys globally, and a background process kept alive only for a hotkey costs memory. So this package registers the shortcut with the desktop itself. The desktop then runs your command when the keys are pressed (for example myapp --quick).
- Conflict check first. If another shortcut already uses the keys, nothing is changed and you get the names.
- Honest result. The answer comes from reading the desktop's settings back, not from a program's exit code.
- Fixed commands only. The program and its arguments are fixed values you pass in. Characters that would need escaping are refused.
- Any other desktop. Nothing is changed, and you get the exact command to show the user.
Extracted from the Quick Access shortcut of the VIBE music player.
Install #
dependencies:
vibe_desktop_shortcut: ^0.1.1
or dart pub add vibe_desktop_shortcut. It has no dependencies.
Platform support #
Linux only (it uses dart:io and desktop tools). On other systems apply returns manual. Needs these programs on the user's machine:
- KDE Plasma:
kwriteconfig6(orkwriteconfig5). - GNOME:
gsettings. - Hyprland:
hyprctl.
Use #
import 'package:vibe_desktop_shortcut/vibe_desktop_shortcut.dart';
final registrar = ShortcutRegistrar();
final result = await registrar.apply(
ShortcutSpec(id: 'myapp-quick', name: 'MyApp Quick Access', executable: '/usr/bin/myapp', args: ['--quick']),
KeyCombo.parse('Ctrl+Alt+K')!,
);
switch (result.status) {
case RegistrationStatus.registered: // the desktop reports it as set
case RegistrationStatus.written: // saved, but the desktop has not loaded it: log out and in
case RegistrationStatus.conflict: // result.conflicts names the other shortcuts
case RegistrationStatus.manual: // show result.command to the user
case RegistrationStatus.missing:
}
KeyCombo.parse needs at least one modifier and one key (a letter, a digit, F1 to F12 or Space). Super, Win and Control work as aliases. It returns null for anything else.
Optional on ShortcutSpec: icon (adds an Icon= line to the KDE launcher file), displayNames (a different label per desktop, for example {Desktop.gnome: 'MyApp Quick'}) and quoteExecutable: true (always double-quote the program path, even a plain one).
The id names the files and settings that are written, so the same id always updates the same shortcut.
Add a desktop #
Each desktop is a ShortcutBackend (conflicts, register, verify). Write your own for another desktop and pass it in backends: of ShortcutRegistrar.
What to know #
- Hyprland: the bind is live only. Hyprland forgets it at the next start.
result.noteholds thebind = ...line to add tohyprland.conf. - KDE: a running Plasma may not load the new shortcut until the next login. In that case the status is
written, notregistered. - Conflict checks are best effort. They read what each desktop exposes.
- There is no remove function in this version.
- It was tested with fake program runners and temporary folders, and the output was compared with VIBE's own code. It was not run against a real KDE, GNOME or Hyprland session in these tests.
- Paths and arguments may not contain a backslash, a double quote,
$or a backtick.
License #
MIT.