1
0
mirror of synced 2024-11-24 07:40:17 +01:00

fix: Shortcuts not working correctly with non-western keyboards

This commit is contained in:
WerWolv 2023-11-17 20:27:42 +01:00
parent e7bfa483f8
commit 2d45dce075
3 changed files with 31 additions and 35 deletions

View File

@ -189,7 +189,15 @@ namespace hex {
} }
bool operator==(const Shortcut &other) const { bool operator==(const Shortcut &other) const {
return this->m_keys == other.m_keys; auto thisKeys = this->m_keys;
auto otherKeys = other.m_keys;
thisKeys.erase(CurrentView);
thisKeys.erase(AllowWhileTyping);
otherKeys.erase(CurrentView);
otherKeys.erase(AllowWhileTyping);
return thisKeys == otherKeys;
} }
bool isLocal() const { bool isLocal() const {

View File

@ -42,44 +42,36 @@ namespace hex {
return pressedShortcut; return pressedShortcut;
} }
void ShortcutManager::process(const std::unique_ptr<View> &currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) { static void processShortcut(const Shortcut &shortcut, const std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, focused, keyCode);
if (keyCode != 0)
s_prevShortcut = Shortcut(pressedShortcut.getKeys());
if (s_paused) return;
if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
return;
if (currentView->m_shortcuts.contains(pressedShortcut + AllowWhileTyping)) {
currentView->m_shortcuts[pressedShortcut + AllowWhileTyping].callback();
} else if (currentView->m_shortcuts.contains(pressedShortcut)) {
if (!ImGui::GetIO().WantTextInput)
currentView->m_shortcuts[pressedShortcut].callback();
}
}
void ShortcutManager::processGlobals(bool ctrl, bool alt, bool shift, bool super, u32 keyCode) {
Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, false, keyCode);
if (keyCode != 0)
s_prevShortcut = pressedShortcut;
if (s_paused) return; if (s_paused) return;
if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId)) if (ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId))
return; return;
if (s_globalShortcuts.contains(pressedShortcut + AllowWhileTyping)) { if (shortcuts.contains(shortcut + AllowWhileTyping)) {
s_globalShortcuts[pressedShortcut + AllowWhileTyping].callback(); shortcuts.at(shortcut + AllowWhileTyping).callback();
} else if (s_globalShortcuts.contains(pressedShortcut)) { } else if (shortcuts.contains(shortcut)) {
if (!ImGui::GetIO().WantTextInput) if (!ImGui::GetIO().WantTextInput)
s_globalShortcuts[pressedShortcut].callback(); shortcuts.at(shortcut).callback();
} }
} }
void ShortcutManager::process(const std::unique_ptr<View> &currentView, bool ctrl, bool alt, bool shift, bool super, bool focused, u32 keyCode) {
Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, focused, keyCode);
if (keyCode != 0)
s_prevShortcut = Shortcut(pressedShortcut.getKeys());
processShortcut(pressedShortcut, currentView->m_shortcuts);
}
void ShortcutManager::processGlobals(bool ctrl, bool alt, bool shift, bool super, u32 keyCode) {
Shortcut pressedShortcut = getShortcut(ctrl, alt, shift, super, false, keyCode);
if (keyCode != 0)
s_prevShortcut = Shortcut(pressedShortcut.getKeys());
processShortcut(pressedShortcut, s_globalShortcuts);
}
void ShortcutManager::clearShortcuts() { void ShortcutManager::clearShortcuts() {
s_globalShortcuts.clear(); s_globalShortcuts.clear();
} }

View File

@ -1044,7 +1044,7 @@ namespace hex {
#if !defined(OS_WEB) #if !defined(OS_WEB)
// Register key press callback // Register key press callback
glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) { glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int, int action, int mods) {
hex::unused(mods); hex::unused(mods);
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window)); auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
@ -1057,10 +1057,6 @@ namespace hex {
if (key == GLFW_KEY_UNKNOWN) return; if (key == GLFW_KEY_UNKNOWN) return;
auto keyName = glfwGetKeyName(key, scancode);
if (keyName != nullptr)
key = std::toupper(keyName[0]);
if (action == GLFW_PRESS || action == GLFW_REPEAT) { if (action == GLFW_PRESS || action == GLFW_REPEAT) {
if (key != GLFW_KEY_LEFT_CONTROL && key != GLFW_KEY_RIGHT_CONTROL && if (key != GLFW_KEY_LEFT_CONTROL && key != GLFW_KEY_RIGHT_CONTROL &&
key != GLFW_KEY_LEFT_ALT && key != GLFW_KEY_RIGHT_ALT && key != GLFW_KEY_LEFT_ALT && key != GLFW_KEY_RIGHT_ALT &&