Fix SDL borderless windowed mode for real this time

Introduces r_borderless cvar. 0: never borderless, 1: always borderless, 2: borderless if resolution matches desktop resolution (default).

git-svn-id: https://svn.eduke32.com/eduke32@8060 1a8010ca-5511-0410-912e-c29ae57300e0

# Conflicts:
#	source/build/include/baselayer.h
#	source/build/src/baselayer.cpp
#	source/build/src/polymost.cpp
This commit is contained in:
terminx 2019-08-29 19:00:52 +00:00 committed by Christoph Oelckers
parent 4300eb1a66
commit f0ea646560
3 changed files with 11 additions and 7 deletions

View File

@ -28,6 +28,7 @@ extern char quitevent, appactive;
extern char modechange;
extern int32_t vsync;
extern int32_t g_borderless;
extern void app_crashhandler(void);

View File

@ -18,6 +18,7 @@ extern "C"
}
#endif // _WIN32
int32_t g_borderless=2;
// input
char inputdevices = 0;

View File

@ -1590,8 +1590,8 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
SDL_DisplayMode desktopmode;
SDL_GetDesktopDisplayMode(0, &desktopmode);
int const windowedMode = (desktopmode.w == x && desktopmode.h == y) ? SDL_WINDOW_BORDERLESS : 0;
int const matchedResolution = (desktopmode.w == x && desktopmode.h == y);
int const borderless = (g_borderless == 1 || (g_borderless == 2 && matchedResolution)) ? SDL_WINDOW_BORDERLESS : 0;
#ifdef USE_OPENGL
if (c > 8 || !nogl)
{
@ -1630,9 +1630,11 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
/* HACK: changing SDL GL attribs only works before surface creation,
so we have to create a new surface in a different format first
to force the surface we WANT to be recreated instead of reused. */
sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED,
windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED, x, y,
SDL_WINDOW_OPENGL);
SDL_WINDOW_OPENGL | borderless);
if (sdl_window)
sdl_context = SDL_GL_CreateContext(sdl_window);
@ -1640,6 +1642,7 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
if (!sdl_window || !sdl_context)
{
initprintf("Unable to set video mode: %s failed: %s\n", sdl_window ? "SDL_GL_CreateContext" : "SDL_GL_CreateWindow", SDL_GetError());
nogl = 1;
destroy_window_resources();
return -1;
}
@ -1653,8 +1656,7 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
return -1;
}
// this is using the windowedMode variable to determine whether to pass SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP
SDL_SetWindowFullscreen(sdl_window, ((fs & 1) ? windowedMode ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN : windowedMode));
SDL_SetWindowFullscreen(sdl_window, ((fs & 1) ? (matchedResolution ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN) : 0));
SDL_GL_SetSwapInterval(vsync_renderlayer);
setrefreshrate();
@ -1666,7 +1668,7 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
// init
sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED,
windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED, x, y,
0);
borderless);
if (!sdl_window)
SDL2_VIDEO_ERR("SDL_CreateWindow");
@ -1679,7 +1681,7 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
SDL2_VIDEO_ERR("SDL_GetWindowSurface");
}
SDL_SetWindowFullscreen(sdl_window, ((fs & 1) ? SDL_WINDOW_FULLSCREEN : windowedMode));
SDL_SetWindowFullscreen(sdl_window, ((fs & 1) ? (matchedResolution ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN) : 0));
}
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");