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."""