Skip to content

Commit a6d6df9

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 a6d6df9

2 files changed

Lines changed: 13 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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,19 @@ 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(
56+
f"Enumerating input devices (filter: {device_name!r}, readonly_mode={readonly_mode})"
57+
)
58+
all_paths = evdev.list_devices(writable=not readonly_mode)
5559
_debug(f"Found {len(all_paths)} total input devices")
5660

5761
devices = []
5862
for path in all_paths:
5963
_debug(f"Opening device: {path}")
60-
device = evdev.InputDevice(path)
64+
device = evdev.InputDevice(path, readonly=readonly_mode)
6165
_debug(f" Device name: '{device.name}', phys: '{device.phys}'")
6266
if _check_device_has_numlock(device):
6367
devices.append(device)
@@ -230,10 +234,13 @@ def off():
230234

231235

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

0 commit comments

Comments
 (0)