Nimbin[12]?Linux & System / Linux-disable-Middle-Mouse-Click / commits / f9bab56

Linux-disable-Middle-Mouse-Click git · main

Disable middle mouse click paste (evdev + sysv script)

linux evdev mouse c · first commit 2026-08-11 · last commit 2026-09-03 (2 months ago) · synced 1 hour ago · upstream: github.com/nimbin2/Linux-disable-Middle-Mouse-Click

C 72.9% Markdown 20.5% Shell 6.5%
git clone https://git.christianimmanuel.de/linux-system/Linux-disable-Middle-Mouse-Click.gitwget https://git.christianimmanuel.de/linux-system/Linux-disable-Middle-Mouse-Click/archive/Linux-disable-Middle-Mouse-Click.tar.gz

update

Christian Immanuel · 2026-08-11 08:59 · f9bab56aa2e323fd64c61e63ea106bfe9858768f

 README.md | 161 ++++++++------------------------------------------------------
 1 file changed, 20 insertions(+), 141 deletions(-)

diff --git a/README.md b/README.md
index 593694e..086788e 100644
--- a/README.md
+++ b/README.md
@@ -1,158 +1,37 @@
-# middle‑disable – Disable TrackPoint middle‑click, keep scrolling
+# Linux-disable-Middle-Mouse-Click
 
-ThinkPad/Lenovo TrackPoint keyboards use the middle button *and* the
-TrackPoint itself to implement click‑and‑scroll.  When you also use the
-middle button for opening browser tabs, the scrolling‑behaviour becomes
-annoying.  This tiny C program intercepts the raw input events, drops the
-plain middle‑click while still emitting the proper *press‑and‑scroll*
-events.
+Disable **TrackPoint middle-click** while keeping **press-and-scroll** working.
 
-> **100 % vibecode** – the source is small, self‑contained and completely
-> free to modify.
+ThinkPad/Lenovo TrackPoint devices use the middle button + TrackPoint to implement
+click-and-scroll. If you also use middle-click to open links/tabs, this can be
+annoying because accidental middle-clicks happen while scrolling.
+
+This tiny C program intercepts raw evdev events, removes the *plain* middle-click,
+but still emits the correct events when you actually use middle-button scrolling.
+
+> **100% vibecode** – the code is intentionally small, direct, and easy to tweak.
 
 ---
 
-## Features
+## Features / Options
 
 | Option | What it does |
 |--------|--------------|
-| `-d /dev/input/eventX` (repeatable) | Filter a specific device. |
-| `--auto` | Scan the system and automatically filter *all* TrackPoint devices (`ID_INPUT_POINTINGSTICK=1`). |
-| `-h / --help` | Show a usage summary. |
+| `-d /dev/input/eventX` (repeatable) | Filter specific device node(s). |
+| `--auto` | Auto-detect TrackPoint devices via udev (requires `ID_INPUT_POINTINGSTICK=1` **and** the device must actually expose `BTN_MIDDLE`). |
+| `--match REGEX` | Optional extra filter for `--auto`: case-insensitive POSIX regex matched against udev `ID_MODEL` (useful if auto finds more than you want). |
+| `-h` / `--help` | Show help. |
 
-If you give *both* `-d` and `--auto`, the program will filter the union of
-the explicit devices and the auto‑detected ones.
+If you pass both `-d` and `--auto`, the program filters the **union** of both sets.
 
 ---
 
 ## Getting the right device names
 
