From a584d6cc1027ad44f725f3440bb2d714aa62e926 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 5 Sep 2024 12:10:42 -0700 Subject: [PATCH 1/7] Fixed Alt handling by passing modifiers to the text input event. --- lib/sdl.cpp | 21 +++++++++++++++------ lib/sdl.hpp | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/sdl.cpp b/lib/sdl.cpp index d7a5620b..82b9b14d 100644 --- a/lib/sdl.cpp +++ b/lib/sdl.cpp @@ -274,10 +274,10 @@ void SdlWindow::keyDownEvent(SDL_Keysym& ks) // to be processed there. // Note: the same condition has to be used in signalKeyDown(). const char *scan_name = SDL_GetScancodeName(ks.scancode); - if ((scan_name[0] >= 32 && scan_name[0] < 127) && scan_name[1] == '\0' - && (ks.mod & (KMOD_CTRL | KMOD_ALT | KMOD_GUI)) == 0) + if ((scan_name[0] >= 32 && scan_name[0] < 127) && scan_name[1] == '\0') { lastKeyDownProcessed = false; + lastKeyDownMods = ks.mod; return; } // If any 'mod' key other than KMOD_SHIFT or KMOD_CAPS is pressed, or the key @@ -313,13 +313,22 @@ void SdlWindow::textInputEvent(const SDL_TextInputEvent &tie) const char c = tie.text[0]; if (onKeyDown[c]) { - // Keys with 'mods' (other than Shift and CapsLock) are processed in - // keyDownEvent(). - const int mods = 0; - onKeyDown[c](mods); + onKeyDown[c](lastKeyDownMods & ~(KMOD_CAPS | KMOD_LSHIFT | KMOD_RSHIFT)); // Record the key in 'saved_keys': + bool isAlt = lastKeyDownMods & (KMOD_ALT); + bool isCtrl = lastKeyDownMods & (KMOD_CTRL); + if (isAlt || isCtrl) + { + saved_keys += "["; + } + if (isCtrl) { saved_keys += "C-"; } + if (isAlt) { saved_keys += "Alt-"; } saved_keys += c; + if (isAlt || isCtrl) + { + saved_keys += "]"; + } } } diff --git a/lib/sdl.hpp b/lib/sdl.hpp index 347b3b1d..00b98a18 100644 --- a/lib/sdl.hpp +++ b/lib/sdl.hpp @@ -127,6 +127,7 @@ class SdlWindow std::string screenshot_file; bool screenshot_convert; bool lastKeyDownProcessed; + Uint16 lastKeyDownMods; // internal event handlers void windowEvent(SDL_WindowEvent& ew); From dac3d2c15f148d72e6f5213014149ca01777803e Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 5 Sep 2024 14:20:00 -0700 Subject: [PATCH 2/7] Synchronized the condition in signalKeyDown() with keyDownEvent(). --- lib/sdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sdl.cpp b/lib/sdl.cpp index 82b9b14d..0a2dd8b1 100644 --- a/lib/sdl.cpp +++ b/lib/sdl.cpp @@ -641,7 +641,7 @@ void SdlWindow::signalKeyDown(SDL_Keycode k, SDL_Keymod m) queueEvents({ event }); // The same condition as in keyDownEvent(). - if ((k >= 32 && k < 127) && (m & (KMOD_CTRL | KMOD_ALT | KMOD_GUI)) == 0) + if (k >= 32 && k < 127) { event.type = SDL_TEXTINPUT; event.text.windowID = window_id; From 9e60e60b6929e10c7d412d6c9121e76c280ea4dc Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 5 Sep 2024 14:23:55 -0700 Subject: [PATCH 3/7] Updated comments in keyDownEvent(). --- lib/sdl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/sdl.cpp b/lib/sdl.cpp index 0a2dd8b1..bba11b6f 100644 --- a/lib/sdl.cpp +++ b/lib/sdl.cpp @@ -270,8 +270,8 @@ void SdlWindow::mouseEventUp(SDL_MouseButtonEvent& eb) void SdlWindow::keyDownEvent(SDL_Keysym& ks) { // Some keyDown events will be followed by a textInput event which will - // handle key translation due to Shift or CapsLock, so we leave such events - // to be processed there. + // handle key translation due to Shift, CapsLock or AltGr, so we leave such + // events to be processed there. // Note: the same condition has to be used in signalKeyDown(). const char *scan_name = SDL_GetScancodeName(ks.scancode); if ((scan_name[0] >= 32 && scan_name[0] < 127) && scan_name[1] == '\0') @@ -280,8 +280,7 @@ void SdlWindow::keyDownEvent(SDL_Keysym& ks) lastKeyDownMods = ks.mod; return; } - // If any 'mod' key other than KMOD_SHIFT or KMOD_CAPS is pressed, or the key - // is not in the range [32,127) then we processed the event here. + // If the key is not in the range [32,127) then we processed the event here. lastKeyDownProcessed = true; if (onKeyDown[ks.sym]) { From 7abcc9fe1b6eea90162488aed83b85d06d2cb5d9 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 12 Sep 2024 12:38:55 -0700 Subject: [PATCH 4/7] Fixed handling of keys that are translated unintentionally. --- lib/sdl.cpp | 9 ++++++++- lib/sdl.hpp | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/sdl.cpp b/lib/sdl.cpp index bba11b6f..c49f09d7 100644 --- a/lib/sdl.cpp +++ b/lib/sdl.cpp @@ -278,6 +278,7 @@ void SdlWindow::keyDownEvent(SDL_Keysym& ks) { lastKeyDownProcessed = false; lastKeyDownMods = ks.mod; + lastKeyDownChar = scan_name[0]; return; } // If the key is not in the range [32,127) then we processed the event here. @@ -309,7 +310,13 @@ void SdlWindow::textInputEvent(const SDL_TextInputEvent &tie) // This event follows a keyDown event where we've recorded if the event was // processed in keyDownEvent(). If it was not processed, we do it here. if (lastKeyDownProcessed) { return; } - const char c = tie.text[0]; + char c = tie.text[0]; + if (!onKeyDown[c]) + { + // If the key was translated to something that is not handled, return to + // the physical key passed in the keyDown event. + c = lastKeyDownChar; + } if (onKeyDown[c]) { onKeyDown[c](lastKeyDownMods & ~(KMOD_CAPS | KMOD_LSHIFT | KMOD_RSHIFT)); diff --git a/lib/sdl.hpp b/lib/sdl.hpp index 00b98a18..e003cfa5 100644 --- a/lib/sdl.hpp +++ b/lib/sdl.hpp @@ -128,6 +128,7 @@ class SdlWindow bool screenshot_convert; bool lastKeyDownProcessed; Uint16 lastKeyDownMods; + char lastKeyDownChar; // internal event handlers void windowEvent(SDL_WindowEvent& ew); From 031ca5c1c63f24d12b167b908299500d40c07249 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 13 Sep 2024 14:49:32 -0700 Subject: [PATCH 5/7] Fixed stored char for Mac. --- lib/sdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sdl.cpp b/lib/sdl.cpp index c49f09d7..0a978f5f 100644 --- a/lib/sdl.cpp +++ b/lib/sdl.cpp @@ -278,7 +278,7 @@ void SdlWindow::keyDownEvent(SDL_Keysym& ks) { lastKeyDownProcessed = false; lastKeyDownMods = ks.mod; - lastKeyDownChar = scan_name[0]; + lastKeyDownChar = ks.sym; return; } // If the key is not in the range [32,127) then we processed the event here. From f241d4d214831460908c6b1a8e03b57a0f92b1b1 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 19 Sep 2024 08:36:26 -0700 Subject: [PATCH 6/7] Returned to handling ctrl, lalt and gui modifiers in kyeDownEvent(). --- lib/sdl.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/sdl.cpp b/lib/sdl.cpp index 0a978f5f..613d1720 100644 --- a/lib/sdl.cpp +++ b/lib/sdl.cpp @@ -274,14 +274,17 @@ void SdlWindow::keyDownEvent(SDL_Keysym& ks) // events to be processed there. // Note: the same condition has to be used in signalKeyDown(). const char *scan_name = SDL_GetScancodeName(ks.scancode); - if ((scan_name[0] >= 32 && scan_name[0] < 127) && scan_name[1] == '\0') + if ((scan_name[0] >= 32 && scan_name[0] < 127) && scan_name[1] == '\0' + && (ks.mod & (KMOD_CTRL | KMOD_LALT | KMOD_GUI)) == 0) { lastKeyDownProcessed = false; lastKeyDownMods = ks.mod; lastKeyDownChar = ks.sym; return; } - // If the key is not in the range [32,127) then we processed the event here. + // If any 'mod' key other than KMOD_SHIFT, KMOD_CAPS or KMOD_RALT is + // pressed, or the key is not in the range [32,127) then we processed the + // event here. lastKeyDownProcessed = true; if (onKeyDown[ks.sym]) { @@ -647,7 +650,7 @@ void SdlWindow::signalKeyDown(SDL_Keycode k, SDL_Keymod m) queueEvents({ event }); // The same condition as in keyDownEvent(). - if (k >= 32 && k < 127) + if ((k >= 32 && k < 127) && (m & (KMOD_CTRL | KMOD_LALT | KMOD_GUI)) == 0) { event.type = SDL_TEXTINPUT; event.text.windowID = window_id; From e6fc8b2f4cd40da7e7ba3335c1ec7950452dcdfe Mon Sep 17 00:00:00 2001 From: Veselin Dobrev Date: Thu, 19 Sep 2024 19:36:48 -0700 Subject: [PATCH 7/7] Document Ctrl+a in README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 346f2033..3cde3bd0 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,11 @@ Key commands - F6 – Palette menu (negative repeat number flips the palette) - F7 – Change the minimum and maximum values - Shift + F7 – Set the bounding box from the terminal +- Ctrl + a – Cycle through the auto-scaling options: + - `off`: do not change the bounding box and the value range + - `on` (default): recompute both the bounding box and the value range + - `value`: recompute only the value range + - `mesh`: recompute only the bounding box ## 2D scalar data