1 { config, lib, pkgs, ... }:
5 let cfg = config.services.xserver.libinput;
7 xorgBool = v: if v then "on" else "off";
9 mkConfigForDevice = deviceType: {
11 type = types.nullOr types.str;
13 example = "/dev/input/event0";
16 Path for ${deviceType} device. Set to `null` to apply to any
17 auto-detected ${deviceType}.
21 accelProfile = mkOption {
22 type = types.enum [ "flat" "adaptive" ];
27 Sets the pointer acceleration profile to the given profile.
28 Permitted values are `adaptive`, `flat`.
29 Not all devices support this option or all profiles.
30 If a profile is unsupported, the default profile for this is used.
31 `flat`: Pointer motion is accelerated by a constant
32 (device-specific) factor, depending on the current speed.
33 `adaptive`: Pointer acceleration depends on the input speed.
34 This is the default profile for most devices.
38 accelSpeed = mkOption {
39 type = types.nullOr types.str;
42 description = lib.mdDoc "Cursor acceleration (how fast speed increases from minSpeed to maxSpeed).";
45 buttonMapping = mkOption {
46 type = types.nullOr types.str;
48 example = "1 6 3 4 5 0 7";
51 Sets the logical button mapping for this device, see XSetPointerMapping(3). The string must
52 be a space-separated list of button mappings in the order of the logical buttons on the
53 device, starting with button 1. The default mapping is "1 2 3 ... 32". A mapping of 0 deac‐
54 tivates the button. Multiple buttons can have the same mapping. Invalid mapping strings are
55 discarded and the default mapping is used for all buttons. Buttons not specified in the
56 user's mapping use the default mapping. See section BUTTON MAPPING for more details.
60 calibrationMatrix = mkOption {
61 type = types.nullOr types.str;
63 example = "0.5 0 0 0 0.8 0.1 0 0 1";
66 A string of 9 space-separated floating point numbers. Sets the calibration matrix to the
67 3x3 matrix where the first row is (abc), the second row is (def) and the third row is (ghi).
71 clickMethod = mkOption {
72 type = types.nullOr (types.enum [ "none" "buttonareas" "clickfinger" ]);
74 example = "buttonareas";
77 Enables a click method. Permitted values are `none`,
78 `buttonareas`, `clickfinger`.
79 Not all devices support all methods, if an option is unsupported,
80 the default click method for this device is used.
84 leftHanded = mkOption {
87 description = lib.mdDoc "Enables left-handed button orientation, i.e. swapping left and right buttons.";
90 middleEmulation = mkOption {
95 Enables middle button emulation. When enabled, pressing the left and right buttons
96 simultaneously produces a middle mouse button click.
100 naturalScrolling = mkOption {
103 description = lib.mdDoc "Enables or disables natural scrolling behavior.";
106 scrollButton = mkOption {
107 type = types.nullOr types.int;
112 Designates a button as scroll button. If the ScrollMethod is button and the button is logically
113 held down, x/y axis movement is converted into scroll events.
117 scrollMethod = mkOption {
118 type = types.enum [ "twofinger" "edge" "button" "none" ];
119 default = "twofinger";
123 Specify the scrolling method: `twofinger`, `edge`,
128 horizontalScrolling = mkOption {
133 Disables horizontal scrolling. When disabled, this driver will discard any horizontal scroll
134 events from libinput. Note that this does not disable horizontal scrolling, it merely
135 discards the horizontal axis from any scroll events.
139 sendEventsMode = mkOption {
140 type = types.enum [ "disabled" "enabled" "disabled-on-external-mouse" ];
142 example = "disabled";
145 Sets the send events mode to `disabled`, `enabled`,
146 or `disabled-on-external-mouse`
155 Enables or disables tap-to-click behavior.
159 tappingButtonMap = mkOption {
160 type = types.nullOr (types.enum [ "lrm" "lmr" ]);
162 description = lib.mdDoc ''
163 Set the button mapping for 1/2/3-finger taps to left/right/middle or left/middle/right, respectively.
167 tappingDragLock = mkOption {
172 Enables or disables drag lock during tapping behavior. When enabled, a finger up during tap-
173 and-drag will not immediately release the button. If the finger is set down again within the
174 timeout, the draging process continues.
178 transformationMatrix = mkOption {
179 type = types.nullOr types.str;
181 example = "0.5 0 0 0 0.8 0.1 0 0 1";
182 description = lib.mdDoc ''
183 A string of 9 space-separated floating point numbers. Sets the transformation matrix to
184 the 3x3 matrix where the first row is (abc), the second row is (def) and the third row is (ghi).
188 disableWhileTyping = mkOption {
193 Disable input method while typing.
197 additionalOptions = mkOption {
202 Option "DragLockButtons" "L1 B1 L2 B2"
204 description = lib.mdDoc ''
205 Additional options for libinput ${deviceType} driver. See
206 {manpage}`libinput(4)`
207 for available options.";
212 mkX11ConfigForDevice = deviceType: matchIs: ''
213 Identifier "libinput ${deviceType} configuration"
214 MatchDriver "libinput"
215 MatchIs${matchIs} "${xorgBool true}"
216 ${optionalString (cfg.${deviceType}.dev != null) ''MatchDevicePath "${cfg.${deviceType}.dev}"''}
217 Option "AccelProfile" "${cfg.${deviceType}.accelProfile}"
218 ${optionalString (cfg.${deviceType}.accelSpeed != null) ''Option "AccelSpeed" "${cfg.${deviceType}.accelSpeed}"''}
219 ${optionalString (cfg.${deviceType}.buttonMapping != null) ''Option "ButtonMapping" "${cfg.${deviceType}.buttonMapping}"''}
220 ${optionalString (cfg.${deviceType}.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.${deviceType}.calibrationMatrix}"''}
221 ${optionalString (cfg.${deviceType}.transformationMatrix != null) ''Option "TransformationMatrix" "${cfg.${deviceType}.transformationMatrix}"''}
222 ${optionalString (cfg.${deviceType}.clickMethod != null) ''Option "ClickMethod" "${cfg.${deviceType}.clickMethod}"''}
223 Option "LeftHanded" "${xorgBool cfg.${deviceType}.leftHanded}"
224 Option "MiddleEmulation" "${xorgBool cfg.${deviceType}.middleEmulation}"
225 Option "NaturalScrolling" "${xorgBool cfg.${deviceType}.naturalScrolling}"
226 ${optionalString (cfg.${deviceType}.scrollButton != null) ''Option "ScrollButton" "${toString cfg.${deviceType}.scrollButton}"''}
227 Option "ScrollMethod" "${cfg.${deviceType}.scrollMethod}"
228 Option "HorizontalScrolling" "${xorgBool cfg.${deviceType}.horizontalScrolling}"
229 Option "SendEventsMode" "${cfg.${deviceType}.sendEventsMode}"
230 Option "Tapping" "${xorgBool cfg.${deviceType}.tapping}"
231 ${optionalString (cfg.${deviceType}.tappingButtonMap != null) ''Option "TappingButtonMap" "${cfg.${deviceType}.tappingButtonMap}"''}
232 Option "TappingDragLock" "${xorgBool cfg.${deviceType}.tappingDragLock}"
233 Option "DisableWhileTyping" "${xorgBool cfg.${deviceType}.disableWhileTyping}"
234 ${cfg.${deviceType}.additionalOptions}
239 (map (option: mkRenamedOptionModule ([ "services" "xserver" "libinput" option ]) [ "services" "xserver" "libinput" "touchpad" option ]) [
250 "horizontalScrolling"
255 "transformationMatrix"
262 services.xserver.libinput = {
263 enable = mkEnableOption (lib.mdDoc "libinput");
264 mouse = mkConfigForDevice "mouse";
265 touchpad = mkConfigForDevice "touchpad";
270 config = mkIf cfg.enable {
272 services.xserver.modules = [ pkgs.xorg.xf86inputlibinput ];
274 environment.systemPackages = [ pkgs.xorg.xf86inputlibinput ];
277 let cfgPath = "X11/xorg.conf.d/40-libinput.conf";
280 source = pkgs.xorg.xf86inputlibinput.out + "/share/" + cfgPath;
284 services.udev.packages = [ pkgs.libinput.out ];
286 services.xserver.inputClassSections = [
287 (mkX11ConfigForDevice "mouse" "Pointer")
288 (mkX11ConfigForDevice "touchpad" "Touchpad")
292 # already present in synaptics.nix
294 assertion = !config.services.xserver.synaptics.enable;
295 message = "Synaptics and libinput are incompatible, you cannot enable both (in services.xserver).";