mirror of
https://github.com/nix-community/plasma-manager.git
synced 2024-11-30 01:39:16 +03:00
module: Add shortcuts module
This commit is contained in:
parent
9e29bcddf3
commit
65e4ed1364
@ -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;
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
{
|
||||
imports = [
|
||||
./files.nix
|
||||
./shortcuts.nix
|
||||
./windows.nix
|
||||
./workspace.nix
|
||||
];
|
||||
|
46
modules/shortcuts.nix
Normal file
46
modules/shortcuts.nix
Normal file
@ -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;
|
||||
};
|
||||
}
|
@ -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(/(?<!\\),/).first.
|
||||
gsub(/\\?\\,/, ',').
|
||||
gsub(/\\t/, "\t").
|
||||
split(/\t/)
|
||||
|
||||
if keys.size > 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
|
||||
|
Loading…
Reference in New Issue
Block a user