1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let cfg = config.services.xserver.synaptics;
6 tapConfig = if cfg.tapButtons then enabledTapConfig else disabledTapConfig;
7 enabledTapConfig = ''
8 Option "MaxTapTime" "180"
9 Option "MaxTapMove" "220"
10 Option "TapButton1" "${builtins.elemAt cfg.fingersMap 0}"
11 Option "TapButton2" "${builtins.elemAt cfg.fingersMap 1}"
12 Option "TapButton3" "${builtins.elemAt cfg.fingersMap 2}"
13 '';
14 disabledTapConfig = ''
15 Option "MaxTapTime" "0"
16 Option "MaxTapMove" "0"
17 Option "TapButton1" "0"
18 Option "TapButton2" "0"
19 Option "TapButton3" "0"
20 '';
21in {
22
23 options = {
24
25 services.xserver.synaptics = {
26
27 enable = mkOption {
28 type = types.bool;
29 default = false;
30 example = true;
31 description = "Whether to enable touchpad support.";
32 };
33
34 dev = mkOption {
35 type = types.nullOr types.str;
36 default = null;
37 example = "/dev/input/event0";
38 description =
39 ''
40 Path for touchpad device. Set to null to apply to any
41 auto-detected touchpad.
42 '';
43 };
44
45 accelFactor = mkOption {
46 type = types.nullOr types.string;
47 default = "0.001";
48 description = "Cursor acceleration (how fast speed increases from minSpeed to maxSpeed).";
49 };
50
51 minSpeed = mkOption {
52 type = types.nullOr types.string;
53 default = "0.6";
54 description = "Cursor speed factor for precision finger motion.";
55 };
56
57 maxSpeed = mkOption {
58 type = types.nullOr types.string;
59 default = "1.0";
60 description = "Cursor speed factor for highest-speed finger motion.";
61 };
62
63 twoFingerScroll = mkOption {
64 type = types.bool;
65 default = false;
66 description = "Whether to enable two-finger drag-scrolling. Overridden by horizTwoFingerScroll and vertTwoFingerScroll.";
67 };
68
69 horizTwoFingerScroll = mkOption {
70 type = types.bool;
71 default = cfg.twoFingerScroll;
72 description = "Whether to enable horizontal two-finger drag-scrolling.";
73 };
74
75 vertTwoFingerScroll = mkOption {
76 type = types.bool;
77 default = cfg.twoFingerScroll;
78 description = "Whether to enable vertical two-finger drag-scrolling.";
79 };
80
81 horizEdgeScroll = mkOption {
82 type = types.bool;
83 default = ! cfg.horizTwoFingerScroll;
84 description = "Whether to enable horizontal edge drag-scrolling.";
85 };
86
87 vertEdgeScroll = mkOption {
88 type = types.bool;
89 default = ! cfg.vertTwoFingerScroll;
90 description = "Whether to enable vertical edge drag-scrolling.";
91 };
92
93 tapButtons = mkOption {
94 type = types.bool;
95 default = true;
96 example = false;
97 description = "Whether to enable tap buttons.";
98 };
99
100 buttonsMap = mkOption {
101 type = types.listOf types.int;
102 default = [1 2 3];
103 example = [1 3 2];
104 description = "Remap touchpad buttons.";
105 apply = map toString;
106 };
107
108 fingersMap = mkOption {
109 type = types.listOf types.int;
110 default = [1 2 3];
111 example = [1 3 2];
112 description = "Remap several-fingers taps.";
113 apply = map toString;
114 };
115
116 palmDetect = mkOption {
117 type = types.bool;
118 default = false;
119 example = true;
120 description = "Whether to enable palm detection (hardware support required)";
121 };
122
123 horizontalScroll = mkOption {
124 type = types.bool;
125 default = true;
126 example = false;
127 description = "Whether to enable horizontal scrolling (on touchpad)";
128 };
129
130 additionalOptions = mkOption {
131 type = types.str;
132 default = "";
133 example = ''
134 Option "RTCornerButton" "2"
135 Option "RBCornerButton" "3"
136 '';
137 description = ''
138 Additional options for synaptics touchpad driver.
139 '';
140 };
141
142 };
143
144 };
145
146
147 config = mkIf cfg.enable {
148
149 services.xserver.modules = [ pkgs.xorg.xf86inputsynaptics ];
150
151 environment.systemPackages = [ pkgs.xorg.xf86inputsynaptics ];
152
153 services.xserver.config =
154 ''
155 # Automatically enable the synaptics driver for all touchpads.
156 Section "InputClass"
157 Identifier "synaptics touchpad catchall"
158 MatchIsTouchpad "on"
159 ${optionalString (cfg.dev != null) ''MatchDevicePath "${cfg.dev}"''}
160 Driver "synaptics"
161 ${optionalString (cfg.minSpeed != null) ''Option "MinSpeed" "${cfg.minSpeed}"''}
162 ${optionalString (cfg.maxSpeed != null) ''Option "MaxSpeed" "${cfg.maxSpeed}"''}
163 ${optionalString (cfg.accelFactor != null) ''Option "AccelFactor" "${cfg.accelFactor}"''}
164 ${optionalString cfg.tapButtons tapConfig}
165 Option "ClickFinger1" "${builtins.elemAt cfg.buttonsMap 0}"
166 Option "ClickFinger2" "${builtins.elemAt cfg.buttonsMap 1}"
167 Option "ClickFinger3" "${builtins.elemAt cfg.buttonsMap 2}"
168 Option "VertTwoFingerScroll" "${if cfg.vertTwoFingerScroll then "1" else "0"}"
169 Option "HorizTwoFingerScroll" "${if cfg.horizTwoFingerScroll then "1" else "0"}"
170 Option "VertEdgeScroll" "${if cfg.vertEdgeScroll then "1" else "0"}"
171 Option "HorizEdgeScroll" "${if cfg.horizEdgeScroll then "1" else "0"}"
172 ${if cfg.palmDetect then ''Option "PalmDetect" "1"'' else ""}
173 ${if cfg.horizontalScroll then "" else ''Option "HorizScrollDelta" "0"''}
174 ${cfg.additionalOptions}
175 EndSection
176 '';
177
178 };
179
180}