2022-06-24 02:25:24 +03:00
|
|
|
# Global hotkeys (user-defined keyboard shortcuts):
|
2024-03-27 17:07:15 +03:00
|
|
|
{ pkgs, config, lib, ... }:
|
2022-06-24 02:25:24 +03:00
|
|
|
let
|
|
|
|
cfg = config.programs.plasma;
|
|
|
|
|
2024-03-31 13:17:38 +03:00
|
|
|
commandString = command: (builtins.replaceStrings [ "%" ] [ "%%" ] command);
|
|
|
|
|
2024-03-27 17:07:15 +03:00
|
|
|
group = rec {
|
|
|
|
name = "plasma-manager-commands";
|
|
|
|
desktop = "${name}.desktop";
|
|
|
|
description = "Plasma Manager";
|
|
|
|
};
|
|
|
|
|
2022-06-24 02:25:24 +03:00
|
|
|
commandType = { name, ... }: {
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = name;
|
|
|
|
description = "Command hotkey name.";
|
|
|
|
};
|
|
|
|
|
|
|
|
comment = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = name;
|
|
|
|
description = "Optional comment to display in the KDE settings UI.";
|
|
|
|
};
|
|
|
|
|
|
|
|
key = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-03-27 17:07:15 +03:00
|
|
|
description = "The key combination that triggers the action.";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
keys = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = "The key combinations that trigger the action.";
|
|
|
|
default = [ ];
|
2022-06-24 02:25:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
command = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The command to execute.";
|
|
|
|
};
|
|
|
|
|
2024-03-27 17:07:15 +03:00
|
|
|
logs.enabled = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Connect command's stdin and stdout to systemd journal with systemd-cat.";
|
2022-06-24 02:25:24 +03:00
|
|
|
};
|
|
|
|
|
2024-03-27 17:07:15 +03:00
|
|
|
logs.identifier = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = lib.trivial.pipe name [
|
|
|
|
lib.strings.toLower
|
|
|
|
(builtins.replaceStrings [ " " ] [ "-" ])
|
|
|
|
(n: "${group.name}-${n}")
|
|
|
|
];
|
|
|
|
description = "Identifier passed down to systemd-cat.";
|
|
|
|
};
|
2022-06-24 02:25:24 +03:00
|
|
|
|
2024-03-27 17:07:15 +03:00
|
|
|
logs.extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "";
|
|
|
|
description = "Additional arguments provided to systemd-cat.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-06-24 02:25:24 +03:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.programs.plasma.hotkeys = {
|
|
|
|
commands = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule commandType);
|
|
|
|
default = { };
|
|
|
|
description = "Commands triggered by a keyboard shortcut.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-15 22:39:30 +03:00
|
|
|
config = lib.mkIf
|
|
|
|
(cfg.enable && builtins.length (builtins.attrNames cfg.hotkeys.commands) != 0)
|
|
|
|
{
|
2024-03-27 17:07:15 +03:00
|
|
|
xdg.desktopEntries."${group.name}" = {
|
|
|
|
name = group.description;
|
|
|
|
noDisplay = true;
|
|
|
|
type = "Application";
|
|
|
|
actions = lib.mapAttrs
|
|
|
|
(_: command: {
|
|
|
|
name = command.name;
|
|
|
|
exec =
|
|
|
|
if command.logs.enabled then
|
2024-03-31 13:17:38 +03:00
|
|
|
"${pkgs.systemd}/bin/systemd-cat --identifier=${command.logs.identifier} ${command.logs.extraArgs} ${commandString command.command}"
|
|
|
|
else (commandString command.command);
|
2024-03-27 17:07:15 +03:00
|
|
|
})
|
|
|
|
cfg.hotkeys.commands;
|
|
|
|
};
|
|
|
|
|
|
|
|
programs.plasma.configFile."kglobalshortcutsrc"."${group.desktop}" = {
|
2024-04-29 23:45:10 +03:00
|
|
|
_k_friendly_name = group.description;
|
2024-03-27 17:20:17 +03:00
|
|
|
} // lib.mapAttrs
|
2024-03-27 17:07:15 +03:00
|
|
|
(_: command:
|
|
|
|
let
|
|
|
|
keys = command.keys ++ lib.optionals (command.key != "") [ command.key ];
|
|
|
|
in
|
2024-04-29 23:45:10 +03:00
|
|
|
lib.concatStringsSep "," [
|
|
|
|
(lib.concatStringsSep "\t" (map (lib.escape [ "," ]) keys))
|
|
|
|
"" # List of default keys, not needed.
|
|
|
|
command.comment
|
|
|
|
])
|
2024-03-27 17:07:15 +03:00
|
|
|
cfg.hotkeys.commands;
|
2022-07-15 22:39:30 +03:00
|
|
|
};
|
2022-06-24 02:25:24 +03:00
|
|
|
}
|