1{ config, lib, pkgs, ... }:
2
3with lib;
4
5{
6 ###### interface
7
8 options = {
9
10 hardware.trackpoint = {
11
12 enable = mkOption {
13 default = false;
14 type = types.bool;
15 description = ''
16 Enable sensitivity and speed configuration for trackpoints.
17 '';
18 };
19
20 sensitivity = mkOption {
21 default = 128;
22 example = 255;
23 type = types.int;
24 description = ''
25 Configure the trackpoint sensitivity. By default, the kernel
26 configures 128.
27 '';
28 };
29
30 speed = mkOption {
31 default = 97;
32 example = 255;
33 type = types.int;
34 description = ''
35 Configure the trackpoint speed. By default, the kernel
36 configures 97.
37 '';
38 };
39
40 emulateWheel = mkOption {
41 default = false;
42 type = types.bool;
43 description = ''
44 Enable scrolling while holding the middle mouse button.
45 '';
46 };
47
48 fakeButtons = mkOption {
49 default = false;
50 type = types.bool;
51 description = ''
52 Switch to "bare" PS/2 mouse support in case Trackpoint buttons are not recognized
53 properly. This can happen for example on models like the L430, T450, T450s, on
54 which the Trackpoint buttons are actually a part of the Synaptics touchpad.
55 '';
56 };
57
58 };
59
60 };
61
62
63 ###### implementation
64
65 config =
66 let cfg = config.hardware.trackpoint; in
67 mkMerge [
68 (mkIf cfg.enable {
69 services.udev.extraRules =
70 ''
71 ACTION=="add|change", SUBSYSTEM=="input", ATTR{name}=="TPPS/2 IBM TrackPoint", ATTR{device/speed}="${toString cfg.speed}", ATTR{device/sensitivity}="${toString cfg.sensitivity}"
72 '';
73
74 system.activationScripts.trackpoint =
75 ''
76 ${config.systemd.package}/bin/udevadm trigger --attr-match=name="TPPS/2 IBM TrackPoint"
77 '';
78 })
79
80 (mkIf (cfg.emulateWheel) {
81 services.xserver.inputClassSections =
82 [''
83 Identifier "Trackpoint Wheel Emulation"
84 MatchProduct "${if cfg.fakeButtons then "PS/2 Generic Mouse" else "ETPS/2 Elantech TrackPoint|Elantech PS/2 TrackPoint|TPPS/2 IBM TrackPoint|DualPoint Stick|Synaptics Inc. Composite TouchPad / TrackPoint|ThinkPad USB Keyboard with TrackPoint|USB Trackpoint pointing device|Composite TouchPad / TrackPoint"}"
85 MatchDevicePath "/dev/input/event*"
86 Option "EmulateWheel" "true"
87 Option "EmulateWheelButton" "2"
88 Option "Emulate3Buttons" "false"
89 Option "XAxisMapping" "6 7"
90 Option "YAxisMapping" "4 5"
91 ''];
92 })
93
94 (mkIf cfg.fakeButtons {
95 boot.extraModprobeConfig = "options psmouse proto=bare";
96 })
97 ];
98}