From 6a2cd089a176bc907c151f7245df66f347c0ed28 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 17 May 2021 08:46:38 +0200 Subject: [PATCH] Initialize input manager dynamically The input manager was partially initialized statically, but a call to input_manager_init() was needed anyway, so initialize all the fields from the "constructor". This is consistent with the initialization of the other structs. --- app/src/input_manager.c | 10 +++++++--- app/src/input_manager.h | 4 ++-- app/src/scrcpy.c | 16 ++-------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 55b5fae2..b008c4db 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -52,9 +52,13 @@ is_shortcut_mod(struct input_manager *im, uint16_t sdl_mod) { } void -input_manager_init(struct input_manager *im, - const struct scrcpy_options *options) -{ +input_manager_init(struct input_manager *im, struct controller *controller, + struct screen *screen, + const struct scrcpy_options *options) { + im->controller = controller; + im->screen = screen; + im->repeat = 0; + im->control = options->control; im->forward_key_repeat = options->forward_key_repeat; im->prefer_text = options->prefer_text; diff --git a/app/src/input_manager.h b/app/src/input_manager.h index 76690757..1dd7825f 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -42,8 +42,8 @@ struct input_manager { }; void -input_manager_init(struct input_manager *im, - const struct scrcpy_options *options); +input_manager_init(struct input_manager *im, struct controller *controller, + struct screen *screen, const struct scrcpy_options *options); bool input_manager_handle_event(struct input_manager *im, SDL_Event *event); diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index e7a349d8..8d14a21b 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -40,19 +40,7 @@ static struct sc_v4l2_sink v4l2_sink; #endif static struct controller controller; static struct file_handler file_handler; - -static struct input_manager input_manager = { - .controller = &controller, - .screen = &screen, - .repeat = 0, - - // initialized later - .prefer_text = false, - .sdl_shortcut_mods = { - .data = {0}, - .count = 0, - }, -}; +static struct input_manager input_manager; #ifdef _WIN32 BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) { @@ -422,7 +410,7 @@ scrcpy(const struct scrcpy_options *options) { } stream_started = true; - input_manager_init(&input_manager, options); + input_manager_init(&input_manager, &controller, &screen, options); ret = event_loop(options); LOGD("quit...");