@@ -0,0 +1,68 @@
1+{ config, lib, pkgs, ... }:
2+with lib;
3+let
4+ cfg = config.services.xserver.imwheel;
5+in
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</command>.
18+ '';
19+ };
20+
21+ rules = mkOption {
22+ type = types.attrsOf types.str;
23+ default = {};
24+ example = literalExample ''
25+ ".*" = '''
26+ None, Up, Button4, 8
27+ None, Down, Button5, 8
28+ Shift_L, Up, Shift_L|Button4, 4
29+ Shift_L, Down, Shift_L|Button5, 4
30+ Control_L, Up, Control_L|Button4
31+ Control_L, Down, Control_L|Button5
32+ ''';
33+ '';
34+ description = ''
35+ Window class translation rules.
36+ /etc/X11/imwheelrc is generated based on this config
37+ which means this config is global for all users.
38+ See <link xlink:href="http://imwheel.sourceforge.net/imwheel.1.html">offical man pages</link>
39+ for more informations.
40+ '';
41+ };
42+ };
43+ };
44+
45+ config = mkIf cfg.enable {
46+ environment.systemPackages = [ pkgs.imwheel ];
47+
48+ environment.etc."X11/imwheel/imwheelrc".source =
49+ pkgs.writeText "imwheelrc" (concatStringsSep "\n\n"
50+ (mapAttrsToList
51+ (rule: conf: "\"${rule}\"\n${conf}") cfg.rules
52+ ));
53+
54+ systemd.user.services.imwheel = {
55+ description = "imwheel service";
56+ wantedBy = [ "graphical-session.target" ];
57+ partOf = [ "graphical-session.target" ];
58+ serviceConfig = {
59+ ExecStart = "${pkgs.imwheel}/bin/imwheel " + escapeShellArgs ([
60+ "--detach"
61+ "--kill"
62+ ] ++ cfg.extraOptions);
63+ ExecStop = "${pkgs.procps}/bin/pkill imwheel";
64+ Restart = "on-failure";
65+ };
66+ };
67+ };
68+ }