ref: 2f26be8a383693a92fe4f47e599c47f63920b9d6
parent: 15b87abac461e37afc89cde202d6b988487f9ee5
parent: 4f9b811f7b1172ea68df93b02223b7ce373c9f14
author: Jonathan Dowland <jon+github@alcopop.org>
date: Mon Jul 4 17:41:52 EDT 2016
Merge pull request #738 from jmtd/sdl2-fix-window-position sdl2: fix window_position config option
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -978,24 +978,24 @@
}
}
-static void SetWindowPositionVars(void)
+static void GetWindowPosition(int *x, int *y)
{
- char buf[64];
- int x, y;
+ // in windowed mode, the desired window position can be specified
+ // in the configuration file.
if (window_position == NULL || !strcmp(window_position, ""))
{
- return;
+ *x = *y = SDL_WINDOWPOS_UNDEFINED;
}
-
- if (!strcmp(window_position, "center"))
+ else if (!strcmp(window_position, "center"))
{
- putenv("SDL_VIDEO_CENTERED=1");
+ *x = *y = SDL_WINDOWPOS_CENTERED;
}
- else if (sscanf(window_position, "%i,%i", &x, &y) == 2)
+ else if (sscanf(window_position, "%i,%i", x, y) != 2)
{
- M_snprintf(buf, sizeof(buf), "SDL_VIDEO_WINDOW_POS=%i,%i", x, y);
- putenv(buf);
+ // invalid format: revert to default
+ fprintf(stderr, "GetWindowPosition: invalid window_position setting\n");
+ *x = *y = SDL_WINDOWPOS_UNDEFINED;
}
}
@@ -1003,6 +1003,7 @@
{
byte *doompal;
int w, h;
+ int x, y;
int flags = 0;
doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE);
@@ -1027,6 +1028,8 @@
w = window_width;
h = window_height;
+ GetWindowPosition(&x, &y);
+
// In windowed mode, the window can be resized while the game is
// running.
flags = SDL_WINDOW_RESIZABLE;
@@ -1055,9 +1058,7 @@
// later anyway and leave the window position "undefined". If "flags"
// contains the fullscreen flag (see above), then w and h are ignored.
- screen = SDL_CreateWindow(NULL,
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
- w, h, flags);
+ screen = SDL_CreateWindow(NULL, x, y, w, h, flags);
if (screen == NULL)
{
@@ -1151,7 +1152,6 @@
}
SetSDLVideoDriver();
- SetWindowPositionVars();
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{