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)
# 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
if cthulhu_state.activeScript:
bindings = cthulhu_state.activeScript.getKeyBindings()
binding = keybindings.KeyBinding(
final_key,
keybindings.defaultModifierMask,
modifiers,
handler)
from . import keybindings
binding = keybindings.KeyBinding(
final_key,
keybindings.defaultModifierMask,
modifiers,
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:
self._gestureBindings[contextName] = []
self._gestureBindings[contextName].append(binding) # This line should be outside the if block
# Register key grab at the system level
grab_ids = self.app.addKeyGrab(binding)
# For later removal
if grab_ids:
binding._grab_ids = grab_ids
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
grab_ids = self.app.addKeyGrab(binding)
# For later removal
if grab_ids:
binding._grab_ids = grab_ids
logger.info(f"Created binding: {binding.keysymstring} with modifiers {binding.modifiers}")
return binding