2019-04-09 17:12:36 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.xcape;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2019-04-09 17:12:36 +02:00
|
|
|
meta.maintainers = [ maintainers.nickhu ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.xcape = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "xcape";
|
2019-04-09 17:12:36 +02:00
|
|
|
|
|
|
|
timeout = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 500;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2019-04-09 17:12:36 +02:00
|
|
|
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;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
Shift_L = "Escape";
|
|
|
|
Control_L = "Control_L|O";
|
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
The value has the grammar `Key[|OtherKey]`.
|
|
|
|
|
2019-04-09 17:12:36 +02:00
|
|
|
The list of key names is found in the header file
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`X11/keysymdef.h` (remove the
|
|
|
|
`XK_` prefix). Note that due to limitations
|
2019-04-09 17:12:36 +02:00
|
|
|
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
|
2023-07-01 01:30:13 +02:00
|
|
|
expression `Shift_L|bracketleft` could be
|
2019-04-09 17:12:36 +02:00
|
|
|
used (assuming that you have a key with "{" above "[").
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2019-04-09 17:12:36 +02:00
|
|
|
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 {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.xcape" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2019-04-09 17:12:36 +02:00
|
|
|
systemd.user.services.xcape = {
|
2021-07-20 03:16:14 +02:00
|
|
|
Unit = mkMerge [
|
|
|
|
{
|
|
|
|
Description = "xcape";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
}
|
|
|
|
(mkIf (config.home.keyboard != null && config.home.keyboard != { }) {
|
|
|
|
After = [ "graphical-session-pre.target" "setxkbmap.service" ];
|
|
|
|
})
|
|
|
|
];
|
2019-04-09 17:12:36 +02:00
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "forking";
|
|
|
|
ExecStart = "${pkgs.xcape}/bin/xcape"
|
|
|
|
+ optionalString (cfg.timeout != null) " -t ${toString cfg.timeout}"
|
2020-02-02 00:39:17 +01:00
|
|
|
+ optionalString (cfg.mapExpression != { }) " -e '${
|
|
|
|
builtins.concatStringsSep ";"
|
|
|
|
(attrsets.mapAttrsToList (n: v: "${n}=${v}") cfg.mapExpression)
|
|
|
|
}'";
|
2019-04-09 17:12:36 +02:00
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2019-04-09 17:12:36 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|