1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7with lib;
8let
9 cfg = config.services.xserver.imwheel;
10in
11{
12 options = {
13 services.xserver.imwheel = {
14 enable = mkEnableOption "IMWheel service";
15
16 extraOptions = mkOption {
17 type = types.listOf types.str;
18 default = [ "--buttons=45" ];
19 example = [ "--debug" ];
20 description = ''
21 Additional command-line arguments to pass to
22 {command}`imwheel`.
23 '';
24 };
25
26 rules = mkOption {
27 type = types.attrsOf types.str;
28 default = { };
29 example = literalExpression ''
30 {
31 ".*" = '''
32 None, Up, Button4, 8
33 None, Down, Button5, 8
34 Shift_L, Up, Shift_L|Button4, 4
35 Shift_L, Down, Shift_L|Button5, 4
36 Control_L, Up, Control_L|Button4
37 Control_L, Down, Control_L|Button5
38 ''';
39 }
40 '';
41 description = ''
42 Window class translation rules.
43 /etc/X11/imwheelrc is generated based on this config
44 which means this config is global for all users.
45 See [official man pages](https://imwheel.sourceforge.net/imwheel.1.html)
46 for more information.
47 '';
48 };
49 };
50 };
51
52 config = mkIf cfg.enable {
53 environment.systemPackages = [ pkgs.imwheel ];
54
55 environment.etc."X11/imwheel/imwheelrc".source = pkgs.writeText "imwheelrc" (
56 concatStringsSep "\n\n" (mapAttrsToList (rule: conf: "\"${rule}\"\n${conf}") cfg.rules)
57 );
58
59 systemd.user.services.imwheel = {
60 description = "imwheel service";
61 wantedBy = [ "graphical-session.target" ];
62 partOf = [ "graphical-session.target" ];
63 serviceConfig = {
64 ExecStart =
65 "${pkgs.imwheel}/bin/imwheel "
66 + escapeShellArgs (
67 [
68 "--detach"
69 "--kill"
70 ]
71 ++ cfg.extraOptions
72 );
73 ExecStop = "${pkgs.procps}/bin/pkill imwheel";
74 RestartSec = 3;
75 Restart = "always";
76 };
77 };
78 };
79}