From 74079ea5e4ce0282a5d078cfa80fc68d2d9da16e Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 2 Aug 2020 15:45:31 +0200 Subject: [PATCH] Copy the options used in input manager init This avoids to pass additional options to some input manager functions. Refs #1623 --- app/src/input_manager.c | 17 ++++++++++------- app/src/input_manager.h | 11 +++++------ app/src/scrcpy.c | 8 +++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index ec1d5a4e..3bf2282e 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -54,11 +54,13 @@ is_shortcut_mod(struct input_manager *im, uint16_t sdl_mod) { } void -input_manager_init(struct input_manager *im, bool prefer_text, - const struct sc_shortcut_mods *shortcut_mods) +input_manager_init(struct input_manager *im, + const struct scrcpy_options *options) { - im->prefer_text = prefer_text; + im->control = options->control; + im->prefer_text = options->prefer_text; + const struct sc_shortcut_mods *shortcut_mods = &options->shortcut_mods; assert(shortcut_mods->count); assert(shortcut_mods->count < SC_MAX_SHORTCUT_MODS); for (unsigned i = 0; i < shortcut_mods->count; ++i) { @@ -318,9 +320,9 @@ convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to, void input_manager_process_key(struct input_manager *im, - const SDL_KeyboardEvent *event, - bool control) { + const SDL_KeyboardEvent *event) { // control: indicates the state of the command-line option --no-control + bool control = im->control; bool smod = is_shortcut_mod(im, event->keysym.mod); @@ -573,8 +575,9 @@ convert_mouse_button(const SDL_MouseButtonEvent *from, struct screen *screen, void input_manager_process_mouse_button(struct input_manager *im, - const SDL_MouseButtonEvent *event, - bool control) { + const SDL_MouseButtonEvent *event) { + bool control = im->control; + if (event->which == SDL_TOUCH_MOUSEID) { // simulated from touch events, so it's a duplicate return; diff --git a/app/src/input_manager.h b/app/src/input_manager.h index c854664a..b3be6507 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -22,6 +22,7 @@ struct input_manager { // number of repetitions. This variable keeps track of the count. unsigned repeat; + bool control; bool prefer_text; struct { @@ -31,8 +32,8 @@ struct input_manager { }; void -input_manager_init(struct input_manager *im, bool prefer_text, - const struct sc_shortcut_mods *shortcut_mods); +input_manager_init(struct input_manager *im, + const struct scrcpy_options *options); void input_manager_process_text_input(struct input_manager *im, @@ -40,8 +41,7 @@ input_manager_process_text_input(struct input_manager *im, void input_manager_process_key(struct input_manager *im, - const SDL_KeyboardEvent *event, - bool control); + const SDL_KeyboardEvent *event); void input_manager_process_mouse_motion(struct input_manager *im, @@ -53,8 +53,7 @@ input_manager_process_touch(struct input_manager *im, void input_manager_process_mouse_button(struct input_manager *im, - const SDL_MouseButtonEvent *event, - bool control); + const SDL_MouseButtonEvent *event); void input_manager_process_mouse_wheel(struct input_manager *im, diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 06a3b3d1..f290f1c2 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -201,7 +201,7 @@ handle_event(SDL_Event *event, bool control) { case SDL_KEYUP: // some key events do not interact with the device, so process the // event even if control is disabled - input_manager_process_key(&input_manager, &event->key, control); + input_manager_process_key(&input_manager, &event->key); break; case SDL_MOUSEMOTION: if (!control) { @@ -219,8 +219,7 @@ handle_event(SDL_Event *event, bool control) { case SDL_MOUSEBUTTONUP: // some mouse events do not interact with the device, so process // the event even if control is disabled - input_manager_process_mouse_button(&input_manager, &event->button, - control); + input_manager_process_mouse_button(&input_manager, &event->button); break; case SDL_FINGERMOTION: case SDL_FINGERDOWN: @@ -443,8 +442,7 @@ scrcpy(const struct scrcpy_options *options) { } } - input_manager_init(&input_manager, options->prefer_text, - &options->shortcut_mods); + input_manager_init(&input_manager, options); ret = event_loop(options->display, options->control); LOGD("quit...");