[client] added new win:forceAspect option

Fixes #225
This commit is contained in:
Geoffrey McRae 2020-01-03 15:53:44 +11:00
parent 899dbff7e9
commit 2196516e2b
4 changed files with 38 additions and 5 deletions

View File

@ -1 +1 @@
B1-47-g4345d94d68+1 B1-48-g899dbff7e9+1

View File

@ -151,6 +151,13 @@ static struct Option options[] =
.type = OPTION_TYPE_BOOL, .type = OPTION_TYPE_BOOL,
.value.x_bool = true, .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", .module = "win",
.name = "borderless", .name = "borderless",
@ -389,6 +396,7 @@ bool config_load(int argc, char * argv[])
params.autoResize = option_get_bool ("win", "autoResize" ); params.autoResize = option_get_bool ("win", "autoResize" );
params.allowResize = option_get_bool ("win", "allowResize" ); params.allowResize = option_get_bool ("win", "allowResize" );
params.keepAspect = option_get_bool ("win", "keepAspect" ); params.keepAspect = option_get_bool ("win", "keepAspect" );
params.forceAspect = option_get_bool ("win", "forceAspect" );
params.borderless = option_get_bool ("win", "borderless" ); params.borderless = option_get_bool ("win", "borderless" );
params.fullscreen = option_get_bool ("win", "fullScreen" ); params.fullscreen = option_get_bool ("win", "fullScreen" );
params.maximize = option_get_bool ("win", "maximize" ); params.maximize = option_get_bool ("win", "maximize" );
@ -568,4 +576,4 @@ static char * optScancodeToString(struct Option * opt)
char * str; char * str;
alloc_sprintf(&str, "%d = %s", opt->value.x_int, SDL_GetScancodeName(opt->value.x_int)); alloc_sprintf(&str, "%d = %s", opt->value.x_int, SDL_GetScancodeName(opt->value.x_int));
return str; return str;
} }

View File

@ -42,11 +42,14 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "common/thread.h" #include "common/thread.h"
#include "common/event.h" #include "common/event.h"
#include "common/ivshmem.h" #include "common/ivshmem.h"
#include "common/time.h"
#include "utils.h" #include "utils.h"
#include "kb.h" #include "kb.h"
#include "ll.h" #include "ll.h"
#define RESIZE_TIMEOUT (10 * 1000) // 10ms
// forwards // forwards
static int cursorThread(void * unused); static int cursorThread(void * unused);
static int renderThread(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.scaleX = (float)state.srcSize.y / (float)state.dstRect.h;
state.scaleY = (float)state.srcSize.x / (float)state.dstRect.w; state.scaleY = (float)state.srcSize.x / (float)state.dstRect.w;
if (params.forceAspect)
{
state.resizeTimeout = getMicrotime() + RESIZE_TIMEOUT;
state.resizeDone = false;
}
} }
state.lgrResize = true; state.lgrResize = true;
@ -161,6 +170,16 @@ static int renderThread(void * unused)
time.tv_nsec = nsec; time.tv_nsec = nsec;
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, NULL); 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; state.running = false;
@ -988,9 +1007,10 @@ static void release_key_binds()
static int lg_run() static int lg_run()
{ {
memset(&state, 0, sizeof(state)); memset(&state, 0, sizeof(state));
state.running = true; state.running = true;
state.scaleX = 1.0f; state.scaleX = 1.0f;
state.scaleY = 1.0f; state.scaleY = 1.0f;
state.resizeDone = true;
state.mouseSens = params.mouseSens; state.mouseSens = params.mouseSens;
if (state.mouseSens < -9) state.mouseSens = -9; if (state.mouseSens < -9) state.mouseSens = -9;

View File

@ -65,6 +65,10 @@ struct AppState
uint64_t frameCount; uint64_t frameCount;
uint64_t renderCount; uint64_t renderCount;
uint64_t resizeTimeout;
bool resizeDone;
KeybindHandle kbFS; KeybindHandle kbFS;
KeybindHandle kbInput; KeybindHandle kbInput;
KeybindHandle kbMouseSensInc; KeybindHandle kbMouseSensInc;
@ -80,6 +84,7 @@ struct AppParams
bool autoResize; bool autoResize;
bool allowResize; bool allowResize;
bool keepAspect; bool keepAspect;
bool forceAspect;
bool borderless; bool borderless;
bool fullscreen; bool fullscreen;
bool maximize; bool maximize;