at 17.09-beta 8.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let cfg = config.services.xserver.libinput; 6 xorgBool = v: if v then "on" else "off"; 7in { 8 9 options = { 10 11 services.xserver.libinput = { 12 13 enable = mkEnableOption "libinput"; 14 15 dev = mkOption { 16 type = types.nullOr types.str; 17 default = null; 18 example = "/dev/input/event0"; 19 description = 20 '' 21 Path for touchpad device. Set to null to apply to any 22 auto-detected touchpad. 23 ''; 24 }; 25 26 accelProfile = mkOption { 27 type = types.enum [ "flat" "adaptive" ]; 28 default = "adaptive"; 29 example = "flat"; 30 description = 31 '' 32 Sets the pointer acceleration profile to the given profile. 33 Permitted values are adaptive, flat. 34 Not all devices support this option or all profiles. 35 If a profile is unsupported, the default profile for this is used. 36 <literal>flat</literal>: Pointer motion is accelerated by a constant 37 (device-specific) factor, depending on the current speed. 38 <literal>adaptive</literal>: Pointer acceleration depends on the input speed. 39 This is the default profile for most devices. 40 ''; 41 }; 42 43 accelSpeed = mkOption { 44 type = types.nullOr types.string; 45 default = null; 46 description = "Cursor acceleration (how fast speed increases from minSpeed to maxSpeed)."; 47 }; 48 49 buttonMapping = mkOption { 50 type = types.nullOr types.string; 51 default = null; 52 description = 53 '' 54 Sets the logical button mapping for this device, see XSetPointerMapping(3). The string must 55 be a space-separated list of button mappings in the order of the logical buttons on the 56 device, starting with button 1. The default mapping is "1 2 3 ... 32". A mapping of 0 deac 57 tivates the button. Multiple buttons can have the same mapping. Invalid mapping strings are 58 discarded and the default mapping is used for all buttons. Buttons not specified in the 59 user's mapping use the default mapping. See section BUTTON MAPPING for more details. 60 ''; 61 }; 62 63 calibrationMatrix = mkOption { 64 type = types.nullOr types.string; 65 default = null; 66 description = 67 '' 68 A string of 9 space-separated floating point numbers. Sets the calibration matrix to the 69 3x3 matrix where the first row is (abc), the second row is (def) and the third row is (ghi). 70 ''; 71 }; 72 73 clickMethod = mkOption { 74 type = types.nullOr (types.enum [ "none" "buttonareas" "clickfinger" ]); 75 default = null; 76 description = 77 '' 78 Enables a click method. Permitted values are none, buttonareas, clickfinger. 79 Not all devices support all methods, if an option is unsupported, 80 the default click method for this device is used. 81 ''; 82 }; 83 84 leftHanded = mkOption { 85 type = types.bool; 86 default = false; 87 description = "Enables left-handed button orientation, i.e. swapping left and right buttons."; 88 }; 89 90 middleEmulation = mkOption { 91 type = types.bool; 92 default = true; 93 description = 94 '' 95 Enables middle button emulation. When enabled, pressing the left and right buttons 96 simultaneously produces a middle mouse button click. 97 ''; 98 }; 99 100 naturalScrolling = mkOption { 101 type = types.bool; 102 default = false; 103 description = "Enables or disables natural scrolling behavior."; 104 }; 105 106 scrollButton = mkOption { 107 type = types.nullOr types.int; 108 default = null; 109 example = 1; 110 description = 111 '' 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. 114 ''; 115 }; 116 117 scrollMethod = mkOption { 118 type = types.enum [ "twofinger" "edge" "none" ]; 119 default = "twofinger"; 120 example = "edge"; 121 description = 122 '' 123 Specify the scrolling method. 124 ''; 125 }; 126 127 horizontalScrolling = mkOption { 128 type = types.bool; 129 default = true; 130 description = 131 '' 132 Disables horizontal scrolling. When disabled, this driver will discard any horizontal scroll 133 events from libinput. Note that this does not disable horizontal scrolling, it merely 134 discards the horizontal axis from any scroll events. 135 ''; 136 }; 137 138 sendEventsMode = mkOption { 139 type = types.enum [ "disabled" "enabled" "disabled-on-external-mouse" ]; 140 default = "enabled"; 141 example = "disabled"; 142 description = 143 '' 144 Sets the send events mode to disabled, enabled, or "disable when an external mouse is connected". 145 ''; 146 }; 147 148 tapping = mkOption { 149 type = types.bool; 150 default = true; 151 description = 152 '' 153 Enables or disables tap-to-click behavior. 154 ''; 155 }; 156 157 tappingDragLock = mkOption { 158 type = types.bool; 159 default = true; 160 description = 161 '' 162 Enables or disables drag lock during tapping behavior. When enabled, a finger up during tap- 163 and-drag will not immediately release the button. If the finger is set down again within the 164 timeout, the draging process continues. 165 ''; 166 }; 167 168 disableWhileTyping = mkOption { 169 type = types.bool; 170 default = true; 171 description = 172 '' 173 Disable input method while typing. 174 ''; 175 }; 176 177 additionalOptions = mkOption { 178 type = types.str; 179 default = ""; 180 example = 181 '' 182 Option "DragLockButtons" "L1 B1 L2 B2" 183 ''; 184 description = "Additional options for libinput touchpad driver."; 185 }; 186 187 }; 188 189 }; 190 191 192 config = mkIf cfg.enable { 193 194 services.xserver.modules = [ pkgs.xorg.xf86inputlibinput ]; 195 196 environment.systemPackages = [ pkgs.xorg.xf86inputlibinput ]; 197 198 services.udev.packages = [ pkgs.libinput ]; 199 200 services.xserver.config = 201 '' 202 # Automatically enable the libinput driver for all touchpads. 203 Section "InputClass" 204 Identifier "libinputConfiguration" 205 MatchIsTouchpad "on" 206 ${optionalString (cfg.dev != null) ''MatchDevicePath "${cfg.dev}"''} 207 Driver "libinput" 208 Option "AccelProfile" "${cfg.accelProfile}" 209 ${optionalString (cfg.accelSpeed != null) ''Option "AccelSpeed" "${cfg.accelSpeed}"''} 210 ${optionalString (cfg.buttonMapping != null) ''Option "ButtonMapping" "${cfg.buttonMapping}"''} 211 ${optionalString (cfg.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.calibrationMatrix}"''} 212 ${optionalString (cfg.clickMethod != null) ''Option "ClickMethod" "${cfg.clickMethod}"''} 213 Option "LeftHanded" "${xorgBool cfg.leftHanded}" 214 Option "MiddleEmulation" "${xorgBool cfg.middleEmulation}" 215 Option "NaturalScrolling" "${xorgBool cfg.naturalScrolling}" 216 ${optionalString (cfg.scrollButton != null) ''Option "ScrollButton" "${toString cfg.scrollButton}"''} 217 Option "ScrollMethod" "${cfg.scrollMethod}" 218 Option "HorizontalScrolling" "${xorgBool cfg.horizontalScrolling}" 219 Option "SendEventsMode" "${cfg.sendEventsMode}" 220 Option "Tapping" "${xorgBool cfg.tapping}" 221 Option "TappingDragLock" "${xorgBool cfg.tappingDragLock}" 222 Option "DisableWhileTyping" "${xorgBool cfg.disableWhileTyping}" 223 ${cfg.additionalOptions} 224 EndSection 225 ''; 226 227 assertions = [ 228 # already present in synaptics.nix 229 /* { 230 assertion = !config.services.xserver.synaptics.enable; 231 message = "Synaptics and libinput are incompatible, you cannot enable both (in services.xserver)."; 232 } */ 233 ]; 234 235 }; 236 237}