fix: Start fixing shortcuts on welcome screen. Breaks certain shortcuts still

This commit is contained in:
WerWolv
2026-01-23 00:07:34 +01:00
parent 96a5a5d34c
commit 810955b1be
4 changed files with 46 additions and 19 deletions

View File

@@ -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<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
static auto findShortcut(const Shortcut &shortcut, const std::map<Shortcut, ShortcutManager::ShortcutEntry> &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<Shortcut, ShortcutManager::ShortcutEntry> &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;

View File

@@ -22,7 +22,7 @@ namespace hex {
}
bool View::shouldProcess() const {
return this->shouldDraw() && this->getWindowOpenState();
return true;
}
bool View::hasViewMenuItemEntry() const {

View File

@@ -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();

View File

@@ -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()) {