about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/x11/hardware/synaptics.nix
blob: e39a56528e82191e035ef1f96f117f5697265268 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
{ config, lib, pkgs, ... }:

with lib;

let cfg = config.services.xserver.synaptics;
    tapConfig = if cfg.tapButtons then enabledTapConfig else disabledTapConfig;
    enabledTapConfig = ''
      Option "MaxTapTime" "180"
      Option "MaxTapMove" "220"
      Option "TapButton1" "${builtins.elemAt cfg.fingersMap 0}"
      Option "TapButton2" "${builtins.elemAt cfg.fingersMap 1}"
      Option "TapButton3" "${builtins.elemAt cfg.fingersMap 2}"
    '';
    disabledTapConfig = ''
      Option "MaxTapTime" "0"
      Option "MaxTapMove" "0"
      Option "TapButton1" "0"
      Option "TapButton2" "0"
      Option "TapButton3" "0"
    '';
  pkg = pkgs.xorg.xf86inputsynaptics;
  etcFile = "X11/xorg.conf.d/70-synaptics.conf";
in {

  options = {

    services.xserver.synaptics = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable touchpad support. Deprecated: Consider services.xserver.libinput.enable.";
      };

      dev = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "/dev/input/event0";
        description =
          ''
            Path for touchpad device.  Set to null to apply to any
            auto-detected touchpad.
          '';
      };

      accelFactor = mkOption {
        type = types.nullOr types.str;
        default = "0.001";
        description = "Cursor acceleration (how fast speed increases from minSpeed to maxSpeed).";
      };

      minSpeed = mkOption {
        type = types.nullOr types.str;
        default = "0.6";
        description = "Cursor speed factor for precision finger motion.";
      };

      maxSpeed = mkOption {
        type = types.nullOr types.str;
        default = "1.0";
        description = "Cursor speed factor for highest-speed finger motion.";
      };

      scrollDelta = mkOption {
        type = types.nullOr types.int;
        default = null;
        example = 75;
        description = "Move distance of the finger for a scroll event.";
      };

      twoFingerScroll = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable two-finger drag-scrolling. Overridden by horizTwoFingerScroll and vertTwoFingerScroll.";
      };

      horizTwoFingerScroll = mkOption {
        type = types.bool;
        default = cfg.twoFingerScroll;
        description = "Whether to enable horizontal two-finger drag-scrolling.";
      };

      vertTwoFingerScroll = mkOption {
        type = types.bool;
        default = cfg.twoFingerScroll;
        description = "Whether to enable vertical two-finger drag-scrolling.";
      };

      horizEdgeScroll = mkOption {
        type = types.bool;
        default = ! cfg.horizTwoFingerScroll;
        description = "Whether to enable horizontal edge drag-scrolling.";
      };

      vertEdgeScroll = mkOption {
        type = types.bool;
        default = ! cfg.vertTwoFingerScroll;
        description = "Whether to enable vertical edge drag-scrolling.";
      };

      tapButtons = mkOption {
        type = types.bool;
        default = true;
        description = "Whether to enable tap buttons.";
      };

      buttonsMap = mkOption {
        type = types.listOf types.int;
        default = [1 2 3];
        example = [1 3 2];
        description = "Remap touchpad buttons.";
        apply = map toString;
      };

      fingersMap = mkOption {
        type = types.listOf types.int;
        default = [1 2 3];
        example = [1 3 2];
        description = "Remap several-fingers taps.";
        apply = map toString;
      };

      palmDetect = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable palm detection (hardware support required)";
      };

      palmMinWidth = mkOption {
        type = types.nullOr types.int;
        default = null;
        example = 5;
        description = "Minimum finger width at which touch is considered a palm";
      };

      palmMinZ = mkOption {
        type = types.nullOr types.int;
        default = null;
        example = 20;
        description = "Minimum finger pressure at which touch is considered a palm";
      };

      horizontalScroll = mkOption {
        type = types.bool;
        default = true;
        description = "Whether to enable horizontal scrolling (on touchpad)";
      };

      additionalOptions = mkOption {
        type = types.str;
        default = "";
        example = ''
          Option "RTCornerButton" "2"
          Option "RBCornerButton" "3"
        '';
        description = ''
          Additional options for synaptics touchpad driver.
        '';
      };

    };

  };


  config = mkIf cfg.enable {

    services.xserver.modules = [ pkg.out ];

    environment.etc."${etcFile}".source =
      "${pkg.out}/share/X11/xorg.conf.d/70-synaptics.conf";

    environment.systemPackages = [ pkg ];

    services.xserver.config =
      ''
        # Automatically enable the synaptics driver for all touchpads.
        Section "InputClass"
          Identifier "synaptics touchpad catchall"
          MatchIsTouchpad "on"
          ${optionalString (cfg.dev != null) ''MatchDevicePath "${cfg.dev}"''}
          Driver "synaptics"
          ${optionalString (cfg.minSpeed != null) ''Option "MinSpeed" "${cfg.minSpeed}"''}
          ${optionalString (cfg.maxSpeed != null) ''Option "MaxSpeed" "${cfg.maxSpeed}"''}
          ${optionalString (cfg.accelFactor != null) ''Option "AccelFactor" "${cfg.accelFactor}"''}
          ${optionalString cfg.tapButtons tapConfig}
          Option "ClickFinger1" "${builtins.elemAt cfg.buttonsMap 0}"
          Option "ClickFinger2" "${builtins.elemAt cfg.buttonsMap 1}"
          Option "ClickFinger3" "${builtins.elemAt cfg.buttonsMap 2}"
          Option "VertTwoFingerScroll" "${if cfg.vertTwoFingerScroll then "1" else "0"}"
          Option "HorizTwoFingerScroll" "${if cfg.horizTwoFingerScroll then "1" else "0"}"
          Option "VertEdgeScroll" "${if cfg.vertEdgeScroll then "1" else "0"}"
          Option "HorizEdgeScroll" "${if cfg.horizEdgeScroll then "1" else "0"}"
          ${optionalString cfg.palmDetect ''Option "PalmDetect" "1"''}
          ${optionalString (cfg.palmMinWidth != null) ''Option "PalmMinWidth" "${toString cfg.palmMinWidth}"''}
          ${optionalString (cfg.palmMinZ != null) ''Option "PalmMinZ" "${toString cfg.palmMinZ}"''}
          ${optionalString (cfg.scrollDelta != null) ''Option "VertScrollDelta" "${toString cfg.scrollDelta}"''}
          ${if !cfg.horizontalScroll then ''Option "HorizScrollDelta" "0"''
            else (optionalString (cfg.scrollDelta != null) ''Option "HorizScrollDelta" "${toString cfg.scrollDelta}"'')}
          ${cfg.additionalOptions}
        EndSection
      '';

    assertions = [
      {
        assertion = !config.services.xserver.libinput.enable;
        message = "Synaptics and libinput are incompatible, you cannot enable both (in services.xserver).";
      }
    ];

  };

}