fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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