From cd15b3a30a6f95b83f1e4cff11f6ebaf8d0ba66e Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 10 Jan 2021 00:46:13 -0300 Subject: [PATCH 1/3] nixos/libinput: separate settings by mouse/touchpad This commits deprecates `services.xserver.libinput` for multiple settings, one for each kind of device: - `services.xserver.libinput.mouse` - `services.xserver.libinput.touchpad` Looking at `man 4 libinput`, they basically have the same options so I simply replicated them, even if some options doesn't make sense for mouse (`tapping` for example). With this commit this is now possible: ```nix { services.xserver.libinput = { enable = true; mouse = { accelProfile = "flat"; }; touchpad = { naturalScrolling = true; }; }; } ``` And you will have a mouse with no natural scrolling but with accel profile flat, while touchpad will have natural scrolling but accel profile adaptative (default). It is possible to support more device types (tablets/keyboards/touchscreens), but at least looking at the libinput manual for those devices it doesn't seem that it has any configuration options for them. They can still be configured using `services.xserver.inputClassSections` though, and this will work now since there is no rule by default that matches them. Closes issue #75007, while also making configuration of mouses and touchpads using Nix attrs possible like said in PR #73785. --- .../services/x11/hardware/libinput.nix | 96 ++++++++++++------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/nixos/modules/services/x11/hardware/libinput.nix b/nixos/modules/services/x11/hardware/libinput.nix index 9548ecb8ef6d..631fb8247689 100644 --- a/nixos/modules/services/x11/hardware/libinput.nix +++ b/nixos/modules/services/x11/hardware/libinput.nix @@ -3,23 +3,18 @@ with lib; let cfg = config.services.xserver.libinput; + xorgBool = v: if v then "on" else "off"; -in { - - options = { - - services.xserver.libinput = { - - enable = mkEnableOption "libinput"; + mkConfigForDevice = deviceType: { 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. + Path for ${deviceType} device. Set to null to apply to any + auto-detected ${deviceType}. ''; }; @@ -185,14 +180,63 @@ in { Option "DragLockButtons" "L1 B1 L2 B2" ''; description = '' - Additional options for libinput touchpad driver. See + Additional options for libinput ${deviceType} driver. See libinput4 for available options."; ''; }; - }; + mkX11ConfigForDevice = deviceType: matchIs: '' + Identifier "libinput ${deviceType} configuration" + MatchDriver "libinput" + MatchIs${matchIs} "${xorgBool true}" + ${optionalString (cfg.${deviceType}.dev != null) ''MatchDevicePath "${cfg.${deviceType}.dev}"''} + Option "AccelProfile" "${cfg.${deviceType}.accelProfile}" + ${optionalString (cfg.${deviceType}.accelSpeed != null) ''Option "AccelSpeed" "${cfg.${deviceType}.accelSpeed}"''} + ${optionalString (cfg.${deviceType}.buttonMapping != null) ''Option "ButtonMapping" "${cfg.${deviceType}.buttonMapping}"''} + ${optionalString (cfg.${deviceType}.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.${deviceType}.calibrationMatrix}"''} + ${optionalString (cfg.${deviceType}.clickMethod != null) ''Option "ClickMethod" "${cfg.${deviceType}.clickMethod}"''} + Option "LeftHanded" "${xorgBool cfg.${deviceType}.leftHanded}" + Option "MiddleEmulation" "${xorgBool cfg.${deviceType}.middleEmulation}" + Option "NaturalScrolling" "${xorgBool cfg.${deviceType}.naturalScrolling}" + ${optionalString (cfg.${deviceType}.scrollButton != null) ''Option "ScrollButton" "${toString cfg.${deviceType}.scrollButton}"''} + Option "ScrollMethod" "${cfg.${deviceType}.scrollMethod}" + Option "HorizontalScrolling" "${xorgBool cfg.${deviceType}.horizontalScrolling}" + Option "SendEventsMode" "${cfg.${deviceType}.sendEventsMode}" + Option "Tapping" "${xorgBool cfg.${deviceType}.tapping}" + Option "TappingDragLock" "${xorgBool cfg.${deviceType}.tappingDragLock}" + Option "DisableWhileTyping" "${xorgBool cfg.${deviceType}.disableWhileTyping}" + ${cfg.${deviceType}.additionalOptions} + ''; +in { + + imports = + (map (option: mkRenamedOptionModule ([ "services" "xserver" "libinput" option ]) [ "services" "xserver" "libinput" "touchpad" option ]) [ + "accelProfile" + "accelSpeed" + "buttonMapping" + "calibrationMatrix" + "clickMethod" + "leftHanded" + "middleEmulation" + "naturalScrolling" + "scrollButton" + "scrollMethod" + "horizontalScrolling" + "sendEventsMode" + "tapping" + "disableWhileTyping" + "additionalOptions" + ]); + + options = { + + services.xserver.libinput = { + enable = mkEnableOption "libinput"; + mouse = mkConfigForDevice "mouse"; + touchpad = mkConfigForDevice "touchpad"; + }; }; @@ -212,32 +256,10 @@ in { services.udev.packages = [ pkgs.libinput.out ]; - services.xserver.config = - '' - # General libinput configuration. - # See CONFIGURATION DETAILS section of man:libinput(4). - Section "InputClass" - Identifier "libinputConfiguration" - MatchDriver "libinput" - ${optionalString (cfg.dev != null) ''MatchDevicePath "${cfg.dev}"''} - Option "AccelProfile" "${cfg.accelProfile}" - ${optionalString (cfg.accelSpeed != null) ''Option "AccelSpeed" "${cfg.accelSpeed}"''} - ${optionalString (cfg.buttonMapping != null) ''Option "ButtonMapping" "${cfg.buttonMapping}"''} - ${optionalString (cfg.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.calibrationMatrix}"''} - ${optionalString (cfg.clickMethod != null) ''Option "ClickMethod" "${cfg.clickMethod}"''} - Option "LeftHanded" "${xorgBool cfg.leftHanded}" - Option "MiddleEmulation" "${xorgBool cfg.middleEmulation}" - Option "NaturalScrolling" "${xorgBool cfg.naturalScrolling}" - ${optionalString (cfg.scrollButton != null) ''Option "ScrollButton" "${toString cfg.scrollButton}"''} - Option "ScrollMethod" "${cfg.scrollMethod}" - Option "HorizontalScrolling" "${xorgBool cfg.horizontalScrolling}" - Option "SendEventsMode" "${cfg.sendEventsMode}" - Option "Tapping" "${xorgBool cfg.tapping}" - Option "TappingDragLock" "${xorgBool cfg.tappingDragLock}" - Option "DisableWhileTyping" "${xorgBool cfg.disableWhileTyping}" - ${cfg.additionalOptions} - EndSection - ''; + services.xserver.inputClassSections = [ + (mkX11ConfigForDevice "mouse" "Pointer") + (mkX11ConfigForDevice "touchpad" "Touchpad") + ]; assertions = [ # already present in synaptics.nix From 887386fbbebd4ef2969e65dd9e49ea5af6e57748 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 10 Jan 2021 01:03:30 -0300 Subject: [PATCH 2/3] nixos/doc: fix manual reference to libinput --- nixos/doc/manual/configuration/x-windows.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/doc/manual/configuration/x-windows.xml b/nixos/doc/manual/configuration/x-windows.xml index b33f6cf82b52..dd879702d7dc 100644 --- a/nixos/doc/manual/configuration/x-windows.xml +++ b/nixos/doc/manual/configuration/x-windows.xml @@ -186,7 +186,7 @@ The driver has many options (see ). For instance, the following disables tap-to-click behavior: - = false; + = false; Note: the use of services.xserver.synaptics is deprecated since NixOS 17.09. From 0f762e558249529a6a55db3eebf6c2e943db3649 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 13 Jan 2021 10:17:23 -0300 Subject: [PATCH 3/3] nixos/doc: document services.xserver.libinput changes --- nixos/doc/manual/release-notes/rl-2103.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-2103.xml b/nixos/doc/manual/release-notes/rl-2103.xml index e46d1ca403f3..94e42369b605 100644 --- a/nixos/doc/manual/release-notes/rl-2103.xml +++ b/nixos/doc/manual/release-notes/rl-2103.xml @@ -430,6 +430,17 @@ http://some.json-exporter.host:7979/probe?target=https://example.com/some/json/e dynamically allocated uid. + + + The libinput module has been updated with the ability to configure mouse and touchpad settings separately. + The options in services.xserver.libinput have been renamed to services.xserver.libinput.touchpad, + while there is a new services.xserver.libinput.mouse for mouse related configuration. + + + Since touchpad options no longer apply to all devices, you may want to replicate your touchpad configuration in + mouse section. + +