Preserve sysfs capability word boundaries in laptop doctor

This commit is contained in:
Codex
2026-10-13 21:55:57 +03:00
parent 70b7edae8a
commit d625733207
2 changed files with 15 additions and 3 deletions
+5 -3
View File
@@ -138,9 +138,11 @@ def doctor_report(*, proc_root=Path('/proc'), sys_root=Path('/sys'), dev_root=Pa
inputs = [p for p in _entries(sys_root / 'class/input') if re.fullmatch(r'event[0-9]+', p.name)]
keyboards = 0
for path in inputs:
value = _read(path / 'device/capabilities/key', 256).strip().replace(' ', '')
if re.fullmatch(r'[0-9a-fA-F]{1,256}', value):
bits = int(value, 16)
words = _read(path / 'device/capabilities/key', 256).split()
if words and all(re.fullmatch(r'[0-9a-fA-F]{1,16}', word) for word in words):
# x86_64 sysfs prints most-significant unsigned-long words first,
# without zero padding. KEY_A (30) and KEY_Z (44) are in the low word.
bits = int(words[-1], 16)
keyboards += bool(bits & (1 << 30) and bits & (1 << 44))
return {
'format': 1,