Skip to content

Commit

Permalink
Pass full options struct to static functions
Browse files Browse the repository at this point in the history
This avoids to pass specific options values individually. Since these
function are static (internal to the file), this is not a problem to
make them depend on scrcpy_options.

Refs #1623 <#1623>

Signed-off-by: Romain Vimont <rom@rom1v.com>
  • Loading branch information
xeropresence authored and rom1v committed Aug 2, 2020
1 parent 74079ea commit 65d06a3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ enum event_result {
};

static enum event_result
handle_event(SDL_Event *event, bool control) {
handle_event(SDL_Event *event, const struct scrcpy_options *options) {
switch (event->type) {
case EVENT_STREAM_STOPPED:
LOGD("Video stream stopped");
Expand All @@ -192,7 +192,7 @@ handle_event(SDL_Event *event, bool control) {
screen_handle_window_event(&screen, &event->window);
break;
case SDL_TEXTINPUT:
if (!control) {
if (!options->control) {
break;
}
input_manager_process_text_input(&input_manager, &event->text);
Expand All @@ -204,13 +204,13 @@ handle_event(SDL_Event *event, bool control) {
input_manager_process_key(&input_manager, &event->key);
break;
case SDL_MOUSEMOTION:
if (!control) {
if (!options->control) {
break;
}
input_manager_process_mouse_motion(&input_manager, &event->motion);
break;
case SDL_MOUSEWHEEL:
if (!control) {
if (!options->control) {
break;
}
input_manager_process_mouse_wheel(&input_manager, &event->wheel);
Expand All @@ -227,7 +227,7 @@ handle_event(SDL_Event *event, bool control) {
input_manager_process_touch(&input_manager, &event->tfinger);
break;
case SDL_DROPFILE: {
if (!control) {
if (!options->control) {
break;
}
file_handler_action_t action;
Expand All @@ -244,16 +244,15 @@ handle_event(SDL_Event *event, bool control) {
}

static bool
event_loop(bool display, bool control) {
(void) display;
event_loop(const struct scrcpy_options *options) {
#ifdef CONTINUOUS_RESIZING_WORKAROUND
if (display) {
if (options->display) {
SDL_AddEventWatch(event_watcher, NULL);
}
#endif
SDL_Event event;
while (SDL_WaitEvent(&event)) {
enum event_result result = handle_event(&event, control);
enum event_result result = handle_event(&event, options);
switch (result) {
case EVENT_RESULT_STOPPED_BY_USER:
return true;
Expand Down Expand Up @@ -444,7 +443,7 @@ scrcpy(const struct scrcpy_options *options) {

input_manager_init(&input_manager, options);

ret = event_loop(options->display, options->control);
ret = event_loop(options);
LOGD("quit...");

screen_destroy(&screen);
Expand Down

0 comments on commit 65d06a3

Please sign in to comment.