From 7f6a565401efcdf4e1ececed7b1beaf72d73e97a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 2 Feb 2018 11:52:19 +0100 Subject: [PATCH] Extract shortcut actions to separate functions To simplify event handling code, move all actions to separate functions. --- app/src/scrcpy.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index c388fce1..c6dd3cb2 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -238,6 +238,21 @@ static void switch_fullscreen(void) { render(renderer, texture_empty ? NULL : texture); } +static void resize_to_fit(void) { + if (!fullscreen) { + struct size optimal_size = get_optimal_window_size(window, frame_size); + SDL_SetWindowSize(window, optimal_size.width, optimal_size.height); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Resized to optimal size"); + } +} + +static void resize_to_pixel_perfect(void) { + if (!fullscreen) { + SDL_SetWindowSize(window, frame_size.width, frame_size.height); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Resized to pixel-perfect"); + } +} + static int wait_for_success(process_t proc, const char *name) { if (proc == PROCESS_NONE) { SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Could not execute \"%s\"", name); @@ -342,22 +357,15 @@ static void handle_key(const SDL_KeyboardEvent *event) { return; } - // Ctrl+x: optimal size + // Ctrl+x: optimal size (remove black borders) if (keycode == SDLK_x && !shift) { - if (!fullscreen) { - struct size optimal_size = get_optimal_window_size(window, frame_size); - SDL_SetWindowSize(window, optimal_size.width, optimal_size.height); - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Resized to optimal size"); - } + resize_to_fit(); return; } // Ctrl+g: pixel-perfect (ratio 1:1) if (keycode == SDLK_g && !shift) { - if (!fullscreen) { - SDL_SetWindowSize(window, frame_size.width, frame_size.height); - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Resized to pixel-perfect"); - } + resize_to_pixel_perfect(); return; }