summary refs log tree commit diff
path: root/nixos/modules/services/x11/hardware/multitouch.nix
blob: c03bb3b494fb55fdb4df4b2de74acb7024ecb299 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{ config, lib, pkgs, ... }:

with lib;

let cfg = config.services.xserver.multitouch;
    disabledTapConfig = ''
      Option "MaxTapTime" "0"
      Option "MaxTapMove" "0"
      Option "TapButton1" "0"
      Option "TapButton2" "0"
      Option "TapButton3" "0"
    '';
in {

  options = {

    services.xserver.multitouch = {

      enable = mkOption {
        default = false;
        description = "Whether to enable multitouch touchpad support.";
      };

      invertScroll = mkOption {
        default = false;
        type = types.bool;
        description = "Whether to invert scrolling direction à la OSX Lion";
      };

      ignorePalm = mkOption {
        default = false;
        type = types.bool;
        description = "Whether to ignore touches detected as being the palm (i.e when typing)";
      };

      tapButtons = mkOption {
        type = types.bool;
        default = true;
        description = "Whether to enable tap buttons.";
      };

      buttonsMap = mkOption {
        type = types.listOf types.int;
        default = [3 2 0];
        example = [1 3 2];
        description = "Remap touchpad buttons.";
        apply = map toString;
      };

      additionalOptions = mkOption {
        type = types.str;
        default = "";
        example = ''
          Option "ScaleDistance" "50"
          Option "RotateDistance" "60"
        '';
        description = ''
          Additional options for mtrack touchpad driver.
        '';
      };

    };

  };

  config = mkIf cfg.enable {

    services.xserver.modules = [ pkgs.xf86_input_mtrack ];

    services.xserver.config =
      ''
        # Automatically enable the multitouch driver
        Section "InputClass"
          MatchIsTouchpad "on"
          Identifier "Touchpads"
          Driver "mtrack"
          Option "IgnorePalm" "${boolToString cfg.ignorePalm}"
          Option "ClickFinger1" "${builtins.elemAt cfg.buttonsMap 0}"
          Option "ClickFinger2" "${builtins.elemAt cfg.buttonsMap 1}"
          Option "ClickFinger3" "${builtins.elemAt cfg.buttonsMap 2}"
          ${optionalString (!cfg.tapButtons) disabledTapConfig}
          ${optionalString cfg.invertScroll ''
            Option "ScrollUpButton" "5"
            Option "ScrollDownButton" "4"
            Option "ScrollLeftButton" "7"
            Option "ScrollRightButton" "6"
          ''}
          ${cfg.additionalOptions}
        EndSection
      '';

  };

}