From f7efafd846e0d5597c6b198f523f1517bf8af782 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 3 Mar 2019 11:05:26 +0100 Subject: [PATCH] Explicitly pass control flag to input manager Replace the "global" control flag in the input_manager by a function parameter to make explicit that the behavior depends whether --no-control has been set. --- app/src/input_manager.c | 12 ++++-------- app/src/input_manager.h | 7 ++++--- app/src/scrcpy.c | 8 +++----- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index eb4047e9..f77d2d26 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -191,7 +191,8 @@ input_manager_process_text_input(struct input_manager *input_manager, void input_manager_process_key(struct input_manager *input_manager, - const SDL_KeyboardEvent *event) { + const SDL_KeyboardEvent *event, + bool control) { bool ctrl = event->keysym.mod & (KMOD_LCTRL | KMOD_RCTRL); bool alt = event->keysym.mod & (KMOD_LALT | KMOD_RALT); bool meta = event->keysym.mod & (KMOD_LGUI | KMOD_RGUI); @@ -202,9 +203,6 @@ input_manager_process_key(struct input_manager *input_manager, return; } - // false if the user requested not to interact with the device - bool control = input_manager->control; - // capture all Ctrl events if (ctrl | meta) { SDL_Keycode keycode = event->keysym.sym; @@ -341,10 +339,8 @@ is_outside_device_screen(struct input_manager *input_manager, int x, int y) void input_manager_process_mouse_button(struct input_manager *input_manager, - const SDL_MouseButtonEvent *event) { - // false if the user requested not to interact with the device - bool control = input_manager->control; - + const SDL_MouseButtonEvent *event, + bool control) { if (event->type == SDL_MOUSEBUTTONDOWN) { if (control && event->button == SDL_BUTTON_RIGHT) { press_back_or_turn_screen_on(input_manager->controller); diff --git a/app/src/input_manager.h b/app/src/input_manager.h index c30a8188..83cb7405 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -13,7 +13,6 @@ struct input_manager { struct controller *controller; struct video_buffer *video_buffer; struct screen *screen; - bool control; }; void @@ -22,7 +21,8 @@ input_manager_process_text_input(struct input_manager *input_manager, void input_manager_process_key(struct input_manager *input_manager, - const SDL_KeyboardEvent *event); + const SDL_KeyboardEvent *event, + bool control); void input_manager_process_mouse_motion(struct input_manager *input_manager, @@ -30,7 +30,8 @@ input_manager_process_mouse_motion(struct input_manager *input_manager, void input_manager_process_mouse_button(struct input_manager *input_manager, - const SDL_MouseButtonEvent *event); + const SDL_MouseButtonEvent *event, + bool control); void input_manager_process_mouse_wheel(struct input_manager *input_manager, diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index c2428c61..61b3f8d9 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -39,7 +39,6 @@ static struct input_manager input_manager = { .controller = &controller, .video_buffer = &video_buffer, .screen = &screen, - .control = true, }; // init SDL and set appropriate hints @@ -146,7 +145,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); + input_manager_process_key(&input_manager, &event->key, control); break; case SDL_MOUSEMOTION: if (!control) { @@ -164,7 +163,8 @@ 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); + input_manager_process_mouse_button(&input_manager, &event->button, + control); break; case SDL_DROPFILE: { if (!control) { @@ -301,8 +301,6 @@ scrcpy(const struct scrcpy_options *options) { goto finally_destroy_server; } - input_manager.control = control; - struct decoder *dec = NULL; if (display) { if (!video_buffer_init(&video_buffer)) {