From 2b34e1224e97e21ca04ce751bf513d85fbcc4a45 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 31 Dec 2021 16:15:41 +0100 Subject: [PATCH] Use separate struct for input manager params This avoids to directly pass the options instance (which contains more data than strictly necessary), and limit the number of parameters for the init function. --- app/src/input_manager.c | 28 +++++++++++++--------------- app/src/input_manager.h | 19 +++++++++++++++---- app/src/scrcpy.c | 15 +++++++++++++-- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 34bab246..ce138012 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -121,24 +121,22 @@ is_shortcut_mod(struct input_manager *im, uint16_t sdl_mod) { } void -input_manager_init(struct input_manager *im, struct controller *controller, - struct screen *screen, struct sc_key_processor *kp, - struct sc_mouse_processor *mp, - const struct scrcpy_options *options) { - assert(!options->control || (kp && kp->ops)); - assert(!options->control || (mp && mp->ops)); +input_manager_init(struct input_manager *im, + const struct input_manager_params *params) { + assert(!params->control || (params->kp && params->kp->ops)); + assert(!params->control || (params->mp && params->mp->ops)); - im->controller = controller; - im->screen = screen; - im->kp = kp; - im->mp = mp; + im->controller = params->controller; + im->screen = params->screen; + im->kp = params->kp; + im->mp = params->mp; - im->control = options->control; - im->forward_all_clicks = options->forward_all_clicks; - im->legacy_paste = options->legacy_paste; - im->clipboard_autosync = options->clipboard_autosync; + im->control = params->control; + im->forward_all_clicks = params->forward_all_clicks; + im->legacy_paste = params->legacy_paste; + im->clipboard_autosync = params->clipboard_autosync; - const struct sc_shortcut_mods *shortcut_mods = &options->shortcut_mods; + const struct sc_shortcut_mods *shortcut_mods = params->shortcut_mods; assert(shortcut_mods->count); assert(shortcut_mods->count < SC_MAX_SHORTCUT_MODS); for (unsigned i = 0; i < shortcut_mods->count; ++i) { diff --git a/app/src/input_manager.h b/app/src/input_manager.h index 5e02b457..38d0d703 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -43,11 +43,22 @@ struct input_manager { uint64_t next_sequence; // used for request acknowledgements }; +struct input_manager_params { + struct controller *controller; + struct screen *screen; + struct sc_key_processor *kp; + struct sc_mouse_processor *mp; + + bool control; + bool forward_all_clicks; + bool legacy_paste; + bool clipboard_autosync; + const struct sc_shortcut_mods *shortcut_mods; +}; + void -input_manager_init(struct input_manager *im, struct controller *controller, - struct screen *screen, struct sc_key_processor *kp, - struct sc_mouse_processor *mp, - const struct scrcpy_options *options); +input_manager_init(struct input_manager *im, + const struct input_manager_params *params); 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 51eb19fb..972e2d99 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -582,8 +582,19 @@ aoa_hid_end: mp = &s->mouse_inject.mouse_processor; } - input_manager_init(&s->input_manager, &s->controller, &s->screen, kp, mp, - options); + struct input_manager_params im_params = { + .controller = &s->controller, + .screen = &s->screen, + .kp = kp, + .mp = mp, + .control = options->control, + .forward_all_clicks = options->forward_all_clicks, + .legacy_paste = options->legacy_paste, + .clipboard_autosync = options->clipboard_autosync, + .shortcut_mods = &options->shortcut_mods, + }; + + input_manager_init(&s->input_manager, &im_params); ret = event_loop(s, options); LOGD("quit...");