Cleaned up the SDL_VIDEO_WINDOW_POS variable support
authorSam Lantinga <slouken@libsdl.org>
Mon, 16 Sep 2002 08:22:25 +0000
changeset 497bb2d68294e81
parent 496 864a66f028d8
child 498 4b8ff8ac2c07
Cleaned up the SDL_VIDEO_WINDOW_POS variable support
src/video/x11/SDL_x11video.c
     1.1 --- a/src/video/x11/SDL_x11video.c	Mon Sep 16 07:09:04 2002 +0000
     1.2 +++ b/src/video/x11/SDL_x11video.c	Mon Sep 16 08:22:25 2002 +0000
     1.3 @@ -513,6 +513,26 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 +static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h)
     1.8 +{
     1.9 +	const char *window = getenv("SDL_VIDEO_WINDOW_POS");
    1.10 +	const char *center = getenv("SDL_VIDEO_CENTERED");
    1.11 +	if ( window ) {
    1.12 +		if ( sscanf(window, "%d,%d", x, y) == 2 ) {
    1.13 +			return SDL_TRUE;
    1.14 +		}
    1.15 +		if ( strcmp(window, "center") == 0 ) {
    1.16 +			center = window;
    1.17 +		}
    1.18 +	}
    1.19 +	if ( center ) {
    1.20 +		*x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2;
    1.21 +		*y = (DisplayHeight(SDL_Display, SDL_Screen) - h)/2;
    1.22 +		return SDL_TRUE;
    1.23 +	}
    1.24 +	return SDL_FALSE;
    1.25 +}
    1.26 +
    1.27  static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags)
    1.28  {
    1.29  	XSizeHints *hints;
    1.30 @@ -535,13 +555,7 @@
    1.31  			hints->flags |= USPosition;
    1.32  		} else
    1.33  		/* Center it, if desired */
    1.34 -		if ( getenv("SDL_VIDEO_CENTERED") ) {
    1.35 -			int display_w, display_h;
    1.36 -
    1.37 -			display_w = DisplayWidth(SDL_Display, SDL_Screen);
    1.38 -			display_h = DisplayHeight(SDL_Display, SDL_Screen);
    1.39 -			hints->x = (display_w - w)/2;
    1.40 -			hints->y = (display_h - h)/2;
    1.41 +		if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
    1.42  			hints->flags |= USPosition;
    1.43  			XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
    1.44  
    1.45 @@ -870,18 +884,6 @@
    1.46  			screen->flags |= SDL_FULLSCREEN;
    1.47  			X11_EnterFullScreen(this);
    1.48  		} else {
    1.49 -			/* Position standalone window based on user request. --ryan. */
    1.50 -			const char *envr = getenv("SDL_WINDOW_POS");
    1.51 -			if (envr != NULL) {
    1.52 -				int xscreen = DefaultScreen(SDL_Display);
    1.53 -				if (strcmp(envr, "center") == 0) {
    1.54 -					int disw = DisplayWidth(SDL_Display, xscreen);
    1.55 -					int dish = DisplayHeight(SDL_Display, xscreen);
    1.56 -					int centerx = (disw - current_w) / 2;
    1.57 -					int centery = (dish - current_h) / 2;
    1.58 -					XMoveWindow(SDL_Display, WMwindow, centerx, centery);
    1.59 -				}
    1.60 -			}
    1.61  			screen->flags &= ~SDL_FULLSCREEN;
    1.62  		}
    1.63  	}