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