Skip to content

Commit

Permalink
Fixed Alt handling by passing modifiers to the text input event.
Browse files Browse the repository at this point in the history
  • Loading branch information
najlkin committed Sep 5, 2024
1 parent 7053ae2 commit a584d6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 += "]";
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/sdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a584d6c

Please sign in to comment.