Skip to content

Commit

Permalink
fixing osk and mouse input
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed May 18, 2024
1 parent e8ab4c1 commit e87f8fb
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ static int app_event_filter(void *userdata, SDL_Event *event) {
case SDL_CONTROLLERTOUCHPADUP:
case SDL_CONTROLLERSENSORUPDATE:
case SDL_TEXTINPUT: {
if (event->type == SDL_MOUSEMOTION) {
bool updated = app_text_input_state_update(&app->ui.input);
if (updated && !app->ui.input.text_input_active && app->session != NULL) {
session_screen_keyboard_closed(app->session);
}
}
if (!app_ui_is_opened(&app->ui) && app->session != NULL) {
session_handle_input_event(app->session, event);
return 0;
Expand Down
24 changes: 23 additions & 1 deletion src/app/stream/input/session_evmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void session_evmouse_init(session_evmouse_t *mouse, session_t *session) {
mouse->session = session;
mouse->lock = SDL_CreateMutex();
mouse->cond = SDL_CreateCond();
mouse->disabled = SDL_FALSE;
mouse->thread = SDL_CreateThread((SDL_ThreadFunction) mouse_worker, "sessinput", mouse);
}

Expand Down Expand Up @@ -46,6 +47,24 @@ void session_evmouse_interrupt(session_evmouse_t *mouse) {
SDL_UnlockMutex(mouse->lock);
}

void session_evmouse_disable(session_evmouse_t *mouse) {
SDL_LockMutex(mouse->lock);
if (!mouse->disabled) {
commons_log_info("Session", "EvMouse disable input");
mouse->disabled = SDL_TRUE;
}
SDL_UnlockMutex(mouse->lock);
}

void session_evmouse_enable(session_evmouse_t *mouse) {
SDL_LockMutex(mouse->lock);
if (mouse->disabled) {
commons_log_info("Session", "EvMouse enable input");
mouse->disabled = SDL_FALSE;
}
SDL_UnlockMutex(mouse->lock);
}

static int mouse_worker(session_evmouse_t *mouse) {
evmouse_t *dev = evmouse_open_default();
if (dev == NULL) {
Expand All @@ -70,8 +89,10 @@ static void set_evmouse(session_evmouse_t *mouse, evmouse_t *dev) {

static void mouse_listener(const evmouse_event_t *event, void *userdata) {
session_evmouse_t *mouse = userdata;
SDL_LockMutex(mouse->lock);
session_t *session = mouse->session;
if (!session_accepting_input(session)) {
if (!session_accepting_input(session) || mouse->disabled) {
SDL_UnlockMutex(mouse->lock);
return;
}
switch (event->type) {
Expand All @@ -91,4 +112,5 @@ static void mouse_listener(const evmouse_event_t *event, void *userdata) {
break;
}
}
SDL_UnlockMutex(mouse->lock);
}
7 changes: 6 additions & 1 deletion src/app/stream/input/session_evmouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef struct session_evmouse_t {
SDL_cond *cond;
SDL_Thread *thread;
struct evmouse_t *dev;
SDL_bool disabled;
} session_evmouse_t;

void session_evmouse_init(session_evmouse_t *mouse, session_t *session);
Expand All @@ -18,4 +19,8 @@ void session_evmouse_deinit(session_evmouse_t *mouse);

void session_evmouse_wait_ready(session_evmouse_t *mouse);

void session_evmouse_interrupt(session_evmouse_t *mouse);
void session_evmouse_interrupt(session_evmouse_t *mouse);

void session_evmouse_disable(session_evmouse_t *mouse);

void session_evmouse_enable(session_evmouse_t *mouse);
18 changes: 18 additions & 0 deletions src/app/stream/input/session_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ void session_input_started(stream_input_t *input) {
void session_input_stopped(stream_input_t *input) {
input->started = false;
}

void session_input_screen_keyboard_opened(stream_input_t *input) {
#if FEATURE_INPUT_EVMOUSE
const session_config_t *config = &input->session->config;
if (config->hardware_mouse) {
session_evmouse_disable(&input->evmouse);
}
#endif
}

void session_input_screen_keyboard_closed(stream_input_t *input) {
#if FEATURE_INPUT_EVMOUSE
const session_config_t *config = &input->session->config;
if (config->hardware_mouse) {
session_evmouse_enable(&input->evmouse);
}
#endif
}
4 changes: 4 additions & 0 deletions src/app/stream/input/session_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ void session_input_started(stream_input_t *input);

void session_input_stopped(stream_input_t *input);

void session_input_screen_keyboard_opened(stream_input_t *input);

void session_input_screen_keyboard_closed(stream_input_t *input);

void stream_input_send_gamepad_arrive(const stream_input_t *input, app_gamepad_state_t *gamepad);

void stream_input_handle_key(stream_input_t *input, const SDL_KeyboardEvent *event);
Expand Down
8 changes: 8 additions & 0 deletions src/app/stream/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ void session_toggle_vmouse(session_t *session) {
session_input_set_vmouse_active(&session->input.vmouse, value);
}

void session_screen_keyboard_opened(session_t *session) {
session_input_screen_keyboard_opened(&session->input);
}

void session_screen_keyboard_closed(session_t *session) {
session_input_screen_keyboard_closed(&session->input);
}

void streaming_display_size(session_t *session, short width, short height) {
session->display_width = width;
session->display_height = height;
Expand Down
4 changes: 4 additions & 0 deletions src/app/stream/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ bool session_has_input(session_t *session);

void session_toggle_vmouse(session_t *session);

void session_screen_keyboard_opened(session_t *session);

void session_screen_keyboard_closed(session_t *session);

bool session_accepting_input(session_t *session);

void streaming_display_size(session_t *session, short width, short height);
Expand Down
5 changes: 4 additions & 1 deletion src/app/ui/streaming/streaming.controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ static void open_keyboard(lv_event_t *event) {
streaming_controller_t *controller = lv_event_get_user_data(event);
hide_overlay(event);
app_t *app = controller->global;
app_start_text_input(&app->ui.input, 0, (app->ui.width - 10) / 2, app->ui.width, 10);
app_start_text_input(&app->ui.input, 0, app->ui.height / 2 - 40, app->ui.width, 40);
session_screen_keyboard_opened(app->session);
}

static void toggle_vmouse(lv_event_t *event) {
Expand All @@ -291,6 +292,8 @@ bool show_overlay(streaming_controller_t *controller) {
lv_area_get_height(&coords));
streaming_refresh_stats();

app_stop_text_input(&controller->global->ui.input);

update_buttons_layout(controller);
return true;
}
Expand Down
18 changes: 17 additions & 1 deletion src/app/ui/ui_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,36 @@ void app_input_set_button_points(app_ui_input_t *input, const lv_point_t *points
void app_start_text_input(app_ui_input_t *input, int x, int y, int w, int h) {
if (w > 0 && h > 0) {
SDL_Rect rect = {x, y, w, h};
commons_log_info("Input", "Setting text input rect to %d, %d, %d, %d", x, y, w, h);
SDL_SetTextInputRect(&rect);
} else {
commons_log_info("Input", "Clearing text input rect");
SDL_SetTextInputRect(NULL);
}
lv_sdl_key_input_release_key(input->key.indev);
if (SDL_IsTextInputActive()) {
commons_log_info("Input", "Text input already active");
return;
}
commons_log_info("Input", "Starting text input");
SDL_StartTextInput();
input->text_input_active = true;
}

void app_stop_text_input(app_ui_input_t *input) {
(void) input;
if (SDL_IsTextInputActive()) {
commons_log_info("Input", "Stopping text input");
}
SDL_StopTextInput();
input->text_input_active = false;
}

bool app_text_input_state_update(app_ui_input_t *input) {
if (input->text_input_active && !SDL_IsTextInputActive()) {
input->text_input_active = false;
return true;
}
return false;
}

static void app_input_populate_group(app_ui_input_t *input) {
Expand Down
5 changes: 5 additions & 0 deletions src/app/ui/ui_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct app_ui_input_t {
app_ui_input_lv_pair_t wheel;
app_ui_input_lv_pair_t button;
app_ui_input_mode_t mode;
bool text_input_active;
};

void app_ui_input_init(app_ui_input_t *input, app_ui_t *ui);
Expand All @@ -58,3 +59,7 @@ void app_start_text_input(app_ui_input_t *input, int x, int y, int w, int h);

void app_stop_text_input(app_ui_input_t *input);

/**
* @return true if state was updated
*/
bool app_text_input_state_update(app_ui_input_t *input);

0 comments on commit e87f8fb

Please sign in to comment.