Skip to content

Commit 9e029d7

Browse files
committed
Handle alpha and space chars as raw events
To handle special chars, text is handled as text input instead of key events. However, this breaks the separation of DOWN and UP key events. As a compromise, send letters and space as key events, to preserve original DOWN/UP events, but send other text input events as text, to be able to send "special" characters.
1 parent 6a1fb07 commit 9e029d7

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

app/src/convert.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static enum android_metastate convert_meta_state(SDL_Keymod mod) {
7070
return autocomplete_metastate(metastate);
7171
}
7272

73-
static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to) {
73+
static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to, Uint16 mod) {
7474
switch (from) {
7575
MAP(SDLK_RETURN, AKEYCODE_ENTER);
7676
MAP(SDLK_KP_ENTER, AKEYCODE_NUMPAD_ENTER);
@@ -86,6 +86,39 @@ static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to) {
8686
MAP(SDLK_LEFT, AKEYCODE_DPAD_LEFT);
8787
MAP(SDLK_DOWN, AKEYCODE_DPAD_DOWN);
8888
MAP(SDLK_UP, AKEYCODE_DPAD_UP);
89+
}
90+
if (mod & (KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI)) {
91+
return SDL_FALSE;
92+
}
93+
// if ALT and META are not pressed, also handle letters and space
94+
switch (from) {
95+
MAP(SDLK_a, AKEYCODE_A);
96+
MAP(SDLK_b, AKEYCODE_B);
97+
MAP(SDLK_c, AKEYCODE_C);
98+
MAP(SDLK_d, AKEYCODE_D);
99+
MAP(SDLK_e, AKEYCODE_E);
100+
MAP(SDLK_f, AKEYCODE_F);
101+
MAP(SDLK_g, AKEYCODE_G);
102+
MAP(SDLK_h, AKEYCODE_H);
103+
MAP(SDLK_i, AKEYCODE_I);
104+
MAP(SDLK_j, AKEYCODE_J);
105+
MAP(SDLK_k, AKEYCODE_K);
106+
MAP(SDLK_l, AKEYCODE_L);
107+
MAP(SDLK_m, AKEYCODE_M);
108+
MAP(SDLK_n, AKEYCODE_N);
109+
MAP(SDLK_o, AKEYCODE_O);
110+
MAP(SDLK_p, AKEYCODE_P);
111+
MAP(SDLK_q, AKEYCODE_Q);
112+
MAP(SDLK_r, AKEYCODE_R);
113+
MAP(SDLK_s, AKEYCODE_S);
114+
MAP(SDLK_t, AKEYCODE_T);
115+
MAP(SDLK_u, AKEYCODE_U);
116+
MAP(SDLK_v, AKEYCODE_V);
117+
MAP(SDLK_w, AKEYCODE_W);
118+
MAP(SDLK_x, AKEYCODE_X);
119+
MAP(SDLK_y, AKEYCODE_Y);
120+
MAP(SDLK_z, AKEYCODE_Z);
121+
MAP(SDLK_SPACE, AKEYCODE_SPACE);
89122
FAIL;
90123
}
91124
}
@@ -126,11 +159,12 @@ SDL_bool input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
126159
return SDL_FALSE;
127160
}
128161

129-
if (!convert_keycode(from->keysym.sym, &to->keycode_event.keycode)) {
162+
Uint16 mod = from->keysym.mod;
163+
if (!convert_keycode(from->keysym.sym, &to->keycode_event.keycode, mod)) {
130164
return SDL_FALSE;
131165
}
132166

133-
to->keycode_event.metastate = convert_meta_state(from->keysym.mod);
167+
to->keycode_event.metastate = convert_meta_state(mod);
134168

135169
return SDL_TRUE;
136170
}

app/src/input_manager.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "input_manager.h"
22

3+
#include <SDL2/SDL_assert.h>
34
#include "convert.h"
45
#include "lock_util.h"
56
#include "log.h"
@@ -129,6 +130,12 @@ static void clipboard_paste(struct controller *controller) {
129130

130131
void input_manager_process_text_input(struct input_manager *input_manager,
131132
const SDL_TextInputEvent *event) {
133+
char c = event->text[0];
134+
if (isalpha(c) || c == ' ') {
135+
SDL_assert(event->text[1] == '\0');
136+
// letters and space are handled as raw key event
137+
return;
138+
}
132139
struct control_event control_event;
133140
control_event.type = CONTROL_EVENT_TYPE_TEXT;
134141
control_event.text_event.text = SDL_strdup(event->text);

0 commit comments

Comments
 (0)