mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-03-06 17:41:01 +00:00
Several fixes in detection of the window position.
In SDL 2 the first display was 0 and the error code -1. In SDL 3 this changed to 1 as the first display and 0 for the error code. While at it implement error handling and fallbacks for all cases.
This commit is contained in:
parent
8a2336a375
commit
bcbeb81198
1 changed files with 55 additions and 26 deletions
|
@ -39,12 +39,7 @@
|
||||||
#include "../../common/header/common.h"
|
#include "../../common/header/common.h"
|
||||||
#include "header/ref.h"
|
#include "header/ref.h"
|
||||||
|
|
||||||
#ifdef USE_SDL3
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#else
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_video.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int glimp_refreshRate = -1;
|
int glimp_refreshRate = -1;
|
||||||
|
|
||||||
|
@ -134,8 +129,14 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
/* save current display as default */
|
/* save current display as default */
|
||||||
last_display = SDL_GetDisplayForWindow(window);
|
if ((last_display = SDL_GetDisplayForWindow(window)) == 0)
|
||||||
SDL_GetWindowPosition(window, &last_position_x, &last_position_y);
|
{
|
||||||
|
/* There are some obscure setups were SDL is
|
||||||
|
unable to get the current display,one X11
|
||||||
|
server with several screen is one of these,
|
||||||
|
so add a fallback to the first display. */
|
||||||
|
last_display = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set requested fullscreen mode. */
|
/* Set requested fullscreen mode. */
|
||||||
if (flags & SDL_WINDOW_FULLSCREEN)
|
if (flags & SDL_WINDOW_FULLSCREEN)
|
||||||
|
@ -827,15 +828,36 @@ GLimp_GetRefreshRate(void)
|
||||||
if (glimp_refreshRate == -1)
|
if (glimp_refreshRate == -1)
|
||||||
{
|
{
|
||||||
const SDL_DisplayMode *mode;
|
const SDL_DisplayMode *mode;
|
||||||
int i = SDL_GetDisplayForWindow(window);
|
int curdisplay;
|
||||||
|
|
||||||
if (i >= 0)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
if ((mode = SDL_GetCurrentDisplayMode(i)) != NULL)
|
/* This is paranoia. This function should only be
|
||||||
|
called if there is a working window. Otherwise
|
||||||
|
things will likely break somewhere else in the
|
||||||
|
client. */
|
||||||
|
curdisplay = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((curdisplay = SDL_GetDisplayForWindow(window)) == 0)
|
||||||
{
|
{
|
||||||
glimp_refreshRate = mode->refresh_rate;
|
/* There are some obscure setups were SDL is
|
||||||
SDL_free((void *)mode);
|
unable to get the current display,one X11
|
||||||
|
server with several screen is one of these,
|
||||||
|
so add a fallback to the first display. */
|
||||||
|
curdisplay = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mode = SDL_GetCurrentDisplayMode(curdisplay)) == NULL)
|
||||||
|
{
|
||||||
|
printf("Couldn't get display refresh rate: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glimp_refreshRate = mode->refresh_rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -848,34 +870,41 @@ GLimp_GetRefreshRate(void)
|
||||||
qboolean
|
qboolean
|
||||||
GLimp_GetDesktopMode(int *pwidth, int *pheight)
|
GLimp_GetDesktopMode(int *pwidth, int *pheight)
|
||||||
{
|
{
|
||||||
if (window)
|
if (window == NULL)
|
||||||
|
{
|
||||||
|
/* Renderers call into this function before the
|
||||||
|
window is created. This could be refactored
|
||||||
|
by passing the mode and not the geometry from
|
||||||
|
the renderer to GLimp_InitGraphics(), however
|
||||||
|
that would break the renderer API. */
|
||||||
|
last_display = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
/* save current display as default */
|
/* save current display as default */
|
||||||
last_display = SDL_GetDisplayForWindow(window);
|
if ((last_display = SDL_GetDisplayForWindow(window)) == 0)
|
||||||
|
{
|
||||||
|
/* There are some obscure setups were SDL is
|
||||||
|
unable to get the current display,one X11
|
||||||
|
server with several screen is one of these,
|
||||||
|
so add a fallback to the first display. */
|
||||||
|
last_display = 1;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_GetWindowPosition(window, &last_position_x, &last_position_y);
|
SDL_GetWindowPosition(window, &last_position_x, &last_position_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last_display < 0)
|
|
||||||
{
|
|
||||||
// In case of error...
|
|
||||||
Com_Printf("Can't detect current desktop.\n");
|
|
||||||
last_display = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We can't get desktop where we start, so use first desktop
|
|
||||||
const SDL_DisplayMode *mode;
|
const SDL_DisplayMode *mode;
|
||||||
|
|
||||||
if ((mode = SDL_GetCurrentDisplayMode(last_display)) == NULL)
|
if ((mode = SDL_GetCurrentDisplayMode(last_display)) == NULL)
|
||||||
{
|
{
|
||||||
// In case of error...
|
Com_Printf("Couldn't detect default desktop mode: %s\n", SDL_GetError());
|
||||||
Com_Printf("Can't detect default desktop mode: %s\n", SDL_GetError());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pwidth = mode->w;
|
*pwidth = mode->w;
|
||||||
*pheight = mode->h;
|
*pheight = mode->h;
|
||||||
|
|
||||||
SDL_free((void *) mode);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue