From 90aecf805566bb2f3dee5ca84614e66913f57af7 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 5 Jun 2025 04:13:24 -0400 Subject: [PATCH] Changes to the plugin manager. --- src/cthulhu/plugin_system_manager.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cthulhu/plugin_system_manager.py b/src/cthulhu/plugin_system_manager.py index 7f3f2d1..bb47ff7 100644 --- a/src/cthulhu/plugin_system_manager.py +++ b/src/cthulhu/plugin_system_manager.py @@ -170,6 +170,33 @@ class PluginSystemManager: active_script = cthulhu_state.activeScript logger.info(f"Registering plugin keybindings with active script: {active_script}") + # First, register keybindings from APIHelper's stored bindings + # This is where plugin keybindings actually get stored + from . import cthulhu + api_helper = cthulhu.cthulhuApp.getAPIHelper() + if api_helper and hasattr(api_helper, '_gestureBindings'): + logger.info("Registering stored gesture bindings from APIHelper") + for context_name, bindings_list in api_helper._gestureBindings.items(): + logger.info(f"Processing context '{context_name}' with {len(bindings_list)} bindings") + for binding in bindings_list: + logger.info(f"Adding stored binding: {binding.keysymstring} with modifiers {binding.modifiers}") + # Check if binding already exists to avoid duplicates + if not active_script.getKeyBindings().hasKeyBinding(binding, "keysNoMask"): + active_script.getKeyBindings().add(binding) + # Force recalculation of keycode if it wasn't set when device was None + if not binding.keycode and binding.keysymstring: + from . import keybindings + binding.keycode = keybindings.getKeycode(binding.keysymstring) + # Register key grab at system level - this was missing! + grab_ids = cthulhu.addKeyGrab(binding) + if grab_ids: + binding._grab_ids = grab_ids + else: + logger.warning(f"Failed to create key grab for {binding.keysymstring} - device may not be available") + else: + logger.info(f"Binding already exists: {binding.keysymstring}") + + # Also check the old method for any plugins that use get_bindings() for pluginInfo in self._plugins.values(): if not pluginInfo.loaded or not pluginInfo.instance: continue @@ -190,7 +217,6 @@ class PluginSystemManager: from . import keybindings binding.keycode = keybindings.getKeycode(binding.keysymstring) # Register key grab at system level - this was missing! - from . import cthulhu grab_ids = cthulhu.addKeyGrab(binding) if grab_ids: binding._grab_ids = grab_ids