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,30 +87,32 @@ 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 # Store binding for later reference
bindings.add(binding)
# 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)
# Register key grab at the system level # Only add to active script if one exists
grab_ids = self.app.addKeyGrab(binding) if cthulhu_state.activeScript:
bindings = cthulhu_state.activeScript.getKeyBindings()
bindings.add(binding)
# For later removal # Register key grab at the system level
if grab_ids: grab_ids = self.app.addKeyGrab(binding)
binding._grab_ids = grab_ids
# For later removal
if grab_ids:
binding._grab_ids = grab_ids
logger.info(f"Created binding: {binding.keysymstring} with modifiers {binding.modifiers}") logger.info(f"Created binding: {binding.keysymstring} with modifiers {binding.modifiers}")
return binding return binding