From c48db4fbba204365c2750bef1665e26fae156590 Mon Sep 17 00:00:00 2001 From: Nick Hu Date: Tue, 9 Apr 2019 16:12:36 +0100 Subject: [PATCH] xcape: add service --- modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/services/xcape.nix | 76 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 modules/services/xcape.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 131c43e5e..29523c925 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1012,6 +1012,13 @@ in A new module is available: 'programs.lsd'. ''; } + + { + time = "2019-04-09T20:10:22+00:00"; + message = '' + A new module is available: 'services.xcape'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 1c2015f72..9153bb262 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -118,6 +118,7 @@ let (loadModule ./services/window-managers/awesome.nix { }) (loadModule ./services/window-managers/i3.nix { }) (loadModule ./services/window-managers/xmonad.nix { }) + (loadModule ./services/xcape.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/xembed-sni-proxy.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/xscreensaver.nix { }) (loadModule ./systemd.nix { }) diff --git a/modules/services/xcape.nix b/modules/services/xcape.nix new file mode 100644 index 000000000..26115a930 --- /dev/null +++ b/modules/services/xcape.nix @@ -0,0 +1,76 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.xcape; + +in + +{ + meta.maintainers = [ maintainers.nickhu ]; + + options = { + services.xcape = { + enable = mkEnableOption "xcape"; + + timeout = mkOption { + type = types.nullOr types.int; + default = null; + example = 500; + description = '' + If you hold a key longer than this timeout, xcape will not + generate a key event. Default is 500 ms. + ''; + }; + + mapExpression = mkOption { + type = types.attrsOf types.str; + default = {}; + example = { Shift_L = "Escape"; Control_L = "Control_L|O"; }; + description = '' + The value has the grammar Key[|OtherKey]. + + + The list of key names is found in the header file + X11/keysymdef.h (remove the + XK_ prefix). Note that due to limitations + of X11 shifted keys must be specified as a shift key + followed by the key to be pressed rather than the actual + name of the character. For example to generate "{" the + expression Shift_L|bracketleft could be + used (assuming that you have a key with "{" above "["). + + + You can also specify keys in decimal (prefix #), octal (#0), + or hexadecimal (#0x). They will be interpreted as keycodes + unless no corresponding key name is found. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.xcape = { + Unit = { + Description = "xcape"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + Type = "forking"; + ExecStart = "${pkgs.xcape}/bin/xcape" + + optionalString (cfg.timeout != null) " -t ${toString cfg.timeout}" + + optionalString (cfg.mapExpression != {}) + " -e '${builtins.concatStringsSep ";" + (attrsets.mapAttrsToList (n: v: "${n}=${v}") cfg.mapExpression)}'"; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; + }; +}