-The kernel creates a node for every input device under **/dev/input/**,
-named `event0`, `event1`, …  You need the exact node that belongs to the
-TrackPoint you want to filter.
-
-### 1. Using `udevadm`
-
-```bash
-# replace event13 with the number you suspect
-udevadm info -a -n /dev/input/event13 | grep -i "trackpoint"
-```
-
-If the output contains a line like `ATTRS{idInputPointingStick}=="1"` you
-have the right one.
-
-### 2. Using `libinput`
-
-```bash
-$ libinput debug-events
--event13  DEVICE_ADDED  TPPS/2 Elan TrackPoint   seat0 default group10 …
--event15  DEVICE_ADDED  Lenovo TrackPoint Keyboard II Mouse …
-```
-
-The part after `-event` is the *eventX* you need (e.g. `event13`).
-
-### 3. By‑id /path shortcuts
-
-The `/dev/input/by-id/` and `/dev/input/by-path/` symlinks are stable across boots,
-e.g.:
+The kernel creates input nodes under `/dev/input/` (`event0`, `event1`, …).
+You need the exact node that belongs to the TrackPoint you want to filter.
 
-```bash
-ls -l /dev/input/by-id/*TrackPoint*mouse
-lrwxrwxrwx 1 root root 13 Sep  1 12:34 usb-Lenovo_TrackPoint_Keyboard_II-if01-event-mouse -> ../event15
-```
-
-You can feed those symlinks straight to the program (`-d /dev/input/by-id/...`).
-
----
-
-## Building
-
-You need the **libudev** development headers (package `libudev-dev` on Debian/Ubuntu,
-`systemd-devel` on Fedora, etc.).
+### 1) Using `libinput`
 
 ```bash
-gcc -Wall -O2 -D_GNU_SOURCE -o middle-disable middle-disable.c -ludev
-```
-
-The binary must be run **as root** (or with the `CAP_SYS_ADMIN` capability)
-because it needs to:
-
-* open `/dev/uinput` and create a virtual device,
-* grab the real `/dev/input/eventX` devices so the kernel stops sending them to X/Wayland.
-
----
-
-## Running
-
-### 1. Manual start (for testing)
-
-```bash
-sudo ./middle-disable --auto
-# or
-sudo ./middle-disable -d /dev/input/event13 -d /dev/input/event15
-```
-
-Press **Ctrl‑C** to stop – the program cleans up the uinput nodes and releases the grabs.
-
-### 2. Systemd service (run at boot)
-
-Create `/etc/systemd/system/middle-disable.service`:
-
-```ini
-[Unit]
-Description=Disable TrackPoint middle click (keep scrolling)
-After=systemd-udevd.service
-Wants=systemd-udevd.service
-
-[Service]
-Type=simple
-ExecStart=/usr/local/sbin/middle-disable --auto
-# change the path if you installed it elsewhere
-Restart=on-failure
-CapabilityBoundingSet=CAP_SYS_ADMIN
-AmbientCapabilities=CAP_SYS_ADMIN
-User=root
-
-[Install]
-WantedBy=multi-user.target
-```
-
-Enable and start it:
-
-```bash
-sudo systemctl daemon-reload
-sudo systemctl enable --now middle-disable.service
-```
-
-Check the log:
-
-```bash
-journalctl -u middle-disable -f
-```
-
----
-
-## How it works (short explanation)
-
-* The program **grabs** the physical input device (`EVIOCGRAB`).  
-  This tells the kernel “don’t deliver the events downstream”.
-* It creates a **virtual** device with `uinput` that mimics the original
-  capabilities (buttons, relative axes).
-* For the built‑in TrackPoint (`internal`), the logic is:
-  * When BTN_MIDDLE goes down, **don’t** forward it immediately.
-  * If a wheel (`REL_WHEEL`, `REL_HWHEEL`, …) shows up while the button is held,
-    emit a *synthetic* BTN_MIDDLE press – this is what the desktop thinks
-    of as “click‑and‑scroll”.
-  * When the button is released, forward the BTN_MIDDLE release **only** if we
-    previously sent the synthetic press.
-* For external keyboards (`external`), any BTN_MIDDLE events are simply **dropped**.
-* All other events (movement, left/right click, etc.) are forwarded unchanged.
-
-That is exactly the behaviour you had in the original code, now with a clean
-command‑line interface and automatic detection.
-
----
-
-## License
-
-Public domain / “free as vibecode”.  Do whatever you want with it.
+sudo libinput debug-events | grep -i trackpoint