From a7fe9ad779057f7a2698fc1769dce3c3786993ee Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 18 Nov 2018 21:20:21 +0100 Subject: [PATCH 1/3] Ignore mouse events outside device screen Never create a "struct point" with a position possibly outside the device screen (i.e. in the black borders area), and do not transmit such events. This fixes an assertion failure on mouse wheel events outside the device screen area. --- app/src/input_manager.c | 58 +++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 21b7c407..7a3a4ad1 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -18,16 +18,9 @@ static void convert_to_renderer_coordinates(SDL_Renderer *renderer, int *x, int *y = (int) (*y / scale_y) - viewport.y; } -static struct point get_mouse_point(struct screen *screen) { - int x; - int y; - SDL_GetMouseState(&x, &y); - convert_to_renderer_coordinates(screen->renderer, &x, &y); - SDL_assert_release(x >= 0 && x < 0x10000 && y >= 0 && y < 0x10000); - return (struct point) { - .x = (Uint16) x, - .y = (Uint16) y, - }; +static void get_mouse_point(struct screen *screen, int *x, int *y) { + SDL_GetMouseState(x, y); + convert_to_renderer_coordinates(screen->renderer, x, y); } static const int ACTION_DOWN = 1; @@ -271,8 +264,18 @@ void input_manager_process_mouse_motion(struct input_manager *input_manager, } } +static SDL_bool is_outside_device_screen(struct input_manager *input_manager, + int x, int y) +{ + return x < 0 || x >= input_manager->screen->frame_size.width || + y < 0 || y >= input_manager->screen->frame_size.height; +} + void input_manager_process_mouse_button(struct input_manager *input_manager, const SDL_MouseButtonEvent *event) { + SDL_bool outside_device_screen = is_outside_device_screen(input_manager, + event->x, + event->y); if (event->type == SDL_MOUSEBUTTONDOWN) { if (event->button == SDL_BUTTON_RIGHT) { press_back_or_turn_screen_on(input_manager->controller); @@ -283,17 +286,19 @@ void input_manager_process_mouse_button(struct input_manager *input_manager, return; } // double-click on black borders resize to fit the device screen - if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) { - SDL_bool outside_device_screen = - event->x < 0 || event->x >= input_manager->screen->frame_size.width || - event->y < 0 || event->y >= input_manager->screen->frame_size.height; - if (outside_device_screen) { - screen_resize_to_fit(input_manager->screen); - return; - } - // otherwise, send the click event to the device + if (event->button == SDL_BUTTON_LEFT && event->clicks == 2 + && outside_device_screen) { + screen_resize_to_fit(input_manager->screen); + return; } + // otherwise, send the click event to the device } + + if (outside_device_screen) { + // ignore + return; + } + struct control_event control_event; if (mouse_button_from_sdl_to_android(event, input_manager->screen->frame_size, &control_event)) { if (!controller_push_event(input_manager->controller, &control_event)) { @@ -304,9 +309,22 @@ void input_manager_process_mouse_button(struct input_manager *input_manager, void input_manager_process_mouse_wheel(struct input_manager *input_manager, const SDL_MouseWheelEvent *event) { + int x; + int y; + get_mouse_point(input_manager->screen, &x, &y); + if (is_outside_device_screen(input_manager, x, y)) { + // ignore + return; + } + + SDL_assert_release(x >= 0 && x < 0x10000 && y >= 0 && y < 0x10000); + struct position position = { .screen_size = input_manager->screen->frame_size, - .point = get_mouse_point(input_manager->screen), + .point = { + .x = (Uint16) x, + .y = (Uint16) y, + }, }; struct control_event control_event; if (mouse_wheel_from_sdl_to_android(event, position, &control_event)) { From f7d02cad4b3c7a48fe5770182b9e9a2d42bd9f56 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 19 Nov 2018 09:38:40 +0100 Subject: [PATCH 2/3] Add ninja-build to the packages list to install The package ninja-build should be installed automatically as a meson dependency, but some users need to install a newer meson from pip3, so ninja must be installed explicitly. --- BUILD.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.md b/BUILD.md index 0da80d57..9c845215 100644 --- a/BUILD.md +++ b/BUILD.md @@ -43,7 +43,7 @@ Install the required packages from your package manager. sudo apt install ffmpeg libsdl2-2.0.0 # client build dependencies -sudo apt install make gcc pkg-config meson \ +sudo apt install make gcc pkg-config meson ninja-build \ libavcodec-dev libavformat-dev libavutil-dev \ libsdl2-dev From 0e019f8ab8f9176e99e162136fbc4b63e7a46f32 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 25 Nov 2018 11:29:27 +0100 Subject: [PATCH 3/3] Add a note to allow simulating input in README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 46a930ef..388c7f52 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ Make sure you [enabled adb debugging][enable-adb] on your device(s). [enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling +On some devices, you also need to enable [an additional option][control] to +control it using keyboard and mouse. + +[control]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323 + ## Get the app