Another try at getting keybindings working.

This commit is contained in:
Storm Dragon 2025-04-20 02:43:59 -04:00
parent c376b2489a
commit d8df2ed757

View File

@ -87,23 +87,25 @@ class APIHelper:
handler = GestureHandler(function, name) handler = GestureHandler(function, name)
# Register the binding with the active script # Create the binding object regardless of whether there's an active script
# This allows plugins to define bindings that will work when a script becomes active
from . import cthulhu_state from . import cthulhu_state
if cthulhu_state.activeScript: from . import keybindings
bindings = cthulhu_state.activeScript.getKeyBindings()
binding = keybindings.KeyBinding( binding = keybindings.KeyBinding(
final_key, final_key,
keybindings.defaultModifierMask, keybindings.defaultModifierMask,
modifiers, modifiers,
handler) handler)
# Add the binding to the active script
bindings.add(binding)
# Store binding for later reference # Store binding for later reference
if contextName not in self._gestureBindings: if contextName not in self._gestureBindings:
self._gestureBindings[contextName] = [] self._gestureBindings[contextName] = []
self._gestureBindings[contextName].append(binding) # This line should be outside the if block self._gestureBindings[contextName].append(binding)
# Only add to active script if one exists
if cthulhu_state.activeScript:
bindings = cthulhu_state.activeScript.getKeyBindings()
bindings.add(binding)
# Register key grab at the system level # Register key grab at the system level
grab_ids = self.app.addKeyGrab(binding) grab_ids = self.app.addKeyGrab(binding)