From 89e5b460ebeeaf41f1176b231a6f34248353fdd6 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 19 Jan 2025 16:49:23 -0500 Subject: [PATCH] Add Ctrl+Plus key command for keyboard layouts that have a "+" key. --- src/app/Scene.cpp | 11 ++++++++--- src/widget/event.cpp | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 0e2c8895..c5253151 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -170,7 +170,7 @@ void Scene::onDragHover(const DragHoverEvent& e) { void Scene::onHoverKey(const HoverKeyEvent& e) { // Key commands that override children if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { - // DEBUG("key %d '%c' scancode %d keyName '%s'", e.key, e.key, e.scancode, e.keyName.c_str()); + // DEBUG("key %d '%c' scancode %d keyName '%s' mods %02x", e.key, e.key, e.scancode, e.keyName.c_str(), e.mods); if (e.isKeyCommand(GLFW_KEY_N, RACK_MOD_CTRL)) { APP->patch->loadTemplateDialog(); e.consume(this); @@ -211,8 +211,13 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { APP->scene->rackScroll->setZoom(std::pow(2.f, zoom)); e.consume(this); } - // Numpad has a "+" key, but the main keyboard section hides it under "=" - if (e.isKeyCommand(GLFW_KEY_EQUAL, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_ADD, RACK_MOD_CTRL)) { + if (e.isKeyCommand(GLFW_KEY_EQUAL, RACK_MOD_CTRL) + // The user might hold shift to access the + character + || e.isKeyCommand(GLFW_KEY_EQUAL, RACK_MOD_CTRL | GLFW_MOD_SHIFT) + // Numpad + key + || e.isKeyCommand(GLFW_KEY_KP_ADD, RACK_MOD_CTRL) + // Some layouts (e.g. QWERTZ) have a + key, but GLFW doesn't have a macro for it + || e.isKeyCommand('+', RACK_MOD_CTRL)) { float zoom = std::log2(APP->scene->rackScroll->getZoom()); zoom *= 2; zoom = std::floor(zoom + 0.01f) + 1; diff --git a/src/widget/event.cpp b/src/widget/event.cpp index f0fc9f33..aca8a96d 100644 --- a/src/widget/event.cpp +++ b/src/widget/event.cpp @@ -74,10 +74,11 @@ std::string getKeyCommandName(int key, int mods) { bool Widget::KeyBaseEvent::isKeyCommand(int key, int mods) const { + // DEBUG("this key '%c' %d keyName \"%s\" mods 0x%02x | checked key '%c' %d mods 0x%02x", this->key, this->key, this->keyName.c_str(), this->mods, key, key, mods); // Reject if mods don't match if ((this->mods & RACK_MOD_MASK) != mods) return false; - // Reject invalid keys + // Reject control characters. GLFW shouldn't generate these anyway. if (this->key < 32) return false; // Are both keys printable? @@ -91,7 +92,7 @@ bool Widget::KeyBaseEvent::isKeyCommand(int key, int mods) const { return k == key; } } - // Check equal QWERTY keys, printable or not + // Check equal GLFW key ID, printable or not return this->key == key; }