Skip to content

Commit

Permalink
wasd aren't handled as textinput anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
King-Slide committed Aug 20, 2018
1 parent e9775c7 commit 465b915
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to) {
MAP(SDLK_LEFT, AKEYCODE_DPAD_LEFT);
MAP(SDLK_DOWN, AKEYCODE_DPAD_DOWN);
MAP(SDLK_UP, AKEYCODE_DPAD_UP);
MAP(SDLK_w, AKEYCODE_W);
MAP(SDLK_a, AKEYCODE_A);
MAP(SDLK_s, AKEYCODE_S);
MAP(SDLK_d, AKEYCODE_D);
FAIL;
}
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/inputmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,25 @@ static void clipboard_paste(struct controller *controller) {
}
}

void input_manager_process_text_input(struct input_manager *input_manager,
SDL_bool input_manager_process_text_input(struct input_manager *input_manager,
const SDL_TextInputEvent *event) {
struct control_event control_event;
control_event.type = CONTROL_EVENT_TYPE_TEXT;
control_event.text_event.text = SDL_strdup(event->text);
if (strcmp(control_event.text_event.text, "w") == 0 ||
strcmp(control_event.text_event.text, "a") == 0 ||
strcmp(control_event.text_event.text, "s") == 0 ||
strcmp(control_event.text_event.text, "d") == 0) {
return SDL_FALSE;
}
if (!control_event.text_event.text) {
LOGW("Cannot strdup input text");
return;
return SDL_TRUE;
}
if (!controller_push_event(input_manager->controller, &control_event)) {
LOGW("Cannot send text event");
}
return SDL_TRUE;
}

void input_manager_process_key(struct input_manager *input_manager,
Expand Down
2 changes: 1 addition & 1 deletion app/src/inputmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct input_manager {
struct screen *screen;
};

void input_manager_process_text_input(struct input_manager *input_manager,
SDL_bool input_manager_process_text_input(struct input_manager *input_manager,
const SDL_TextInputEvent *event);
void input_manager_process_key(struct input_manager *input_manager,
const SDL_KeyboardEvent *event);
Expand Down
5 changes: 3 additions & 2 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ static SDL_bool event_loop(void) {
}
break;
case SDL_TEXTINPUT:
input_manager_process_text_input(&input_manager, &event.text);
break;
if (input_manager_process_text_input(&input_manager, &event.text)) {
break;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
input_manager_process_key(&input_manager, &event.key);
Expand Down

0 comments on commit 465b915

Please sign in to comment.