Commit ecb604e3 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: slightly improve window position handling to help weird edge cases...

engine: slightly improve window position handling to help weird edge cases where the window manager places the window at -1
parent c729f7bd
......@@ -38,7 +38,6 @@ extern int32_t vsync;
extern int32_t r_finishbeforeswap;
extern int32_t r_glfinish;
extern int32_t r_borderless;
extern int32_t r_windowpositioning;
extern int32_t r_displayindex;
extern void app_crashhandler(void);
......
......@@ -981,7 +981,9 @@ typedef struct { int16_t newtile; int16_t owner; } rottile_t;
EXTERN rottile_t rottile[MAXTILES];
EXTERN intptr_t waloff[MAXTILES]; // stores pointers to cache -- SA
EXTERN int32_t windowx, windowy;
EXTERN vec2_t g_windowPos;
EXTERN bool g_windowPosValid;
//These variables are for auto-mapping with the draw2dscreen function.
//When you load a new board, these bits are all set to 0 - since
......
......@@ -821,7 +821,6 @@ int32_t baselayer_init(void)
#ifdef YAX_ENABLE
{ "r_tror_nomaskpass", "enable/disable additional pass in TROR software rendering", (void *)&r_tror_nomaskpass, CVAR_BOOL, 0, 1 },
#endif
{ "r_windowpositioning", "enable/disable window position memory", (void *) &r_windowpositioning, CVAR_BOOL, 0, 1 },
{ "vid_gamma","adjusts gamma component of gamma ramp",(void *) &g_videoGamma, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
{ "vid_contrast","adjusts contrast component of gamma ramp",(void *) &g_videoContrast, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
{ "vid_brightness","adjusts brightness component of gamma ramp",(void *) &g_videoBrightness, CVAR_FLOAT|CVAR_FUNCPTR, -10, 10 },
......
......@@ -172,12 +172,17 @@ int32_t loadsetup(const char *fn)
// if (readconfig(fp, "keychat", val, VL) > 0) keys[BK_MESSAGE] = Bstrtol(val, NULL, 16);
#endif
if (readconfig(fp, "windowpositioning", val, VL) > 0) r_windowpositioning = atoi_safe(val);
windowx = -1;
if (readconfig(fp, "windowposx", val, VL) > 0) windowx = atoi_safe(val);
windowy = -1;
if (readconfig(fp, "windowposy", val, VL) > 0) windowy = atoi_safe(val);
if (readconfig(fp, "windowposx", val, VL) > 0)
{
int32_t x = atoi_safe(val);
if (readconfig(fp, "windowposy", val, VL) > 0)
{
g_windowPos = { x, atoi_safe(val) };
g_windowPosValid = true;
}
}
if (readconfig(fp, "keyconsole", val, VL) > 0)
{
keys[BK_CONSOLE] = Bstrtol(val, NULL, 16);
......@@ -430,8 +435,7 @@ int32_t writesetup(const char *fn)
"maxrefreshfreq = %d\n"
"\n"
#endif
"; Window positioning, 0 = center, 1 = memory\n"
"windowpositioning = %d\n"
"; Window position\n"
"windowposx = %d\n"
"windowposy = %d\n"
"\n"
......@@ -637,7 +641,7 @@ int32_t writesetup(const char *fn)
#else
maxrefreshfreq,
#endif
r_windowpositioning, windowx, windowy,
g_windowPos.x, g_windowPos.y,
vid_gamma_3d>=0?vid_gamma_3d:g_videoGamma,
vid_brightness_3d>=0?vid_brightness_3d:g_videoBrightness,
vid_contrast_3d>=0?vid_contrast_3d:g_videoContrast,
......
......@@ -1246,7 +1246,7 @@ void mouseUninit(void)
static void SetWindowGrab(SDL_Window *pWindow, int const clipToWindow)
{
UNREFERENCED_PARAMETER(pWindow);
RECT rect { windowx, windowy, windowx + xdim, windowy + ydim };
RECT rect { g_windowPos.x, g_windowPos.y, g_windowPos.x + xdim, g_windowPos.y + ydim };
ClipCursor(clipToWindow ? &rect : nullptr);
}
#define SDL_SetWindowGrab SetWindowGrab
......@@ -1667,7 +1667,7 @@ void setvideomode_sdlcommonpost(int32_t x, int32_t y, int32_t c, int32_t fs, int
int const newdisplayindex = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : displayindex;
if (displayindex != newdisplayindex)
windowx = windowy = -1;
g_windowPosValid = false;
SDL_DisplayMode desktopmode;
SDL_GetDesktopDisplayMode(newdisplayindex, &desktopmode);
......@@ -1709,8 +1709,8 @@ void setvideomode_sdlcommonpost(int32_t x, int32_t y, int32_t c, int32_t fs, int
{
SDL_SetWindowFullscreen(sdl_window, 0);
SDL_SetWindowBordered(sdl_window, borderless ? SDL_FALSE : SDL_TRUE);
SDL_SetWindowPosition(sdl_window, (r_windowpositioning && windowx != -1) ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(newdisplayindex),
(r_windowpositioning && windowy != -1) ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(newdisplayindex));
SDL_SetWindowPosition(sdl_window, g_windowPosValid ? g_windowPos.x : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(newdisplayindex),
g_windowPosValid ? g_windowPos.y : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(newdisplayindex));
}
SDL_FlushEvent(SDL_WINDOWEVENT);
......@@ -1794,8 +1794,8 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
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("", r_windowpositioning && windowx != -1 ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
r_windowpositioning && windowy != -1 ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
sdl_window = SDL_CreateWindow("", g_windowPosValid ? g_windowPos.x : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
g_windowPosValid ? g_windowPos.y : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | borderless);
if (sdl_window)
......@@ -1827,8 +1827,8 @@ int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
#endif // defined USE_OPENGL
{
// init
sdl_window = SDL_CreateWindow("", r_windowpositioning && windowx != -1 ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
r_windowpositioning && windowy != -1 ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
sdl_window = SDL_CreateWindow("", g_windowPosValid ? g_windowPos.x : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
g_windowPosValid ? g_windowPos.y : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
SDL_WINDOW_RESIZABLE | borderless);
if (!sdl_window)
SDL2_VIDEO_ERR("SDL_CreateWindow");
......@@ -2628,8 +2628,9 @@ int32_t handleevents_pollsdl(void)
case SDL_WINDOWEVENT_MOVED:
{
if (fullscreen) break;
windowx = ev.window.data1;
windowy = ev.window.data2;
g_windowPos.x = ev.window.data1;
g_windowPos.y = ev.window.data2;
g_windowPosValid = true;
r_displayindex = SDL_GetWindowDisplayIndex(sdl_window);
modeschecked = 0;
......
......@@ -426,7 +426,7 @@ dwm:
if (activeAdapter.hDc == nullptr)
{
LOG_F(ERROR, "null device context for display: %s windowx: %d windowy: %d.", mi.szDevice, windowx, windowy);
LOG_F(ERROR, "null device context for display: %s windowx: %d windowy: %d.", mi.szDevice, g_windowPos.x, g_windowPos.y);
useDWMsync = 1;
goto dwm;
}
......
......@@ -2790,18 +2790,19 @@ static BOOL CreateAppWindow(int32_t modenum)
h=height;
}
if (windowx == -1)
windowx = x;
if (windowy == -1)
windowy = y;
if (!g_windowPosValid)
{
g_windowPos.x = x;
g_windowPos.y = y;
g_windowPosValid = true;
}
SetWindowText(hWindow, apptitle);
ShowWindow(hWindow, SW_SHOWNORMAL);
SetForegroundWindow(hWindow);
SetFocus(hWindow);
SetWindowPos(hWindow, HWND_TOP, r_windowpositioning && windowx != -1?windowx:x, r_windowpositioning && windowy != -1?windowy:y, w, h, 0);
SetWindowPos(hWindow, HWND_TOP, g_windowPos.x, g_windowPos.y, w, h, 0);
// fullscreen?
if (!fs)
......@@ -3327,16 +3328,17 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
return TRUE;
case WM_MOVE:
// windowx = LOWORD(lParam);
// windowy = HIWORD(lParam);
// g_windowPos.x = LOWORD(lParam);
// g_windowPos.y = HIWORD(lParam);
return 0;
case WM_MOVING:
{
RECT *RECTYMcRECT = (LPRECT)lParam;
windowx = RECTYMcRECT->left;
windowy = RECTYMcRECT->top;
g_windowPos.x = RECTYMcRECT->left;
g_windowPos.y = RECTYMcRECT->top;
g_windowPosValid = true;
return 0;
}
case WM_CLOSE:
......
......@@ -774,20 +774,21 @@ int CONFIG_ReadSetup(void)
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out", &ud.lockout);
SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "Password", &ud.pwlockout[0]);
}
windowx = -1;
windowy = -1;
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", "ScreenDisplay", &r_displayindex);
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", "ScreenWidth", &ud.setup.xdim);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&r_windowpositioning);
vec2_t windowPos;
if (!SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", &windowPos.x)
&& !SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", &windowPos.y))
{
g_windowPos = windowPos;
g_windowPosValid = true;
}
if (ud.setup.bpp < 8) ud.setup.bpp = 32;
#ifdef POLYMER
......@@ -938,9 +939,12 @@ void CONFIG_WriteSetup(uint32_t flags)
}
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", r_windowpositioning, FALSE, FALSE);
if (g_windowPosValid)
{
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", g_windowPos.x, FALSE, FALSE);
SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", g_windowPos.y, FALSE, FALSE);
}
if (!NAM_WW2GI)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment