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