Copy the options used in input manager init

This avoids to pass additional options to some input manager functions.

Refs #1623 <https://github.com/Genymobile/scrcpy/pull/1623>
This commit is contained in:
Romain Vimont 2020-08-02 15:45:31 +02:00
parent 0870d8620f
commit 74079ea5e4
3 changed files with 18 additions and 18 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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...");