Skip to content

Commit

Permalink
SDL2: preliminary handling SDL_TEXTINPUT
Browse files Browse the repository at this point in the history
This commit introduces preliminary support for using the SDL2's
textinput API.

So far it only has been tested with dhewm3's console where it
performs adequately.

Issue #368.
  • Loading branch information
cnuke authored and chelmuth committed May 29, 2024
1 parent 745d4ae commit d6c2245
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/lib/sdl2/video/SDL_genode_fb_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ extern "C" {
#include "SDL_sysevents.h"
#include "SDL_genode_fb_events.h"

static bool skipcode(Genode::Codepoint const code)
{
if (!code.valid())
return true;

/* non-printable ascii */
if (code.value <= 31 || code.value == 127)
return true;

/* function-key unicodes */
if (code.value >= 0xf000 && code.value <= 0xf72d)
return true;

return false;
}

static Genode::Constructible<Input::Session_client> input;
static SDL_Scancode scancodes[SDL_NUM_SCANCODES];
Expand Down Expand Up @@ -153,8 +168,13 @@ extern "C" {
curr.handle_press([&] (Input::Keycode key, Genode::Codepoint codepoint) {
if (mouse_button(key))
SDL_SendMouseButton(window, mouse_id, SDL_PRESSED, buttonmap[key]);
else
else if (skipcode(codepoint) || !SDL_IsTextInputActive())
SDL_SendKeyboardKey(SDL_PRESSED, getscancode(key));
else {
Genode::String<5> text(codepoint);
if (text.valid())
SDL_SendKeyboardText(text.string());
}
});

curr.handle_wheel([&] (int const x, int const y) {
Expand Down

0 comments on commit d6c2245

Please sign in to comment.