diff --git a/src/cthulhu/cthulhu.py b/src/cthulhu/cthulhu.py index 997fb12..e22e693 100644 --- a/src/cthulhu/cthulhu.py +++ b/src/cthulhu/cthulhu.py @@ -638,6 +638,9 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False): _scriptManager.activate() _eventManager.activate() + cthulhuApp.getSignalManager().emitSignal('load-setting-begin') + cthulhuApp.getPluginSystemManager().register_plugin_keybindings_with_active_script() + cthulhuApp.getSignalManager().emitSignal('load-setting-completed') debug.printMessage(debug.LEVEL_INFO, 'CTHULHU: User Settings Loaded', True) diff --git a/src/cthulhu/plugin_system_manager.py b/src/cthulhu/plugin_system_manager.py index 80fe9c5..a0f756e 100644 --- a/src/cthulhu/plugin_system_manager.py +++ b/src/cthulhu/plugin_system_manager.py @@ -156,6 +156,34 @@ class PluginSystemManager: import traceback logger.error(traceback.format_exc()) + def register_plugin_keybindings_with_active_script(self): + """Register all plugin keybindings with the active script.""" + + if not PLUGGY_AVAILABLE: + return + + from . import cthulhu_state + if not cthulhu_state.activeScript: + logger.warning("No active script available to register plugin keybindings") + return + + active_script = cthulhu_state.activeScript + logger.info(f"Registering plugin keybindings with active script: {active_script}") + + for pluginInfo in self._plugins.values(): + if not pluginInfo.loaded or not pluginInfo.instance: + continue + + plugin = pluginInfo.instance + if not hasattr(plugin, 'get_bindings') or not plugin.get_bindings(): + continue + + logger.info(f"Registering keybindings for plugin: {plugin.name}") + bindings = plugin.get_bindings() + for binding in bindings.keyBindings: + logger.info(f"Adding binding: {binding.keysymstring} with modifiers {binding.modifiers}") + active_script.getKeyBindings().add(binding) + def _on_settings_changed(self): """Re-register all plugin keybindings when settings change.""" if not hasattr(self, '_plugin_global_bindings'): diff --git a/src/cthulhu/script_manager.py b/src/cthulhu/script_manager.py index c55fb23..0f184ef 100644 --- a/src/cthulhu/script_manager.py +++ b/src/cthulhu/script_manager.py @@ -319,6 +319,14 @@ class ScriptManager: newScript.activate() tokens = ["SCRIPT MANAGER: Setting active script to", newScript, "reason:", reason] + self._activeScript = newScript + + # Register plugin keybindings with the new active script + from . import cthulhu + plugin_manager = cthulhu.getPluginSystemManager() + if plugin_manager: + plugin_manager.register_plugin_keybindings_with_active_script() + debug.printTokens(debug.LEVEL_INFO, tokens, True) def _getScriptForAppReplicant(self, app):