diff --git a/src/app/app.c b/src/app/app.c index 952cf502..911521bf 100644 --- a/src/app/app.c +++ b/src/app/app.c @@ -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; diff --git a/src/app/stream/input/session_evmouse.c b/src/app/stream/input/session_evmouse.c index f5f044a3..87aecf6f 100644 --- a/src/app/stream/input/session_evmouse.c +++ b/src/app/stream/input/session_evmouse.c @@ -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); } @@ -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) { @@ -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) { @@ -91,4 +112,5 @@ static void mouse_listener(const evmouse_event_t *event, void *userdata) { break; } } + SDL_UnlockMutex(mouse->lock); } \ No newline at end of file diff --git a/src/app/stream/input/session_evmouse.h b/src/app/stream/input/session_evmouse.h index b0cc6d5a..fa5c22f8 100644 --- a/src/app/stream/input/session_evmouse.h +++ b/src/app/stream/input/session_evmouse.h @@ -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); @@ -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); \ No newline at end of file +void session_evmouse_interrupt(session_evmouse_t *mouse); + +void session_evmouse_disable(session_evmouse_t *mouse); + +void session_evmouse_enable(session_evmouse_t *mouse); \ No newline at end of file diff --git a/src/app/stream/input/session_input.c b/src/app/stream/input/session_input.c index 606eca79..67969c6b 100644 --- a/src/app/stream/input/session_input.c +++ b/src/app/stream/input/session_input.c @@ -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 +} \ No newline at end of file diff --git a/src/app/stream/input/session_input.h b/src/app/stream/input/session_input.h index d327bde1..63d3ea67 100644 --- a/src/app/stream/input/session_input.h +++ b/src/app/stream/input/session_input.h @@ -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); diff --git a/src/app/stream/session.c b/src/app/stream/session.c index 0571ba80..cffc22d8 100644 --- a/src/app/stream/session.c +++ b/src/app/stream/session.c @@ -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; diff --git a/src/app/stream/session.h b/src/app/stream/session.h index 8096fec9..9a481352 100644 --- a/src/app/stream/session.h +++ b/src/app/stream/session.h @@ -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); diff --git a/src/app/ui/streaming/streaming.controller.c b/src/app/ui/streaming/streaming.controller.c index e57e34de..59bc6d01 100644 --- a/src/app/ui/streaming/streaming.controller.c +++ b/src/app/ui/streaming/streaming.controller.c @@ -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) { @@ -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; } diff --git a/src/app/ui/ui_input.c b/src/app/ui/ui_input.c index 1d3c1ee6..eb55a093 100644 --- a/src/app/ui/ui_input.c +++ b/src/app/ui/ui_input.c @@ -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) { diff --git a/src/app/ui/ui_input.h b/src/app/ui/ui_input.h index deff86be..8245e2d7 100644 --- a/src/app/ui/ui_input.h +++ b/src/app/ui/ui_input.h @@ -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); @@ -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); \ No newline at end of file