From f6f2868868497b2804e3308b774f52bcc5418a5c Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 20 Oct 2019 15:32:33 +0200 Subject: [PATCH] Handle window events from screen.c Only the screen knows what to do on window events. This paves the way to handle more window events. --- app/src/scrcpy.c | 7 +------ app/src/screen.c | 11 +++++++++++ app/src/screen.h | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 64165ac5..0e56696a 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -144,12 +144,7 @@ handle_event(SDL_Event *event, bool control) { } break; case SDL_WINDOWEVENT: - switch (event->window.event) { - case SDL_WINDOWEVENT_EXPOSED: - case SDL_WINDOWEVENT_SIZE_CHANGED: - screen_render(&screen); - break; - } + screen_handle_window_event(&screen, &event->window); break; case SDL_TEXTINPUT: if (!control) { diff --git a/app/src/screen.c b/app/src/screen.c index 4bc4c5c5..0ef803fe 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -327,3 +327,14 @@ screen_resize_to_pixel_perfect(struct screen *screen) { LOGD("Resized to pixel-perfect"); } } + +void +screen_handle_window_event(struct screen *screen, + const SDL_WindowEvent *event) { + switch (event->event) { + case SDL_WINDOWEVENT_EXPOSED: + case SDL_WINDOWEVENT_SIZE_CHANGED: + screen_render(screen); + break; + } +} diff --git a/app/src/screen.h b/app/src/screen.h index bc189189..1c5695bc 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -76,4 +76,8 @@ screen_resize_to_fit(struct screen *screen); void screen_resize_to_pixel_perfect(struct screen *screen); +// react to window events +void +screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event); + #endif