From 930d2b4280728738be98166ee30938e391d86ebb Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 6 Feb 2025 15:58:18 +0100 Subject: [PATCH] fix: Some shortcuts not working correctly on macOS --- lib/libimhex/include/hex/api/shortcut_manager.hpp | 2 ++ lib/libimhex/source/api/shortcut_manager.cpp | 11 +++++++++-- plugins/builtin/source/content/window_decoration.cpp | 8 ++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/libimhex/include/hex/api/shortcut_manager.hpp b/lib/libimhex/include/hex/api/shortcut_manager.hpp index 7ba760d76..fa5d255d7 100644 --- a/lib/libimhex/include/hex/api/shortcut_manager.hpp +++ b/lib/libimhex/include/hex/api/shortcut_manager.hpp @@ -135,6 +135,8 @@ namespace hex { */ static void processGlobals(bool ctrl, bool alt, bool shift, bool super, u32 keyCode); + static void runShortcut(const Shortcut &shortcut, const View *view = nullptr); + /** * @brief Clear all shortcuts */ diff --git a/lib/libimhex/source/api/shortcut_manager.cpp b/lib/libimhex/source/api/shortcut_manager.cpp index bd57b66de..a2c79de22 100644 --- a/lib/libimhex/source/api/shortcut_manager.cpp +++ b/lib/libimhex/source/api/shortcut_manager.cpp @@ -342,12 +342,19 @@ namespace hex { } } + void ShortcutManager::runShortcut(const Shortcut &shortcut, const View *view) { + if (view == nullptr) + processShortcut(shortcut, s_globalShortcuts); + else + processShortcut(shortcut, view->m_shortcuts); + } + void ShortcutManager::process(const View *currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) { const Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, focused, keyCode); if (keyCode != 0) s_prevShortcut = Shortcut(pressedShortcut.getKeys()); - processShortcut(pressedShortcut, currentView->m_shortcuts); + runShortcut(pressedShortcut, currentView); } void ShortcutManager::processGlobals(bool ctrl, bool alt, bool shift, bool super, u32 keyCode) { @@ -355,7 +362,7 @@ namespace hex { if (keyCode != 0) s_prevShortcut = Shortcut(pressedShortcut.getKeys()); - processShortcut(pressedShortcut, s_globalShortcuts); + runShortcut(pressedShortcut); } std::optional ShortcutManager::getLastActivatedMenu() { diff --git a/plugins/builtin/source/content/window_decoration.cpp b/plugins/builtin/source/content/window_decoration.cpp index e1d3773d3..1c92d8c80 100644 --- a/plugins/builtin/source/content/window_decoration.cpp +++ b/plugins/builtin/source/content/window_decoration.cpp @@ -48,8 +48,12 @@ namespace hex::plugin::builtin { callback(); } } else if (menuItems.size() == 1) { - if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback() && (view == nullptr || view->isFocused()))) - callback(); + if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback())) { + if (shortcut == Shortcut::None) + callback(); + else + ShortcutManager::runShortcut(shortcut, view); + } } else { bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;