Support fullscreening to the correct display in multiple monitor configurations

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

# Conflicts:
#	source/build/include/baselayer.h
#	source/build/src/polymost.cpp
This commit is contained in:
terminx 2019-08-29 20:06:31 +00:00 committed by Christoph Oelckers
parent f868345670
commit d0223fd744
5 changed files with 62 additions and 42 deletions

View file

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

View file

@ -147,7 +147,8 @@ int32_t r_usenewaspect = 1, newaspect_enable=0;
uint32_t r_screenxy = 0; uint32_t r_screenxy = 0;
int32_t r_fpgrouscan = 1; int32_t r_fpgrouscan = 1;
int32_t r_displayindex = 0;
int32_t r_borderless = 2;
int32_t globalflags; int32_t globalflags;
float g_videoGamma = DEFAULT_GAMMA; float g_videoGamma = DEFAULT_GAMMA;

View file

@ -1216,7 +1216,6 @@ void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur)
// //
static int sortmodes(const void *a_, const void *b_) static int sortmodes(const void *a_, const void *b_)
{ {
auto a = (const struct validmode_t *)b_; auto a = (const struct validmode_t *)b_;
auto b = (const struct validmode_t *)a_; auto b = (const struct validmode_t *)a_;
@ -1237,6 +1236,7 @@ void videoGetModes(void)
{ {
int32_t i, maxx = 0, maxy = 0; int32_t i, maxx = 0, maxy = 0;
SDL_DisplayMode dispmode; SDL_DisplayMode dispmode;
int const display = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : 0;
if (modeschecked || novideo) if (modeschecked || novideo)
return; return;
@ -1245,9 +1245,9 @@ void videoGetModes(void)
// initprintf("Detecting video modes:\n"); // initprintf("Detecting video modes:\n");
// do fullscreen modes first // do fullscreen modes first
for (i = 0; i < SDL_GetNumDisplayModes(0); i++) for (i = 0; i < SDL_GetNumDisplayModes(display); i++)
{ {
SDL_GetDisplayMode(0, i, &dispmode); SDL_GetDisplayMode(display, i, &dispmode);
if (!SDL_CHECKMODE(dispmode.w, dispmode.h) || if (!SDL_CHECKMODE(dispmode.w, dispmode.h) ||
(maxrefreshfreq && (dispmode.refresh_rate > maxrefreshfreq))) (maxrefreshfreq && (dispmode.refresh_rate > maxrefreshfreq)))
@ -1271,7 +1271,7 @@ void videoGetModes(void)
// add windowed modes next // add windowed modes next
// SDL sorts display modes largest to smallest, so we can just compare with mode 0 // SDL sorts display modes largest to smallest, so we can just compare with mode 0
// to make sure we aren't adding modes that are larger than the actual screen res // to make sure we aren't adding modes that are larger than the actual screen res
SDL_GetDisplayMode(0, 0, &dispmode); SDL_GetDisplayMode(display, 0, &dispmode);
for (i = 0; g_defaultVideoModes[i].x; i++) for (i = 0; g_defaultVideoModes[i].x; i++)
{ {
@ -1546,13 +1546,15 @@ void setvideomode_sdlcommonpost(int32_t x, int32_t y, int32_t c, int32_t fs, int
#if SDL_MAJOR_VERSION!=1 #if SDL_MAJOR_VERSION!=1
void setrefreshrate(void) void setrefreshrate(void)
{ {
int const display = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : 0;
SDL_DisplayMode dispmode; SDL_DisplayMode dispmode;
SDL_GetCurrentDisplayMode(0, &dispmode); SDL_GetCurrentDisplayMode(display, &dispmode);
dispmode.refresh_rate = maxrefreshfreq; dispmode.refresh_rate = maxrefreshfreq;
SDL_DisplayMode newmode; SDL_DisplayMode newmode;
SDL_GetClosestDisplayMode(0, &dispmode, &newmode); SDL_GetClosestDisplayMode(display, &dispmode, &newmode);
char error = 0; char error = 0;
@ -1587,11 +1589,13 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
initprintf("Setting video mode %dx%d (%d-bpp %s)\n", x, y, c, ((fs & 1) ? "fullscreen" : "windowed")); initprintf("Setting video mode %dx%d (%d-bpp %s)\n", x, y, c, ((fs & 1) ? "fullscreen" : "windowed"));
int const display = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : 0;
SDL_DisplayMode desktopmode; SDL_DisplayMode desktopmode;
SDL_GetDesktopDisplayMode(0, &desktopmode); SDL_GetDesktopDisplayMode(display, &desktopmode);
int const matchedResolution = (desktopmode.w == x && desktopmode.h == y); int const matchedResolution = (desktopmode.w == x && desktopmode.h == y);
int const borderless = (g_borderless == 1 || (g_borderless == 2 && matchedResolution)) ? SDL_WINDOW_BORDERLESS : 0; int const borderless = (r_borderless == 1 || (r_borderless == 2 && matchedResolution)) ? SDL_WINDOW_BORDERLESS : 0;
#ifdef USE_OPENGL #ifdef USE_OPENGL
if (c > 8 || !nogl) if (c > 8 || !nogl)
{ {
@ -1632,8 +1636,8 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
to force the surface we WANT to be recreated instead of reused. */ to force the surface we WANT to be recreated instead of reused. */
sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED, sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED, x, y, windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
SDL_WINDOW_OPENGL | borderless); SDL_WINDOW_OPENGL | borderless);
if (sdl_window) if (sdl_window)
@ -1666,8 +1670,8 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
#endif // defined USE_OPENGL #endif // defined USE_OPENGL
{ {
// init // init
sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED, sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED, x, y, windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
borderless); borderless);
if (!sdl_window) if (!sdl_window)
SDL2_VIDEO_ERR("SDL_CreateWindow"); SDL2_VIDEO_ERR("SDL_CreateWindow");
@ -2405,12 +2409,18 @@ int32_t handleevents_pollsdl(void)
break; break;
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
{
if (windowpos) if (windowpos)
{ {
windowx = ev.window.data1; windowx = ev.window.data1;
windowy = ev.window.data2; windowy = ev.window.data2;
} }
r_displayindex = SDL_GetWindowDisplayIndex(sdl_window);
modeschecked = 0;
videoGetModes();
break; break;
}
case SDL_WINDOWEVENT_ENTER: case SDL_WINDOWEVENT_ENTER:
g_mouseInsideWindow = 1; g_mouseInsideWindow = 1;
break; break;
@ -2418,6 +2428,7 @@ int32_t handleevents_pollsdl(void)
g_mouseInsideWindow = 0; g_mouseInsideWindow = 0;
break; break;
} }
break; break;
default: default:

View file

@ -867,6 +867,7 @@ int CONFIG_ReadSetup(void)
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", &r_displayindex);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim);
@ -978,6 +979,7 @@ void CONFIG_WriteSetup(uint32_t flags)
#endif #endif
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", r_displayindex, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE);

View file

@ -1919,34 +1919,6 @@ void Menu_Init(void)
} }
M_JOYSTICKAXES.numEntries = joystick.numAxes; M_JOYSTICKAXES.numEntries = joystick.numAxes;
// prepare video setup
for (i = 0; i < validmodecnt; ++i)
{
for (j = 0; j < MEOS_VIDEOSETUP_RESOLUTION.numOptions; ++j)
{
if (validmode[i].xdim == resolution[j].xdim && validmode[i].ydim == resolution[j].ydim)
{
resolution[j].flags |= validmode[i].fs ? RES_FS : RES_WIN;
Bsnprintf(resolution[j].name, MAXRESOLUTIONSTRINGLENGTH, "%d x %d%s", resolution[j].xdim, resolution[j].ydim, (resolution[j].flags & RES_FS) ? "" : "Win");
MEOSN_VIDEOSETUP_RESOLUTION[j] = resolution[j].name;
if (validmode[i].bpp > resolution[j].bppmax)
resolution[j].bppmax = validmode[i].bpp;
break;
}
}
if (j == MEOS_VIDEOSETUP_RESOLUTION.numOptions) // no match found
{
resolution[j].xdim = validmode[i].xdim;
resolution[j].ydim = validmode[i].ydim;
resolution[j].bppmax = validmode[i].bpp;
resolution[j].flags = validmode[i].fs ? RES_FS : RES_WIN;
Bsnprintf(resolution[j].name, MAXRESOLUTIONSTRINGLENGTH, "%d x %d%s", resolution[j].xdim, resolution[j].ydim, (resolution[j].flags & RES_FS) ? "" : "Win");
MEOSN_VIDEOSETUP_RESOLUTION[j] = resolution[j].name;
++MEOS_VIDEOSETUP_RESOLUTION.numOptions;
}
}
// prepare sound setup // prepare sound setup
#ifndef EDUKE32_STANDALONE #ifndef EDUKE32_STANDALONE
if (WW2GI) if (WW2GI)
@ -2120,6 +2092,39 @@ static void Menu_Pre(MenuID_t cm)
case MENU_VIDEOSETUP: case MENU_VIDEOSETUP:
{ {
Bmemset(resolution, 0, sizeof(resolution));
MEOS_VIDEOSETUP_RESOLUTION.numOptions = 0;
// prepare video setup
for (int i = 0; i < validmodecnt; ++i)
{
int j;
for (j = 0; j < MEOS_VIDEOSETUP_RESOLUTION.numOptions; ++j)
{
if (validmode[i].xdim == resolution[j].xdim && validmode[i].ydim == resolution[j].ydim)
{
resolution[j].flags |= validmode[i].fs ? RES_FS : RES_WIN;
Bsnprintf(resolution[j].name, MAXRESOLUTIONSTRINGLENGTH, "%d x %d%s", resolution[j].xdim, resolution[j].ydim, (resolution[j].flags & RES_FS) ? "" : "Win");
MEOSN_VIDEOSETUP_RESOLUTION[j] = resolution[j].name;
if (validmode[i].bpp > resolution[j].bppmax)
resolution[j].bppmax = validmode[i].bpp;
break;
}
}
if (j == MEOS_VIDEOSETUP_RESOLUTION.numOptions) // no match found
{
resolution[j].xdim = validmode[i].xdim;
resolution[j].ydim = validmode[i].ydim;
resolution[j].bppmax = validmode[i].bpp;
resolution[j].flags = validmode[i].fs ? RES_FS : RES_WIN;
Bsnprintf(resolution[j].name, MAXRESOLUTIONSTRINGLENGTH, "%d x %d%s", resolution[j].xdim, resolution[j].ydim, (resolution[j].flags & RES_FS) ? "" : "Win");
MEOSN_VIDEOSETUP_RESOLUTION[j] = resolution[j].name;
++MEOS_VIDEOSETUP_RESOLUTION.numOptions;
}
}
const int32_t nr = newresolution; const int32_t nr = newresolution;
// don't allow setting fullscreen mode if it's not supported by the resolution // don't allow setting fullscreen mode if it's not supported by the resolution