annotate src/video/wincommon/SDL_lowvideo.h @ 1287:15a89a0c52bf

Date: Tue, 15 Feb 2005 21:28:48 +0900 (JST) From: "Michael Leonhard" Subject: [SDL] resize bug on Win32 and patch This is my first post to this mailing list. In this email I will detail a bug in the behavior of resizable SDL windows on Win32. Then I will explain the solution and provide a patch. Symptoms: Under Windows, an SDL display created with the SDL_RESIZABLE flag exhibits quirky behavior when being maximized. The window is resized to the proper size, but it is shifted upwards about half the height of the title bar. Similarly, a window whose origin is above the top of the screen will spontaneously move its upper-left origin upon being resized. After two such resize-induced moves, the title bar will be entirely off the top edge of the screen. Subsequently, when the mouse is clicked and released on the window border, the window will shrink its height spontaneously. This height shrinkage occurs even if the user did not resize the border. To observe this curious situation, please invoke: SDL-1.2.8/test/testwm.exe -resize Cause: A pair of integers, SDL_windowX and SDL_windowY, are defined in video/wincommon/SDL_sysevents.c. They are used by the DirectX video driver and the DIB video driver: video/windx5/SDL_dx5video.c video/windib/SDL_dibvideo.c As I understand the source code, the primary use of these variables is to create a rectangle that represents the surface area in CLIENT SPACE. Client space refers to a coordinate system that originates at the upper left corner of a Win32 Window's drawable area. This is just inside the window border and title bar. This client space rectangle, called bounds, is subsequently converted to screen space with a call to AdjustWindowRectEx. The problem is found in SDL's handling of the WM_WINDOWPOSCHANGED message. According to MSDN, "The WM_WINDOWPOSCHANGED message is sent to a window whose size, position, or place in the Z order has changed as a result of a call to the SetWindowPos function or another window-management function." I have confirmed that this message is indeed being sent to the SDL window when the mouse is clicked on the window border, even if the window border is not dragged. In video/wincommon/SDL_sysevents.c, on line 464, in response to the WM_WINDOWPOSCHANGED message, the (potentially) new client rectangle is obtained. This rectangle is translated into screen coordinates and THEN assigned to the SDL_windowX and Y variables. Thus screen coordinates are being assigned to client coordinate variables. Once this is understood, the solution is apparent: assign SDL_windowX and Y before translating the rectangle to screen coordinates. This is accomplished by the following patch. -Mike_L
author Sam Lantinga <slouken@libsdl.org>
date Sun, 29 Jan 2006 08:50:06 +0000
parents f61f045343d3
children c3e36ac8a94c
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 453
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 145
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 #ifdef SAVE_RCSID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 static char rcsid =
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 "@(#) $Id$";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #ifndef _SDL_lowvideo_h
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #define _SDL_lowvideo_h
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <windows.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 /* Hidden "this" pointer for the video functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #define _THIS SDL_VideoDevice *this
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
304
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
38 #define WINDIB_FULLSCREEN() \
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
39 ( \
335
bc4d50d2edd9 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 325
diff changeset
40 SDL_VideoSurface && \
304
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
41 ((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
42 (((SDL_VideoSurface->flags & SDL_OPENGL ) == SDL_OPENGL ) || \
1251
86d0d01290ea Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents: 833
diff changeset
43 ((strcmp(this->name, "windib") == 0) || \
86d0d01290ea Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents: 833
diff changeset
44 (strcmp(this->name, "gapi") == 0))) \
304
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
45 )
13
e30a8ce27c22 Fixed double-mouse event bug on Windows using OpenGL
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
46 #define DDRAW_FULLSCREEN() \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 ( \
335
bc4d50d2edd9 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 325
diff changeset
48 SDL_VideoSurface && \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 ((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 ((SDL_VideoSurface->flags & SDL_OPENGL ) != SDL_OPENGL ) && \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 (strcmp(this->name, "directx") == 0) \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53
325
1b5457c0a8ad Fixed the bug where mouse cursor and SDL mouse coordinates didn't match
Sam Lantinga <slouken@libsdl.org>
parents: 304
diff changeset
54 #define DINPUT_FULLSCREEN() DDRAW_FULLSCREEN()
13
e30a8ce27c22 Fixed double-mouse event bug on Windows using OpenGL
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
55
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 /* The main window -- and a function to set it for the audio */
453
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 338
diff changeset
57 #ifdef _WIN32_WCE
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 338
diff changeset
58 extern LPWSTR SDL_Appname;
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 338
diff changeset
59 #else
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 338
diff changeset
60 extern LPSTR SDL_Appname;
a6fa62b1be09 Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents: 338
diff changeset
61 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 extern HINSTANCE SDL_Instance;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 extern HWND SDL_Window;
1280
f61f045343d3 Re-query the SDL_WINDOWID each time we initialize the video
Sam Lantinga <slouken@libsdl.org>
parents: 1253
diff changeset
64 extern BOOL SDL_windowid;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 /* Variables and functions exported to other parts of the native video
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 subsystem (SDL_sysevents.c)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 /* Called by windows message loop when system palette is available */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 extern void (*WIN_RealizePalette)(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 /* Called by windows message loop when the system palette changes */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 extern void (*WIN_PaletteChanged)(_THIS, HWND window);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 /* Called by windows message loop when a portion of the screen needs update */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 extern void (*WIN_WinPAINT)(_THIS, HDC hdc);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 /* Called by windows message loop when the message isn't handled */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 extern LONG (*HandleMessage)(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 /* The window cursor (from SDL_sysmouse.c) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 extern HCURSOR SDL_hcursor;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 /* The bounds of the window in screen coordinates */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 extern RECT SDL_bounds;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86
833
31fa08b36380 Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
87 /* The position of the window in windowed mode */
31fa08b36380 Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
88 extern int SDL_windowX;
31fa08b36380 Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
89 extern int SDL_windowY;
31fa08b36380 Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
90
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 /* Flag -- SDL is performing a resize, rather than the user */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 extern int SDL_resizing;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 /* Flag -- the mouse is in relative motion mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 extern int mouse_relative;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96
304
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
97 /* The GDI fullscreen mode currently active */
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
98 #ifndef NO_CHANGEDISPLAYSETTINGS
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
99 extern DEVMODE SDL_fullscreen_mode;
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
100 #endif
ec53caed9fb2 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
101
338
518ffd98a8f6 Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents: 335
diff changeset
102 /* The system gamma ramp for GDI modes */
518ffd98a8f6 Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents: 335
diff changeset
103 extern WORD *gamma_saved;
518ffd98a8f6 Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents: 335
diff changeset
104
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 /* This is really from SDL_dx5audio.c */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 extern void DX5_SoundFocus(HWND window);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107
145
29a638dc26db Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 13
diff changeset
108 /* DJM: This is really from SDL_sysevents.c, we need it in
29a638dc26db Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 13
diff changeset
109 GDL_CreateWindow as well */
29a638dc26db Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 13
diff changeset
110 LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
29a638dc26db Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 13
diff changeset
111
1253
7c7ddaf195bf Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
112 /* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */
7c7ddaf195bf Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
113 typedef int (WINAPI *ToUnicodeFN)(UINT, UINT, PBYTE, LPWSTR, int, UINT);
7c7ddaf195bf Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
114
7c7ddaf195bf Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
115 extern ToUnicodeFN SDL_ToUnicode;
7c7ddaf195bf Implemented ToUnicode() support on Windows 95/98/ME/NT/2000/XP
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
116
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 #endif /* SDL_lowvideo_h */