diff --git a/example/home.nix b/example/home.nix index 544791d..19fc4c1 100644 --- a/example/home.nix +++ b/example/home.nix @@ -6,6 +6,21 @@ # A high-level setting: workspace.clickItemTo = "select"; + # A mid-level setting: + shortcuts = { + ksmserver = { + "Lock Session" = [ "Screensaver" "Meta+Ctrl+Alt+L" ]; + }; + + kwin = { + "Expose" = "Meta+,"; + "Switch Window Down" = "Meta+J"; + "Switch Window Left" = "Meta+H"; + "Switch Window Right" = "Meta+L"; + "Switch Window Up" = "Meta+K"; + }; + }; + # A low-level setting: files."baloofilerc"."Basic Settings"."Indexing-Enabled" = false; }; diff --git a/modules/default.nix b/modules/default.nix index d2fa1c8..2cbd7b7 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,6 +3,7 @@ { imports = [ ./files.nix + ./shortcuts.nix ./windows.nix ./workspace.nix ]; diff --git a/modules/shortcuts.nix b/modules/shortcuts.nix new file mode 100644 index 0000000..a1ee8d6 --- /dev/null +++ b/modules/shortcuts.nix @@ -0,0 +1,46 @@ +# Global keyboard shortcuts: +{ config, lib, ... }: + +let + cfg = config.programs.plasma; + + # Convert one shortcut into a settings attribute set. + shortcutToNameValuePair = action: skey: + 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 + { + name = action; + value = lib.concatStringsSep "," [ + (lib.concatStringsSep "\t" (map escape keys)) + "" # List of default keys, not needed. + "" # Display string, not needed. + ]; + }; + + shortcutsToSettings = groups: + lib.mapAttrs (_group: lib.mapAttrs' shortcutToNameValuePair) groups; + +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. + ''; + }; + + config = lib.mkIf cfg.enable { + programs.plasma.files."kglobalshortcutsrc" = + shortcutsToSettings cfg.shortcuts; + }; +} diff --git a/script/rc2nix.rb b/script/rc2nix.rb index b1c8db6..8a2c2ee 100755 --- a/script/rc2nix.rb +++ b/script/rc2nix.rb @@ -131,6 +131,9 @@ module Rc2Nix puts("{") puts(" programs.plasma = {") puts(" enable = true;") + puts(" shortcuts = {") + pp_shortcuts(settings["kglobalshortcutsrc"], 6) + puts(" };") puts(" files = {") pp_settings(settings, 6) puts(" };") @@ -143,6 +146,8 @@ module Rc2Nix settings.keys.sort.each do |file| settings[file].keys.sort.each do |group| settings[file][group].keys.sort.each do |key| + next if file == "kglobalshortcutsrc" && key != "_k_friendly_name" + print(" " * indent) print("\"#{file}\".") print("\"#{group}\".") @@ -154,6 +159,35 @@ module Rc2Nix end end + ############################################################################ + def pp_shortcuts(groups, indent) + groups&.keys.sort.each do |group| + groups[group].keys.sort.each do |action| + next if action == "_k_friendly_name" + + print(" " * indent) + print("\"#{group}\".") + print("\"#{action}\" = ") + + keys = groups[group][action]. + split(/(? 1 + print("[" + keys.map {|k| nix_val(k)}.join(" ") + "]") + elsif keys.first == "none" + print("[ ]") + else + print(nix_val(keys.first)) + end + + print(";\n") + end + end + end + ############################################################################ def nix_val(str) case str