1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let cfg = config.services.xserver.multitouch;
6 disabledTapConfig = ''
7 Option "MaxTapTime" "0"
8 Option "MaxTapMove" "0"
9 Option "TapButton1" "0"
10 Option "TapButton2" "0"
11 Option "TapButton3" "0"
12 '';
13in {
14
15 options = {
16
17 services.xserver.multitouch = {
18
19 enable = mkOption {
20 default = false;
21 example = true;
22 description = "Whether to enable multitouch touchpad support.";
23 };
24
25 invertScroll = mkOption {
26 default = false;
27 example = true;
28 type = types.bool;
29 description = "Whether to invert scrolling direction à la OSX Lion";
30 };
31
32 ignorePalm = mkOption {
33 default = false;
34 example = true;
35 type = types.bool;
36 description = "Whether to ignore touches detected as being the palm (i.e when typing)";
37 };
38
39 tapButtons = mkOption {
40 type = types.bool;
41 default = true;
42 example = false;
43 description = "Whether to enable tap buttons.";
44 };
45
46 buttonsMap = mkOption {
47 type = types.listOf types.int;
48 default = [3 2 0];
49 example = [1 3 2];
50 description = "Remap touchpad buttons.";
51 apply = map toString;
52 };
53
54 additionalOptions = mkOption {
55 type = types.str;
56 default = "";
57 example = ''
58 Option "ScaleDistance" "50"
59 Option "RotateDistance" "60"
60 '';
61 description = ''
62 Additional options for mtrack touchpad driver.
63 '';
64 };
65
66 };
67
68 };
69
70 config = mkIf cfg.enable {
71
72 services.xserver.modules = [ pkgs.xf86_input_mtrack ];
73
74 services.xserver.config =
75 ''
76 # Automatically enable the multitouch driver
77 Section "InputClass"
78 MatchIsTouchpad "on"
79 Identifier "Touchpads"
80 Driver "mtrack"
81 Option "IgnorePalm" "${if cfg.ignorePalm then "true" else "false"}"
82 Option "ClickFinger1" "${builtins.elemAt cfg.buttonsMap 0}"
83 Option "ClickFinger2" "${builtins.elemAt cfg.buttonsMap 1}"
84 Option "ClickFinger3" "${builtins.elemAt cfg.buttonsMap 2}"
85 ${optionalString (!cfg.tapButtons) disabledTapConfig}
86 ${optionalString cfg.invertScroll ''
87 Option "ScrollUpButton" "5"
88 Option "ScrollDownButton" "4"
89 Option "ScrollLeftButton" "7"
90 Option "ScrollRightButton" "6"
91 ''}
92 ${cfg.additionalOptions}
93 EndSection
94 '';
95
96 };
97
98}