Skip to content

Commit 6beb563

Browse files
committed
fix: open devices read-only for status command to avoid LED pulsing
Use evdev readonly mode for the status command to prevent O_RDWR open from triggering LED re-assertion on certain hardware (e.g. Tuxedo Stellaris touchpad LED). Temporarily depends on xz-dev/python-evdev@feat/inputdevice-readonly pending upstream merge (gvalkov/python-evdev#251). See: https://www.reddit.com/r/tuxedocomputers/comments/1rtj3c9/
1 parent 8baa8ae commit 6beb563

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
evdev==1.9.3
1+
evdev @ git+https://github.com/xz-dev/python-evdev.git@feat/inputdevice-readonly

src/numlockw/__main__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ def _check_device_has_numlock(device: evdev.InputDevice) -> bool:
4949
return has_numlock
5050

5151

52-
def _devices(device_name: Optional[str]) -> List[evdev.InputDevice]:
53-
_debug(f"Enumerating input devices (filter: {device_name!r})")
54-
all_paths = evdev.list_devices()
52+
def _devices(
53+
device_name: Optional[str], readonly_mode: bool = False
54+
) -> List[evdev.InputDevice]:
55+
_debug(f"Enumerating input devices (filter: {device_name!r}, readonly_mode={readonly_mode})")
56+
all_paths = evdev.list_devices(writable=not readonly_mode)
5557
_debug(f"Found {len(all_paths)} total input devices")
5658

5759
devices = []
5860
for path in all_paths:
5961
_debug(f"Opening device: {path}")
60-
device = evdev.InputDevice(path)
62+
device = evdev.InputDevice(path, readonly=readonly_mode)
6163
_debug(f" Device name: '{device.name}', phys: '{device.phys}'")
6264
if _check_device_has_numlock(device):
6365
devices.append(device)
@@ -230,10 +232,13 @@ def off():
230232

231233

232234
def status():
235+
# Use readonly=True to avoid O_RDWR open which can trigger LED re-assertion
236+
# on certain hardware (e.g. Tuxedo Stellaris touchpad LED pulsing).
237+
# See: https://www.reddit.com/r/tuxedocomputers/comments/1rtj3c9/numlockw_status_causes_touchpad_led_to_pulse/
233238
_debug("status() called - checking NumLock status")
234239
filter_name = "*" if device_name is None else device_name
235240
_debug(f"Using device filter: {filter_name!r}")
236-
devices = _devices(filter_name)
241+
devices = _devices(filter_name, readonly_mode=True)
237242
current_status = numlock_get_status_devices(devices)
238243
_debug(f"Final status: {'ON' if current_status else 'OFF'}")
239244
print("NumLock is", "on" if current_status else "off")

0 commit comments

Comments
 (0)