fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . xcape ; 8 9in { 10meta . maintainers = [ maintainers . nickhu ]; 11 12options = { 13services . xcape = { 14enable = mkEnableOption "xcape" ; 15 16timeout = mkOption { 17type = types . nullOr types . int ; 18default = null ; 19example = 500 ; 20description = '' 21If you hold a key longer than this timeout, xcape will not 22generate a key event. Default is 500 ms. 23'' ; 24}; 25 26mapExpression = mkOption { 27type = types . attrsOf types . str ; 28default = { }; 29example = { 30Shift_L = "Escape" ; 31Control_L = "Control_L|O" ; 32}; 33description = '' 34The value has the grammar `Key[|OtherKey]`. 35 36The list of key names is found in the header file 37{file}`X11/keysymdef.h` (remove the 38`XK_` prefix). Note that due to limitations 39of X11 shifted keys must be specified as a shift key 40followed by the key to be pressed rather than the actual 41name of the character. For example to generate "{" the 42expression `Shift_L|bracketleft` could be 43used (assuming that you have a key with "{" above "["). 44 45You can also specify keys in decimal (prefix #), octal (#0), 46or hexadecimal (#0x). They will be interpreted as keycodes 47unless no corresponding key name is found. 48'' ; 49}; 50}; 51}; 52 53config = mkIf cfg . enable { 54assertions = [ 55( lib . hm . assertions . assertPlatform "services.xcape" pkgs 56lib . platforms . linux ) 57]; 58 59systemd . user . services . xcape = { 60Unit = mkMerge [ 61{ 62Description = "xcape" ; 63After = [ "graphical-session-pre.target" ]; 64PartOf = [ "graphical-session.target" ]; 65} 66( mkIf ( config . home . keyboard != null && config . home . keyboard != { }) { 67After = [ "graphical-session-pre.target" "setxkbmap.service" ]; 68}) 69]; 70 71Service = { 72Type = "forking" ; 73ExecStart = " ${ pkgs . xcape } /bin/xcape" 74+ optionalString ( cfg . timeout != null ) " -t ${ toString cfg . timeout } " 75+ optionalString ( cfg . mapExpression != { }) " -e ' ${ 76builtins . concatStringsSep ";" 77( attrsets . mapAttrsToList ( n : v : " ${ n } = ${ v } " ) cfg . mapExpression ) 78} '" ; 79}; 80 81Install = { WantedBy = [ "graphical-session.target" ]; }; 82}; 83}; 84}