From 314aa18a1be3d918e2d661a259a977620010edfd Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 5 Jun 2025 03:42:02 -0400 Subject: [PATCH] Another another attempt to fix the plugin keybindings. --- src/cthulhu/event_manager.py | 7 +++++++ src/cthulhu/plugin_system_manager.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/cthulhu/event_manager.py b/src/cthulhu/event_manager.py index a507ab9..2e43e21 100644 --- a/src/cthulhu/event_manager.py +++ b/src/cthulhu/event_manager.py @@ -112,6 +112,13 @@ class EventManager: cthulhu_state.device.key_watcher = cthulhu_state.device.add_key_watcher( self._processNewKeyboardEvent) self.newKeyHandlingActive = True + + # Notify plugin system that device is now available for keybinding registration + from . import cthulhu + if hasattr(cthulhu, 'cthulhuApp') and cthulhu.cthulhuApp: + plugin_manager = cthulhu.cthulhuApp.getPluginSystemManager() + if plugin_manager: + plugin_manager.register_plugin_keybindings_with_active_script() def activateLegacyKeyHandling(self): if not self.legacyKeyHandlingActive: diff --git a/src/cthulhu/plugin_system_manager.py b/src/cthulhu/plugin_system_manager.py index 60326d6..04407fd 100644 --- a/src/cthulhu/plugin_system_manager.py +++ b/src/cthulhu/plugin_system_manager.py @@ -185,11 +185,17 @@ class PluginSystemManager: # 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! from . import cthulhu 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") def _on_settings_changed(self, app=None): """Re-register all plugin keybindings when settings change."""