diff --git a/lib/libimhex/source/api/shortcut_manager.cpp b/lib/libimhex/source/api/shortcut_manager.cpp index ca5b69ebe..06be31fec 100644 --- a/lib/libimhex/source/api/shortcut_manager.cpp +++ b/lib/libimhex/source/api/shortcut_manager.cpp @@ -316,28 +316,40 @@ namespace hex { pressedShortcut += s_macOSMode ? CTRLCMD : SUPER; if (focused) pressedShortcut += CurrentView; + if (!ImHexApi::Provider::isValid()) { + pressedShortcut += CurrentView; + pressedShortcut += ShowOnWelcomeScreen; + } pressedShortcut += scanCodeToKey(keyCode); return pressedShortcut; } - static bool processShortcut(Shortcut shortcut, const std::map &shortcuts) { + static auto findShortcut(const Shortcut &shortcut, const std::map &shortcuts, bool condition, auto ... extraOption) { + auto modifiedShortcut = shortcut; + ((modifiedShortcut += extraOption), ...); + if (condition) { + return shortcuts.find(modifiedShortcut); + } else { + auto it = shortcuts.find(shortcut); + if (it == shortcuts.end()) + return shortcuts.find(modifiedShortcut); + } + + return shortcuts.end(); + } + + static bool processShortcut(const Shortcut &shortcut, const std::map &shortcuts) { if (s_paused) return true; if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId)) return true; - auto it = shortcuts.end(); - if (ImGui::GetIO().WantTextInput) { - it = shortcuts.find(shortcut + AllowWhileTyping); - } else { - it = shortcuts.find(shortcut); - if (it == shortcuts.end()) - it = shortcuts.find(shortcut + AllowWhileTyping); - } - + auto it = findShortcut(shortcut, shortcuts, ImGui::GetIO().WantTextInput, AllowWhileTyping); + if (it == shortcuts.end()) + it = findShortcut(shortcut, shortcuts, ImGui::GetIO().WantTextInput, AllowWhileTyping, ShowOnWelcomeScreen); if (it != shortcuts.end()) { const auto &[foundShortcut, entry] = *it; diff --git a/lib/libimhex/source/ui/view.cpp b/lib/libimhex/source/ui/view.cpp index b524c953b..2b0250eff 100644 --- a/lib/libimhex/source/ui/view.cpp +++ b/lib/libimhex/source/ui/view.cpp @@ -22,7 +22,7 @@ namespace hex { } bool View::shouldProcess() const { - return this->shouldDraw() && this->getWindowOpenState(); + return true; } bool View::hasViewMenuItemEntry() const { diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index da74b51c8..1898a82b8 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -728,13 +728,13 @@ namespace hex { view->trackViewState(); // Skip views that shouldn't be processed currently - if (!view->shouldProcess()) + if (!view->shouldProcess() || !view->getWindowOpenState()) continue; const auto openViewCount = std::ranges::count_if(ContentRegistry::Views::impl::getEntries(), [](const auto &entry) { const auto &[unlocalizedName, openView] = entry; - return openView->hasViewMenuItemEntry() && openView->shouldProcess(); + return openView->hasViewMenuItemEntry() && openView->shouldDraw(); }); ImGuiWindowClass windowClass = {}; @@ -758,6 +758,19 @@ namespace hex { // Draw view view->draw(); + // Handle view shortcuts + for (const auto &key : m_pressedKeys) { + ShortcutManager::process( + view.get(), + io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl, + io.KeyAlt, + io.KeyShift, + io.ConfigMacOSXBehaviors ? io.KeyCtrl : io.KeySuper, + view.get() == View::getLastFocusedView(), + key + ); + } + // If the window was just opened, it wasn't found above, so try to find it again if (window == nullptr) window = ImGui::FindWindowByName(view->getName().c_str()); @@ -793,10 +806,6 @@ namespace hex { // Pass on currently pressed keys to the shortcut handler if (!windowIsPopup) { - for (const auto &key : m_pressedKeys) { - ShortcutManager::process(view.get(), io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl, io.KeyAlt, io.KeyShift, io.ConfigMacOSXBehaviors ? io.KeyCtrl : io.KeySuper, focused, key); - } - ImGui::End(); } } else if (view->didWindowJustClose()) { @@ -808,7 +817,13 @@ namespace hex { // Handle global shortcuts for (const auto &key : m_pressedKeys) { - ShortcutManager::processGlobals(io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl, io.KeyAlt, io.KeyShift, io.ConfigMacOSXBehaviors ? io.KeyCtrl : io.KeySuper, key); + ShortcutManager::processGlobals( + io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl, + io.KeyAlt, + io.KeyShift, + io.ConfigMacOSXBehaviors ? io.KeyCtrl : io.KeySuper, + key + ); } m_pressedKeys.clear(); diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index b32ad40d2..a4a5c187e 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -373,7 +373,7 @@ for (const auto &path : m_paths) { if (const auto &shortcut = ShortcutManager::getPreviousShortcut(); shortcut.has_value()) { auto keys = m_shortcut.getKeys(); std::erase_if(keys, [](Key key) { - return key != AllowWhileTyping && key != CurrentView; + return key != AllowWhileTyping && key != CurrentView && key != ShowOnWelcomeScreen; }); for (const auto &key : shortcut->getKeys()) {