fix: Shortcuts not working correctly in Web build
This commit is contained in:
parent
ab34312089
commit
c1ed1baaad
@ -153,12 +153,7 @@ namespace hex {
|
||||
constexpr static auto SUPER = Key(static_cast<Keys>(0x0800'0000));
|
||||
constexpr static auto CurrentView = Key(static_cast<Keys>(0x1000'0000));
|
||||
constexpr static auto AllowWhileTyping = Key(static_cast<Keys>(0x2000'0000));
|
||||
|
||||
#if defined (OS_MACOS)
|
||||
constexpr static auto CTRLCMD = SUPER;
|
||||
#else
|
||||
constexpr static auto CTRLCMD = CTRL;
|
||||
#endif
|
||||
constexpr static auto CTRLCMD = Key(static_cast<Keys>(0x4000'0000));
|
||||
|
||||
class Shortcut {
|
||||
public:
|
||||
@ -255,6 +250,8 @@ namespace hex {
|
||||
static void resumeShortcuts();
|
||||
static void pauseShortcuts();
|
||||
|
||||
static void enableMacOSMode();
|
||||
|
||||
[[nodiscard]] static std::optional<Shortcut> getPreviousShortcut();
|
||||
|
||||
[[nodiscard]] static std::vector<ShortcutEntry> getGlobalShortcuts();
|
||||
|
@ -12,6 +12,7 @@ namespace hex {
|
||||
AutoReset<std::map<Shortcut, ShortcutManager::ShortcutEntry>> s_globalShortcuts;
|
||||
std::atomic<bool> s_paused;
|
||||
std::optional<Shortcut> s_prevShortcut;
|
||||
bool s_macOSMode = false;
|
||||
|
||||
}
|
||||
|
||||
@ -78,22 +79,14 @@ namespace hex {
|
||||
std::string Shortcut::toString() const {
|
||||
std::string result;
|
||||
|
||||
#if defined(OS_MACOS)
|
||||
constexpr static auto CTRL_NAME = "⌃";
|
||||
constexpr static auto ALT_NAME = "⌥";
|
||||
constexpr static auto SHIFT_NAME = "⇧";
|
||||
constexpr static auto SUPER_NAME = "⌘";
|
||||
constexpr static auto Concatination = " ";
|
||||
#else
|
||||
constexpr static auto CTRL_NAME = "CTRL";
|
||||
constexpr static auto ALT_NAME = "ALT";
|
||||
constexpr static auto SHIFT_NAME = "SHIFT";
|
||||
constexpr static auto SUPER_NAME = "SUPER";
|
||||
constexpr static auto Concatination = " + ";
|
||||
#endif
|
||||
const auto CTRL_NAME = s_macOSMode ? "⌃" : "CTRL";
|
||||
const auto ALT_NAME = s_macOSMode ? "⌥" : "ALT";
|
||||
const auto SHIFT_NAME = s_macOSMode ? "⇧" : "SHIFT";
|
||||
const auto SUPER_NAME = s_macOSMode ? "⌘" : "SUPER";
|
||||
const auto Concatination = s_macOSMode ? " " : " + ";
|
||||
|
||||
auto keys = m_keys;
|
||||
if (keys.erase(CTRL) > 0) {
|
||||
if (keys.erase(CTRL) > 0 || (!s_macOSMode && keys.erase(CTRLCMD) > 0)) {
|
||||
result += CTRL_NAME;
|
||||
result += Concatination;
|
||||
}
|
||||
@ -105,7 +98,7 @@ namespace hex {
|
||||
result += SHIFT_NAME;
|
||||
result += Concatination;
|
||||
}
|
||||
if (keys.erase(SUPER) > 0) {
|
||||
if (keys.erase(SUPER) > 0 || (s_macOSMode && keys.erase(CTRLCMD) > 0)) {
|
||||
result += SUPER_NAME;
|
||||
result += Concatination;
|
||||
}
|
||||
@ -267,13 +260,13 @@ namespace hex {
|
||||
Shortcut pressedShortcut;
|
||||
|
||||
if (ctrl)
|
||||
pressedShortcut += CTRL;
|
||||
pressedShortcut += s_macOSMode ? CTRL : CTRLCMD;
|
||||
if (alt)
|
||||
pressedShortcut += ALT;
|
||||
if (shift)
|
||||
pressedShortcut += SHIFT;
|
||||
if (super)
|
||||
pressedShortcut += SUPER;
|
||||
pressedShortcut += s_macOSMode ? CTRLCMD : SUPER;
|
||||
if (focused)
|
||||
pressedShortcut += CurrentView;
|
||||
if (ImGui::GetIO().WantTextInput)
|
||||
@ -387,4 +380,9 @@ namespace hex {
|
||||
return result;
|
||||
}
|
||||
|
||||
void ShortcutManager::enableMacOSMode() {
|
||||
s_macOSMode = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,6 +25,10 @@ EM_JS(void, resizeCanvas, (), {
|
||||
js_resizeCanvas();
|
||||
});
|
||||
|
||||
EM_JS(bool, isMacOS, (), {
|
||||
return navigator.userAgent.indexOf('Mac OS X') != -1
|
||||
});
|
||||
|
||||
EM_JS(void, fixCanvasInPlace, (), {
|
||||
document.getElementById('canvas').classList.add('canvas-fixed');
|
||||
});
|
||||
@ -126,6 +130,9 @@ namespace hex {
|
||||
|
||||
if (themeFollowSystem)
|
||||
EventOSThemeChanged::post();
|
||||
|
||||
if (isMacOS())
|
||||
ShortcutManager::enableMacOSMode();
|
||||
}
|
||||
|
||||
void Window::beginNativeWindowFrame() {
|
||||
|
@ -81,6 +81,10 @@ namespace hex {
|
||||
EventImHexStartupFinished::post();
|
||||
|
||||
TutorialManager::init();
|
||||
|
||||
#if defined(OS_MACOS)
|
||||
ShortcutManager::enableMacOSMode();
|
||||
#endif
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
@ -881,13 +885,11 @@ namespace hex {
|
||||
EventWindowFocused::post(focused == GLFW_TRUE);
|
||||
});
|
||||
|
||||
#if !defined(OS_WEB)
|
||||
// Register key press callback
|
||||
glfwSetInputMode(m_window, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
|
||||
glfwSetKeyCallback(m_window, [](GLFWwindow *window, int key, int scanCode, int action, int mods) {
|
||||
std::ignore = mods;
|
||||
|
||||
|
||||
// Handle A-Z keys using their ASCII value instead of the keycode
|
||||
if (key >= GLFW_KEY_A && key <= GLFW_KEY_Z) {
|
||||
std::string_view name = glfwGetKeyName(key, scanCode);
|
||||
@ -930,7 +932,6 @@ namespace hex {
|
||||
}
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
// Register window close callback
|
||||
glfwSetWindowCloseCallback(m_window, [](GLFWwindow *window) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user