Skip to content

Commit 5ea2554

Browse files
darkLabz001claude
andcommitted
fix(uconsole): Esc no longer quits bigbox; detect keyboard by presence
- Esc only exits in dev mode now. On a real device Esc fell through to self.running=False and closed bigbox (reported on the uConsole); it now maps to Back (Button.B) via the keymap instead. - Enable physical typing when a real keyboard is actually present (_has_physical_keyboard scans /proc/bus/input/devices), not just when the device-tree string matches — the uConsole's CM4 model often lacks a "clockwork" tag, which left typing disabled. HDMI-CEC/GPIO 'kbd' handlers are excluded so the GamePi43 stays grid-only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c6c13dc commit 5ea2554

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

‎bigbox/app.py‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ def _is_uconsole() -> bool:
183183
return False
184184

185185

186+
def _has_physical_keyboard() -> bool:
187+
"""True if a real multi-key keyboard input device is present (the uConsole's
188+
QWERTY, a plugged-in USB keyboard, etc.). Distinguishes from HDMI-CEC 'kbd'
189+
handlers and GPIO-only setups so the GamePi43 (no keyboard) stays False."""
190+
try:
191+
data = open("/proc/bus/input/devices").read()
192+
except Exception:
193+
return False
194+
for block in data.split("\n\n"):
195+
low = block.lower()
196+
if "kbd" not in low:
197+
continue
198+
# skip HDMI-CEC consumer-control and GPIO button "keyboards"
199+
if any(x in low for x in ("vc4-hdmi", "hdmi", "cec", "gpio-keys", "gpio_keys")):
200+
continue
201+
if "keyboard" in low:
202+
return True
203+
# a real keyboard exposes a long EV_KEY bitmap; a gamepad/power button
204+
# only a short one.
205+
for line in block.splitlines():
206+
if line.startswith("B: KEY=") and len(line.split("=", 1)[1].split()) >= 4:
207+
return True
208+
return False
209+
210+
186211
class App:
187212
def __init__(self) -> None:
188213
self.dev_mode = bool(os.environ.get("BIGBOX_DEV"))
@@ -423,7 +448,9 @@ def _start_input(self) -> None:
423448
# Devices with a real QWERTY (uConsole, or forced via BIGBOX_KEYBOARD)
424449
# can type straight into the on-screen keyboard's text field; the D-pad
425450
# still drives its grid. The GamePi43 (no keyboard) stays grid-only.
426-
self._kb_can_type = bool(os.environ.get("BIGBOX_KEYBOARD") or _is_uconsole())
451+
self._kb_can_type = bool(
452+
os.environ.get("BIGBOX_KEYBOARD") or _is_uconsole() or _has_physical_keyboard()
453+
)
427454
if self._kb_can_type:
428455
print("[bigbox] physical keyboard text entry enabled")
429456

@@ -902,7 +929,11 @@ def run(self) -> int:
902929
and getattr(self, "_kb_can_type", False)
903930
and self.kb_view.type_key(ev)):
904931
continue
905-
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
932+
# Esc quits ONLY in dev mode (windowed on a PC). On a real
933+
# device it must not close bigbox — it falls through to the
934+
# keymap as Back (Button.B).
935+
if (self.dev_mode and ev.type == pygame.KEYDOWN
936+
and ev.key == pygame.K_ESCAPE):
906937
self.running = False
907938
# Always translate keyboard events (supports USB/BLE keyboards on device)
908939
kbd_translate(ev, self.bus)

0 commit comments

Comments
 (0)