2022-06-23 02:53:37 +03:00
|
|
|
# Global keyboard shortcuts:
|
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.plasma;
|
|
|
|
|
|
|
|
# Convert one shortcut into a settings attribute set.
|
2022-07-15 23:31:50 +03:00
|
|
|
shortcutToNameValuePair = _action: skey:
|
2022-06-23 02:53:37 +03:00
|
|
|
let
|
|
|
|
# Keys are expected to be a list:
|
|
|
|
keys =
|
|
|
|
if builtins.isList skey
|
|
|
|
then (if builtins.length skey == 0 then [ "none" ] else skey)
|
|
|
|
else [ skey ];
|
|
|
|
|
|
|
|
# Don't allow un-escaped commas:
|
|
|
|
escape = lib.escape [ "," ];
|
|
|
|
in
|
2022-07-15 23:31:50 +03:00
|
|
|
lib.concatStringsSep "," [
|
|
|
|
(lib.concatStringsSep "\t" (map escape keys))
|
|
|
|
"" # List of default keys, not needed.
|
|
|
|
"" # Display string, not needed.
|
|
|
|
];
|
2022-06-23 02:53:37 +03:00
|
|
|
|
|
|
|
shortcutsToSettings = groups:
|
2022-07-15 23:31:50 +03:00
|
|
|
lib.mapAttrs
|
|
|
|
(group: attrs:
|
|
|
|
(lib.mapAttrs shortcutToNameValuePair attrs) // {
|
|
|
|
# Some shortcut groups have a dot in their name so we
|
|
|
|
# explicitly set the group nesting to only one level deep:
|
|
|
|
configGroupNesting = [ group ];
|
|
|
|
})
|
|
|
|
groups;
|
2022-06-23 02:53:37 +03:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.programs.plasma.shortcuts = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (attrsOf (oneOf [ (listOf str) str ]));
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
An attribute set where the keys are application groups and the
|
|
|
|
values are shortcuts.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-06-23 23:39:19 +03:00
|
|
|
config = lib.mkIf (cfg.enable && builtins.attrNames cfg.shortcuts != 0) {
|
2022-06-23 02:53:37 +03:00
|
|
|
programs.plasma.files."kglobalshortcutsrc" =
|
|
|
|
shortcutsToSettings cfg.shortcuts;
|
|
|
|
};
|
|
|
|
}
|