some fixes

This commit is contained in:
2026-04-03 04:10:16 -03:00
parent 6159b2a027
commit 6852bb8889
4 changed files with 15 additions and 28 deletions

View File

@@ -41,15 +41,18 @@ class KeyboardManager:
def __init__(self):
self._bindings: dict[int, Callable] = {}
self._passthrough: Callable[[], bool] | None = None
self._passthrough_except: set[int] = set()
self._window = None
def bind(self, keyval: int, handler: Callable):
"""Register a handler for a key. Handler receives shift=bool."""
self._bindings[keyval] = handler
def set_passthrough(self, check: Callable[[], bool]):
"""When check() returns True, keys pass through to focused widget."""
def set_passthrough(self, check: Callable[[], bool], except_keys: set[int] | None = None):
"""When check() returns True, keys pass through to focused widget.
Keys in except_keys are still handled even during passthrough."""
self._passthrough = check
self._passthrough_except = except_keys or set()
def attach(self, window):
"""Attach to a GTK4 window."""
@@ -76,7 +79,7 @@ class KeyboardManager:
self._window.set_focus(None)
def _on_key_pressed(self, controller, keyval, keycode, state):
if self._passthrough and self._passthrough():
if self._passthrough and self._passthrough() and keyval not in self._passthrough_except:
return False
handler = self._bindings.get(keyval)