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