some fixes
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user