at 24.11-pre 7.3 kB view raw
1{ config, lib, options, pkgs, ... }: 2 3with lib; 4 5let cfg = config.services.xserver.synaptics; 6 opt = options.services.xserver.synaptics; 7 tapConfig = if cfg.tapButtons then enabledTapConfig else disabledTapConfig; 8 enabledTapConfig = '' 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}" 14 ''; 15 disabledTapConfig = '' 16 Option "MaxTapTime" "0" 17 Option "MaxTapMove" "0" 18 Option "TapButton1" "0" 19 Option "TapButton2" "0" 20 Option "TapButton3" "0" 21 ''; 22 pkg = pkgs.xorg.xf86inputsynaptics; 23 etcFile = "X11/xorg.conf.d/70-synaptics.conf"; 24in { 25 26 options = { 27 28 services.xserver.synaptics = { 29 30 enable = mkOption { 31 type = types.bool; 32 default = false; 33 description = "Whether to enable touchpad support. Deprecated: Consider services.libinput.enable."; 34 }; 35 36 dev = mkOption { 37 type = types.nullOr types.str; 38 default = null; 39 example = "/dev/input/event0"; 40 description = '' 41 Path for touchpad device. Set to null to apply to any 42 auto-detected touchpad. 43 ''; 44 }; 45 46 accelFactor = mkOption { 47 type = types.nullOr types.str; 48 default = "0.001"; 49 description = "Cursor acceleration (how fast speed increases from minSpeed to maxSpeed)."; 50 }; 51 52 minSpeed = mkOption { 53 type = types.nullOr types.str; 54 default = "0.6"; 55 description = "Cursor speed factor for precision finger motion."; 56 }; 57 58 maxSpeed = mkOption { 59 type = types.nullOr types.str; 60 default = "1.0"; 61 description = "Cursor speed factor for highest-speed finger motion."; 62 }; 63 64 scrollDelta = mkOption { 65 type = types.nullOr types.int; 66 default = null; 67 example = 75; 68 description = "Move distance of the finger for a scroll event."; 69 }; 70 71 twoFingerScroll = mkOption { 72 type = types.bool; 73 default = false; 74 description = "Whether to enable two-finger drag-scrolling. Overridden by horizTwoFingerScroll and vertTwoFingerScroll."; 75 }; 76 77 horizTwoFingerScroll = mkOption { 78 type = types.bool; 79 default = cfg.twoFingerScroll; 80 defaultText = literalExpression "config.${opt.twoFingerScroll}"; 81 description = "Whether to enable horizontal two-finger drag-scrolling."; 82 }; 83 84 vertTwoFingerScroll = mkOption { 85 type = types.bool; 86 default = cfg.twoFingerScroll; 87 defaultText = literalExpression "config.${opt.twoFingerScroll}"; 88 description = "Whether to enable vertical two-finger drag-scrolling."; 89 }; 90 91 horizEdgeScroll = mkOption { 92 type = types.bool; 93 default = ! cfg.horizTwoFingerScroll; 94 defaultText = literalExpression "! config.${opt.horizTwoFingerScroll}"; 95 description = "Whether to enable horizontal edge drag-scrolling."; 96 }; 97 98 vertEdgeScroll = mkOption { 99 type = types.bool; 100 default = ! cfg.vertTwoFingerScroll; 101 defaultText = literalExpression "! config.${opt.vertTwoFingerScroll}"; 102 description = "Whether to enable vertical edge drag-scrolling."; 103 }; 104 105 tapButtons = mkOption { 106 type = types.bool; 107 default = true; 108 description = "Whether to enable tap buttons."; 109 }; 110 111 buttonsMap = mkOption { 112 type = types.listOf types.int; 113 default = [1 2 3]; 114 example = [1 3 2]; 115 description = "Remap touchpad buttons."; 116 apply = map toString; 117 }; 118 119 fingersMap = mkOption { 120 type = types.listOf types.int; 121 default = [1 2 3]; 122 example = [1 3 2]; 123 description = "Remap several-fingers taps."; 124 apply = map toString; 125 }; 126 127 palmDetect = mkOption { 128 type = types.bool; 129 default = false; 130 description = "Whether to enable palm detection (hardware support required)"; 131 }; 132 133 palmMinWidth = mkOption { 134 type = types.nullOr types.int; 135 default = null; 136 example = 5; 137 description = "Minimum finger width at which touch is considered a palm"; 138 }; 139 140 palmMinZ = mkOption { 141 type = types.nullOr types.int; 142 default = null; 143 example = 20; 144 description = "Minimum finger pressure at which touch is considered a palm"; 145 }; 146 147 horizontalScroll = mkOption { 148 type = types.bool; 149 default = true; 150 description = "Whether to enable horizontal scrolling (on touchpad)"; 151 }; 152 153 additionalOptions = mkOption { 154 type = types.str; 155 default = ""; 156 example = '' 157 Option "RTCornerButton" "2" 158 Option "RBCornerButton" "3" 159 ''; 160 description = '' 161 Additional options for synaptics touchpad driver. 162 ''; 163 }; 164 165 }; 166 167 }; 168 169 170 config = mkIf cfg.enable { 171 172 services.xserver.modules = [ pkg.out ]; 173 174 environment.etc.${etcFile}.source = 175 "${pkg.out}/share/X11/xorg.conf.d/70-synaptics.conf"; 176 177 environment.systemPackages = [ pkg ]; 178 179 services.xserver.config = 180 '' 181 # Automatically enable the synaptics driver for all touchpads. 182 Section "InputClass" 183 Identifier "synaptics touchpad catchall" 184 MatchIsTouchpad "on" 185 ${optionalString (cfg.dev != null) ''MatchDevicePath "${cfg.dev}"''} 186 Driver "synaptics" 187 ${optionalString (cfg.minSpeed != null) ''Option "MinSpeed" "${cfg.minSpeed}"''} 188 ${optionalString (cfg.maxSpeed != null) ''Option "MaxSpeed" "${cfg.maxSpeed}"''} 189 ${optionalString (cfg.accelFactor != null) ''Option "AccelFactor" "${cfg.accelFactor}"''} 190 ${optionalString cfg.tapButtons tapConfig} 191 Option "ClickFinger1" "${builtins.elemAt cfg.buttonsMap 0}" 192 Option "ClickFinger2" "${builtins.elemAt cfg.buttonsMap 1}" 193 Option "ClickFinger3" "${builtins.elemAt cfg.buttonsMap 2}" 194 Option "VertTwoFingerScroll" "${if cfg.vertTwoFingerScroll then "1" else "0"}" 195 Option "HorizTwoFingerScroll" "${if cfg.horizTwoFingerScroll then "1" else "0"}" 196 Option "VertEdgeScroll" "${if cfg.vertEdgeScroll then "1" else "0"}" 197 Option "HorizEdgeScroll" "${if cfg.horizEdgeScroll then "1" else "0"}" 198 ${optionalString cfg.palmDetect ''Option "PalmDetect" "1"''} 199 ${optionalString (cfg.palmMinWidth != null) ''Option "PalmMinWidth" "${toString cfg.palmMinWidth}"''} 200 ${optionalString (cfg.palmMinZ != null) ''Option "PalmMinZ" "${toString cfg.palmMinZ}"''} 201 ${optionalString (cfg.scrollDelta != null) ''Option "VertScrollDelta" "${toString cfg.scrollDelta}"''} 202 ${if !cfg.horizontalScroll then ''Option "HorizScrollDelta" "0"'' 203 else (optionalString (cfg.scrollDelta != null) ''Option "HorizScrollDelta" "${toString cfg.scrollDelta}"'')} 204 ${cfg.additionalOptions} 205 EndSection 206 ''; 207 208 assertions = [ 209 { 210 assertion = !config.services.libinput.enable; 211 message = "Synaptics and libinput are incompatible, you cannot enable both."; 212 } 213 ]; 214 215 }; 216 217}