1 { config, lib, options, pkgs, ... }:
5 let cfg = config.services.xserver.synaptics;
6 opt = options.services.xserver.synaptics;
7 tapConfig = if cfg.tapButtons then enabledTapConfig else disabledTapConfig;
9 Option "MaxTapTime" "180"
10 Option "MaxTapMove" "220"
11 Option "TapButton1" "${builtins.elemAt cfg.fingersMap 0}"
12 Option "TapButton2" "${builtins.elemAt cfg.fingersMap 1}"
13 Option "TapButton3" "${builtins.elemAt cfg.fingersMap 2}"
15 disabledTapConfig = ''
16 Option "MaxTapTime" "0"
17 Option "MaxTapMove" "0"
18 Option "TapButton1" "0"
19 Option "TapButton2" "0"
20 Option "TapButton3" "0"
22 pkg = pkgs.xorg.xf86inputsynaptics;
23 etcFile = "X11/xorg.conf.d/70-synaptics.conf";
28 services.xserver.synaptics = {
33 description = lib.mdDoc "Whether to enable touchpad support. Deprecated: Consider services.xserver.libinput.enable.";
37 type = types.nullOr types.str;
39 example = "/dev/input/event0";
42 Path for touchpad device. Set to null to apply to any
43 auto-detected touchpad.
47 accelFactor = mkOption {
48 type = types.nullOr types.str;
50 description = lib.mdDoc "Cursor acceleration (how fast speed increases from minSpeed to maxSpeed).";
54 type = types.nullOr types.str;
56 description = lib.mdDoc "Cursor speed factor for precision finger motion.";
60 type = types.nullOr types.str;
62 description = lib.mdDoc "Cursor speed factor for highest-speed finger motion.";
65 scrollDelta = mkOption {
66 type = types.nullOr types.int;
69 description = lib.mdDoc "Move distance of the finger for a scroll event.";
72 twoFingerScroll = mkOption {
75 description = lib.mdDoc "Whether to enable two-finger drag-scrolling. Overridden by horizTwoFingerScroll and vertTwoFingerScroll.";
78 horizTwoFingerScroll = mkOption {
80 default = cfg.twoFingerScroll;
81 defaultText = literalExpression "config.${opt.twoFingerScroll}";
82 description = lib.mdDoc "Whether to enable horizontal two-finger drag-scrolling.";
85 vertTwoFingerScroll = mkOption {
87 default = cfg.twoFingerScroll;
88 defaultText = literalExpression "config.${opt.twoFingerScroll}";
89 description = lib.mdDoc "Whether to enable vertical two-finger drag-scrolling.";
92 horizEdgeScroll = mkOption {
94 default = ! cfg.horizTwoFingerScroll;
95 defaultText = literalExpression "! config.${opt.horizTwoFingerScroll}";
96 description = lib.mdDoc "Whether to enable horizontal edge drag-scrolling.";
99 vertEdgeScroll = mkOption {
101 default = ! cfg.vertTwoFingerScroll;
102 defaultText = literalExpression "! config.${opt.vertTwoFingerScroll}";
103 description = lib.mdDoc "Whether to enable vertical edge drag-scrolling.";
106 tapButtons = mkOption {
109 description = lib.mdDoc "Whether to enable tap buttons.";
112 buttonsMap = mkOption {
113 type = types.listOf types.int;
116 description = lib.mdDoc "Remap touchpad buttons.";
117 apply = map toString;
120 fingersMap = mkOption {
121 type = types.listOf types.int;
124 description = lib.mdDoc "Remap several-fingers taps.";
125 apply = map toString;
128 palmDetect = mkOption {
131 description = lib.mdDoc "Whether to enable palm detection (hardware support required)";
134 palmMinWidth = mkOption {
135 type = types.nullOr types.int;
138 description = lib.mdDoc "Minimum finger width at which touch is considered a palm";
141 palmMinZ = mkOption {
142 type = types.nullOr types.int;
145 description = lib.mdDoc "Minimum finger pressure at which touch is considered a palm";
148 horizontalScroll = mkOption {
151 description = lib.mdDoc "Whether to enable horizontal scrolling (on touchpad)";
154 additionalOptions = mkOption {
158 Option "RTCornerButton" "2"
159 Option "RBCornerButton" "3"
161 description = lib.mdDoc ''
162 Additional options for synaptics touchpad driver.
171 config = mkIf cfg.enable {
173 services.xserver.modules = [ pkg.out ];
175 environment.etc.${etcFile}.source =
176 "${pkg.out}/share/X11/xorg.conf.d/70-synaptics.conf";
178 environment.systemPackages = [ pkg ];
180 services.xserver.config =
182 # Automatically enable the synaptics driver for all touchpads.
184 Identifier "synaptics touchpad catchall"
186 ${optionalString (cfg.dev != null) ''MatchDevicePath "${cfg.dev}"''}
188 ${optionalString (cfg.minSpeed != null) ''Option "MinSpeed" "${cfg.minSpeed}"''}
189 ${optionalString (cfg.maxSpeed != null) ''Option "MaxSpeed" "${cfg.maxSpeed}"''}
190 ${optionalString (cfg.accelFactor != null) ''Option "AccelFactor" "${cfg.accelFactor}"''}
191 ${optionalString cfg.tapButtons tapConfig}
192 Option "ClickFinger1" "${builtins.elemAt cfg.buttonsMap 0}"
193 Option "ClickFinger2" "${builtins.elemAt cfg.buttonsMap 1}"
194 Option "ClickFinger3" "${builtins.elemAt cfg.buttonsMap 2}"
195 Option "VertTwoFingerScroll" "${if cfg.vertTwoFingerScroll then "1" else "0"}"
196 Option "HorizTwoFingerScroll" "${if cfg.horizTwoFingerScroll then "1" else "0"}"
197 Option "VertEdgeScroll" "${if cfg.vertEdgeScroll then "1" else "0"}"
198 Option "HorizEdgeScroll" "${if cfg.horizEdgeScroll then "1" else "0"}"
199 ${optionalString cfg.palmDetect ''Option "PalmDetect" "1"''}
200 ${optionalString (cfg.palmMinWidth != null) ''Option "PalmMinWidth" "${toString cfg.palmMinWidth}"''}
201 ${optionalString (cfg.palmMinZ != null) ''Option "PalmMinZ" "${toString cfg.palmMinZ}"''}
202 ${optionalString (cfg.scrollDelta != null) ''Option "VertScrollDelta" "${toString cfg.scrollDelta}"''}
203 ${if !cfg.horizontalScroll then ''Option "HorizScrollDelta" "0"''
204 else (optionalString (cfg.scrollDelta != null) ''Option "HorizScrollDelta" "${toString cfg.scrollDelta}"'')}
205 ${cfg.additionalOptions}
211 assertion = !config.services.xserver.libinput.enable;
212 message = "Synaptics and libinput are incompatible, you cannot enable both (in services.xserver).";