macbook: drop DWT daemon, native libinput DWT works

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-07-16 21:27:56 +01:00
parent 4f99ea2019
commit a07759a40d

View file

@ -48,75 +48,6 @@
ID_INPUT_TOUCHPAD_INTEGRATION=internal
'';
# Fallback DWT daemon for the bcm5974 touchpad.
# TODO: remove once native libinput DWT (hwdb fix above) is verified.
systemd.services.macbook-dwt = {
description = "Disable touchpad while typing (bcm5974)";
after = [ "systemd-udevd.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
Restart = "on-failure";
RestartSec = 3;
ExecStopPost = pkgs.writeShellScript "dwt-uninhibit" ''
for p in /sys/class/input/event*/device/name; do
if grep -q bcm5974 "$p" 2>/dev/null; then
echo 0 > "''${p%/name}/inhibited"
fi
done
true
'';
ExecStart = "${pkgs.python3.withPackages (p: [])}/bin/python3 ${pkgs.writeText "macbook-dwt.py" ''
import glob, os, select, struct, time
EVENT_SIZE = struct.calcsize("llHHi")
EV_KEY = 0x01
DWT_TIMEOUT = 0.4
# Modifier keycodes — don't inhibit touchpad for these
MODIFIERS = {42, 54, 29, 97, 56, 100, 125, 126} # L/R Shift, Ctrl, Alt, Super
def find_event(name):
for p in sorted(glob.glob("/sys/class/input/event*/device/name")):
with open(p) as f:
if name in f.read():
return p.split("/")[4]
return None
def main():
tp = find_event("bcm5974")
kb = find_event("Apple Internal Keyboard")
if not tp or not kb:
raise SystemExit(f"Devices not found: touchpad={tp}, keyboard={kb}")
inhibit = f"/sys/class/input/{tp}/device/inhibited"
active = False
last_key = 0.0
with open(f"/dev/input/{kb}", "rb") as f:
try:
while True:
timeout = max(0, DWT_TIMEOUT - (time.monotonic() - last_key)) if active else None
r, _, _ = select.select([f], [], [], timeout)
if r:
data = os.read(f.fileno(), EVENT_SIZE * 64)
for off in range(0, len(data) - EVENT_SIZE + 1, EVENT_SIZE):
_, _, typ, code, val = struct.unpack("llHHi", data[off:off + EVENT_SIZE])
if typ == EV_KEY and val and code not in MODIFIERS:
last_key = time.monotonic()
if not active:
open(inhibit, "w").write("1")
active = True
if active and time.monotonic() - last_key >= DWT_TIMEOUT:
open(inhibit, "w").write("0")
active = False
finally:
open(inhibit, "w").write("0")
main()
''}";
};
};
home-manager.users.fred = { pkgs, ... }: {
wayland.windowManager.hyprland.settings.monitor = [{
output = "";