From d4863007907bcd6ad7b6e05285d6c4557a23fdcf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 16 Sep 2002 08:22:25 +0000 Subject: [PATCH] Cleaned up the SDL_VIDEO_WINDOW_POS variable support --- src/video/x11/SDL_x11video.c | 40 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 6967ee0c2..a257e8cdb 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -513,6 +513,26 @@ static void X11_DestroyWindow(_THIS, SDL_Surface *screen) } } +static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h) +{ + const char *window = getenv("SDL_VIDEO_WINDOW_POS"); + const char *center = getenv("SDL_VIDEO_CENTERED"); + if ( window ) { + if ( sscanf(window, "%d,%d", x, y) == 2 ) { + return SDL_TRUE; + } + if ( strcmp(window, "center") == 0 ) { + center = window; + } + } + if ( center ) { + *x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2; + *y = (DisplayHeight(SDL_Display, SDL_Screen) - h)/2; + return SDL_TRUE; + } + return SDL_FALSE; +} + static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) { XSizeHints *hints; @@ -535,13 +555,7 @@ static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) hints->flags |= USPosition; } else /* Center it, if desired */ - if ( getenv("SDL_VIDEO_CENTERED") ) { - int display_w, display_h; - - display_w = DisplayWidth(SDL_Display, SDL_Screen); - display_h = DisplayHeight(SDL_Display, SDL_Screen); - hints->x = (display_w - w)/2; - hints->y = (display_h - h)/2; + if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) { hints->flags |= USPosition; XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y); @@ -870,18 +884,6 @@ static int X11_CreateWindow(_THIS, SDL_Surface *screen, screen->flags |= SDL_FULLSCREEN; X11_EnterFullScreen(this); } else { - /* Position standalone window based on user request. --ryan. */ - const char *envr = getenv("SDL_WINDOW_POS"); - if (envr != NULL) { - int xscreen = DefaultScreen(SDL_Display); - if (strcmp(envr, "center") == 0) { - int disw = DisplayWidth(SDL_Display, xscreen); - int dish = DisplayHeight(SDL_Display, xscreen); - int centerx = (disw - current_w) / 2; - int centery = (dish - current_h) / 2; - XMoveWindow(SDL_Display, WMwindow, centerx, centery); - } - } screen->flags &= ~SDL_FULLSCREEN; } }