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.
This commit is contained in:
Romain Vimont 2021-12-31 16:15:41 +01:00
parent a9d23400cd
commit 2b34e1224e
3 changed files with 41 additions and 21 deletions

View file

@ -121,24 +121,22 @@ is_shortcut_mod(struct input_manager *im, uint16_t sdl_mod) {
} }
void void
input_manager_init(struct input_manager *im, struct controller *controller, input_manager_init(struct input_manager *im,
struct screen *screen, struct sc_key_processor *kp, const struct input_manager_params *params) {
struct sc_mouse_processor *mp, assert(!params->control || (params->kp && params->kp->ops));
const struct scrcpy_options *options) { assert(!params->control || (params->mp && params->mp->ops));
assert(!options->control || (kp && kp->ops));
assert(!options->control || (mp && mp->ops));
im->controller = controller; im->controller = params->controller;
im->screen = screen; im->screen = params->screen;
im->kp = kp; im->kp = params->kp;
im->mp = mp; im->mp = params->mp;
im->control = options->control; im->control = params->control;
im->forward_all_clicks = options->forward_all_clicks; im->forward_all_clicks = params->forward_all_clicks;
im->legacy_paste = options->legacy_paste; im->legacy_paste = params->legacy_paste;
im->clipboard_autosync = options->clipboard_autosync; 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);
assert(shortcut_mods->count < SC_MAX_SHORTCUT_MODS); assert(shortcut_mods->count < SC_MAX_SHORTCUT_MODS);
for (unsigned i = 0; i < shortcut_mods->count; ++i) { for (unsigned i = 0; i < shortcut_mods->count; ++i) {

View file

@ -43,11 +43,22 @@ struct input_manager {
uint64_t next_sequence; // used for request acknowledgements 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 void
input_manager_init(struct input_manager *im, struct controller *controller, input_manager_init(struct input_manager *im,
struct screen *screen, struct sc_key_processor *kp, const struct input_manager_params *params);
struct sc_mouse_processor *mp,
const struct scrcpy_options *options);
bool bool
input_manager_handle_event(struct input_manager *im, SDL_Event *event); input_manager_handle_event(struct input_manager *im, SDL_Event *event);

View file

@ -582,8 +582,19 @@ aoa_hid_end:
mp = &s->mouse_inject.mouse_processor; mp = &s->mouse_inject.mouse_processor;
} }
input_manager_init(&s->input_manager, &s->controller, &s->screen, kp, mp, struct input_manager_params im_params = {
options); .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); ret = event_loop(s, options);
LOGD("quit..."); LOGD("quit...");