The event code was fine, and calculated the SDL_windowX/Y correctly.
authorSam Lantinga <slouken@libsdl.org>
Sun, 29 Jan 2006 18:17:35 +0000
changeset 1290c4a5a772c5d9
parent 1289 c07c6ef7c93e
child 1291 31331c444ea2
The event code was fine, and calculated the SDL_windowX/Y correctly.
What we really needed to do was avoid doing client rect adjustment on
zoomed windows. :)
src/video/wincommon/SDL_sysevents.c
src/video/windib/SDL_dibvideo.c
src/video/windx5/SDL_dx5video.c
     1.1 --- a/src/video/wincommon/SDL_sysevents.c	Sun Jan 29 09:19:55 2006 +0000
     1.2 +++ b/src/video/wincommon/SDL_sysevents.c	Sun Jan 29 18:17:35 2006 +0000
     1.3 @@ -566,13 +566,13 @@
     1.4  			int w, h;
     1.5  
     1.6  			GetClientRect(SDL_Window, &SDL_bounds);
     1.7 +			ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds);
     1.8 +			ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds+1);
     1.9  			SDL_windowX = SDL_bounds.left;
    1.10  			SDL_windowY = SDL_bounds.top;
    1.11  			w = SDL_bounds.right-SDL_bounds.left;
    1.12  			h = SDL_bounds.bottom-SDL_bounds.top;
    1.13  			if ( this->input_grab != SDL_GRAB_OFF ) {
    1.14 -				ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds);
    1.15 -				ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds+1);
    1.16  				ClipCursor(&SDL_bounds);
    1.17  			}
    1.18  			if ( SDL_PublicSurface && 
     2.1 --- a/src/video/windib/SDL_dibvideo.c	Sun Jan 29 09:19:55 2006 +0000
     2.2 +++ b/src/video/windib/SDL_dibvideo.c	Sun Jan 29 18:17:35 2006 +0000
     2.3 @@ -665,13 +665,15 @@
     2.4  	}
     2.5  
     2.6  	/* Resize the window */
     2.7 -	if ( !SDL_windowid ) {
     2.8 +	if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
     2.9  		HWND top;
    2.10  		UINT swp_flags;
    2.11 -		const char *window = getenv("SDL_VIDEO_WINDOW_POS");
    2.12 -		const char *center = getenv("SDL_VIDEO_CENTERED");
    2.13 +		const char *window = NULL;
    2.14 +		const char *center = NULL;
    2.15  
    2.16  		if ( !SDL_windowX && !SDL_windowY ) {
    2.17 +			window = getenv("SDL_VIDEO_WINDOW_POS");
    2.18 +			center = getenv("SDL_VIDEO_CENTERED");
    2.19  			if ( window ) {
    2.20  				if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
    2.21  					SDL_windowX = x;
    2.22 @@ -679,7 +681,6 @@
    2.23  				}
    2.24  				if ( strcmp(window, "center") == 0 ) {
    2.25  					center = window;
    2.26 -					window = NULL;
    2.27  				}
    2.28  			}
    2.29  		}
    2.30 @@ -706,9 +707,6 @@
    2.31  			x = y = -1;
    2.32  			swp_flags |= SWP_NOMOVE;
    2.33  		}
    2.34 -		if ( y < 0 ) { /* Cover up title bar for more client area */
    2.35 -			y -= GetSystemMetrics(SM_CYCAPTION)/2;
    2.36 -		}
    2.37  		if ( flags & SDL_FULLSCREEN ) {
    2.38  			top = HWND_TOPMOST;
    2.39  		} else {
     3.1 --- a/src/video/windx5/SDL_dx5video.c	Sun Jan 29 09:19:55 2006 +0000
     3.2 +++ b/src/video/windx5/SDL_dx5video.c	Sun Jan 29 18:17:35 2006 +0000
     3.3 @@ -1003,7 +1003,6 @@
     3.4  			(WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);
     3.5  	const DWORD resizestyle =
     3.6  			(WS_THICKFRAME|WS_MAXIMIZEBOX);
     3.7 -	int windowX, windowY;
     3.8  	DDSURFACEDESC ddsd;
     3.9  	LPDIRECTDRAWSURFACE  dd_surface1;
    3.10  	LPDIRECTDRAWSURFACE3 dd_surface3;
    3.11 @@ -1036,8 +1035,6 @@
    3.12  
    3.13  	/* If we are setting a GL mode, use GDI, not DirectX (yuck) */
    3.14  	if ( flags & SDL_OPENGL ) {
    3.15 -		RECT bounds;
    3.16 -		int x, y;
    3.17  		Uint32 Rmask, Gmask, Bmask;
    3.18  
    3.19  		/* Recalculate the bitmasks if necessary */
    3.20 @@ -1137,13 +1134,17 @@
    3.21  			SetWindowLong(SDL_Window, GWL_STYLE, style);
    3.22  
    3.23  		/* Resize the window (copied from SDL WinDIB driver) */
    3.24 -		if ( !SDL_windowid ) {
    3.25 +		if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
    3.26 +			RECT bounds;
    3.27 +			int x, y;
    3.28  			HWND top;
    3.29  			UINT swp_flags;
    3.30 -			const char *window = getenv("SDL_VIDEO_WINDOW_POS");
    3.31 -			const char *center = getenv("SDL_VIDEO_CENTERED");
    3.32 +			const char *window = NULL;
    3.33 +			const char *center = NULL;
    3.34  
    3.35  			if ( !SDL_windowX && !SDL_windowY ) {
    3.36 +				window = getenv("SDL_VIDEO_WINDOW_POS");
    3.37 +				center = getenv("SDL_VIDEO_CENTERED");
    3.38  				if ( window ) {
    3.39  					if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
    3.40  						SDL_windowX = x;
    3.41 @@ -1151,7 +1152,6 @@
    3.42  					}
    3.43  					if ( strcmp(window, "center") == 0 ) {
    3.44  						center = window;
    3.45 -						window = NULL;
    3.46  					}
    3.47  				}
    3.48  			}
    3.49 @@ -1178,9 +1178,6 @@
    3.50  				x = y = -1;
    3.51  				swp_flags |= SWP_NOMOVE;
    3.52  			}
    3.53 -			if ( y < 0 ) { /* Cover up title bar for more client area */
    3.54 -				y -= GetSystemMetrics(SM_CYCAPTION)/2;
    3.55 -			}
    3.56  			if ( flags & SDL_FULLSCREEN ) {
    3.57  				top = HWND_TOPMOST;
    3.58  			} else {
    3.59 @@ -1200,8 +1197,6 @@
    3.60  	}
    3.61  
    3.62  	/* Set the appropriate window style */
    3.63 -	windowX = SDL_windowX;
    3.64 -	windowY = SDL_windowY;
    3.65  	style = GetWindowLong(SDL_Window, GWL_STYLE);
    3.66  	style &= ~(resizestyle|WS_MAXIMIZE);
    3.67  	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
    3.68 @@ -1237,8 +1232,6 @@
    3.69  		SetDDerror("DirectDraw2::SetCooperativeLevel", result);
    3.70  		return(NULL);
    3.71  	}
    3.72 -	SDL_windowX = windowX;
    3.73 -	SDL_windowY = windowY;
    3.74  
    3.75  	/* Set the display mode, if we are in fullscreen mode */
    3.76  	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
    3.77 @@ -1513,12 +1506,6 @@
    3.78  
    3.79  	/* Make our window the proper size, set the clipper, then show it */
    3.80  	if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
    3.81 -		RECT bounds;
    3.82 -		int  x, y;
    3.83 -		UINT swp_flags;
    3.84 -		const char *window = getenv("SDL_VIDEO_WINDOW_POS");
    3.85 -		const char *center = getenv("SDL_VIDEO_CENTERED");
    3.86 -
    3.87  		/* Create and set a clipper on our primary surface */
    3.88  		if ( SDL_clipper == NULL ) {
    3.89  			result = IDirectDraw2_CreateClipper(ddraw2,
    3.90 @@ -1549,46 +1536,50 @@
    3.91  			return(NULL);
    3.92  		}
    3.93  
    3.94 -		if ( !SDL_windowX && !SDL_windowY ) {
    3.95 -			if ( window ) {
    3.96 -				if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
    3.97 -					SDL_windowX = x;
    3.98 -					SDL_windowY = y;
    3.99 -				}
   3.100 -				if ( strcmp(window, "center") == 0 ) {
   3.101 -					center = window;
   3.102 -					window = NULL;
   3.103 +		/* Resize the window (copied from SDL WinDIB driver) */
   3.104 +		if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
   3.105 +			RECT bounds;
   3.106 +			int  x, y;
   3.107 +			UINT swp_flags;
   3.108 +			const char *window = NULL;
   3.109 +			const char *center = NULL;
   3.110 +
   3.111 +			if ( !SDL_windowX && !SDL_windowY ) {
   3.112 +				window = getenv("SDL_VIDEO_WINDOW_POS");
   3.113 +				center = getenv("SDL_VIDEO_CENTERED");
   3.114 +				if ( window ) {
   3.115 +					if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
   3.116 +						SDL_windowX = x;
   3.117 +						SDL_windowY = y;
   3.118 +					}
   3.119 +					if ( strcmp(window, "center") == 0 ) {
   3.120 +						center = window;
   3.121 +					}
   3.122  				}
   3.123  			}
   3.124 -		}
   3.125 -		swp_flags = SWP_NOCOPYBITS;
   3.126 +			swp_flags = SWP_NOCOPYBITS;
   3.127  
   3.128 -		SDL_resizing = 1;
   3.129 -		bounds.left = SDL_windowX;
   3.130 -		bounds.top = SDL_windowY;
   3.131 -		bounds.right = SDL_windowX+video->w;
   3.132 -		bounds.bottom = SDL_windowY+video->h;
   3.133 -		AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
   3.134 -		width = bounds.right-bounds.left;
   3.135 -		height = bounds.bottom-bounds.top;
   3.136 -		if ( (flags & SDL_FULLSCREEN) ) {
   3.137 -			x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
   3.138 -			y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
   3.139 -		} else if ( center ) {
   3.140 -			x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
   3.141 -			y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
   3.142 -		} else if ( SDL_windowX || SDL_windowY || window ) {
   3.143 -			x = bounds.left;
   3.144 -			y = bounds.top;
   3.145 -		} else {
   3.146 -			x = y = -1;
   3.147 -			swp_flags |= SWP_NOMOVE;
   3.148 +			SDL_resizing = 1;
   3.149 +			bounds.left = SDL_windowX;
   3.150 +			bounds.top = SDL_windowY;
   3.151 +			bounds.right = SDL_windowX+video->w;
   3.152 +			bounds.bottom = SDL_windowY+video->h;
   3.153 +			AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
   3.154 +			width = bounds.right-bounds.left;
   3.155 +			height = bounds.bottom-bounds.top;
   3.156 +			if ( center ) {
   3.157 +				x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
   3.158 +				y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
   3.159 +			} else if ( SDL_windowX || SDL_windowY || window ) {
   3.160 +				x = bounds.left;
   3.161 +				y = bounds.top;
   3.162 +			} else {
   3.163 +				x = y = -1;
   3.164 +				swp_flags |= SWP_NOMOVE;
   3.165 +			}
   3.166 +			SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags);
   3.167 +			SDL_resizing = 0;
   3.168  		}
   3.169 -		if ( y < 0 ) { /* Cover up title bar for more client area */
   3.170 -			y -= GetSystemMetrics(SM_CYCAPTION)/2;
   3.171 -		}
   3.172 -		SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags);
   3.173 -		SDL_resizing = 0;
   3.174  
   3.175  	}
   3.176  	ShowWindow(SDL_Window, SW_SHOW);