From 2196516e2bb6401129f057906258862d3a60b9e8 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 3 Jan 2020 15:53:44 +1100 Subject: [PATCH] [client] added new `win:forceAspect` option Fixes #225 --- VERSION | 2 +- client/src/config.c | 10 +++++++++- client/src/main.c | 26 +++++++++++++++++++++++--- client/src/main.h | 5 +++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index d4e46533..585a33b3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-47-g4345d94d68+1 \ No newline at end of file +B1-48-g899dbff7e9+1 \ No newline at end of file diff --git a/client/src/config.c b/client/src/config.c index 9c683c9c..2d899ba0 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -151,6 +151,13 @@ static struct Option options[] = .type = OPTION_TYPE_BOOL, .value.x_bool = true, }, + { + .module = "win", + .name = "forceAspect", + .description = "Force the window to maintain the aspect ratio", + .type = OPTION_TYPE_BOOL, + .value.x_bool = true, + }, { .module = "win", .name = "borderless", @@ -389,6 +396,7 @@ bool config_load(int argc, char * argv[]) params.autoResize = option_get_bool ("win", "autoResize" ); params.allowResize = option_get_bool ("win", "allowResize" ); params.keepAspect = option_get_bool ("win", "keepAspect" ); + params.forceAspect = option_get_bool ("win", "forceAspect" ); params.borderless = option_get_bool ("win", "borderless" ); params.fullscreen = option_get_bool ("win", "fullScreen" ); params.maximize = option_get_bool ("win", "maximize" ); @@ -568,4 +576,4 @@ static char * optScancodeToString(struct Option * opt) char * str; alloc_sprintf(&str, "%d = %s", opt->value.x_int, SDL_GetScancodeName(opt->value.x_int)); return str; -} +} \ No newline at end of file diff --git a/client/src/main.c b/client/src/main.c index 27546984..1022a55e 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -42,11 +42,14 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/thread.h" #include "common/event.h" #include "common/ivshmem.h" +#include "common/time.h" #include "utils.h" #include "kb.h" #include "ll.h" +#define RESIZE_TIMEOUT (10 * 1000) // 10ms + // forwards static int cursorThread(void * unused); static int renderThread(void * unused); @@ -98,6 +101,12 @@ static void updatePositionInfo() state.scaleX = (float)state.srcSize.y / (float)state.dstRect.h; state.scaleY = (float)state.srcSize.x / (float)state.dstRect.w; + + if (params.forceAspect) + { + state.resizeTimeout = getMicrotime() + RESIZE_TIMEOUT; + state.resizeDone = false; + } } state.lgrResize = true; @@ -161,6 +170,16 @@ static int renderThread(void * unused) time.tv_nsec = nsec; clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, NULL); + + if (!state.resizeDone && state.resizeTimeout < getMicrotime()) + { + SDL_SetWindowSize( + state.window, + state.dstRect.w, + state.dstRect.h + ); + state.resizeDone = true; + } } state.running = false; @@ -988,9 +1007,10 @@ static void release_key_binds() static int lg_run() { memset(&state, 0, sizeof(state)); - state.running = true; - state.scaleX = 1.0f; - state.scaleY = 1.0f; + state.running = true; + state.scaleX = 1.0f; + state.scaleY = 1.0f; + state.resizeDone = true; state.mouseSens = params.mouseSens; if (state.mouseSens < -9) state.mouseSens = -9; diff --git a/client/src/main.h b/client/src/main.h index d5da7e3f..ad623e69 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -65,6 +65,10 @@ struct AppState uint64_t frameCount; uint64_t renderCount; + + uint64_t resizeTimeout; + bool resizeDone; + KeybindHandle kbFS; KeybindHandle kbInput; KeybindHandle kbMouseSensInc; @@ -80,6 +84,7 @@ struct AppParams bool autoResize; bool allowResize; bool keepAspect; + bool forceAspect; bool borderless; bool fullscreen; bool maximize;