Only reset the clip rect if it's currently the rect we previously clipped. This prevents us from clearing the clip rect globally when another application has set it. There's also an experimental change to regularly update the clip rect for a window defensively, in case someone else has reset it. It works well, but I don't know if it's cheap enough to call as frequently as it would be called now, and might have other undesirable side effects. Also fixed whitespace and SDL coding style
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 801a55b..ae6fee9 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1543,8 +1543,9 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
// Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
// but it's important or window focus will get broken on windows!
#if !defined(__WIN32__)
- if ( window->flags & SDL_WINDOW_MINIMIZED )
+ if (window->flags & SDL_WINDOW_MINIMIZED) {
window->flags &= ~SDL_WINDOW_MINIMIZED;
+ }
#endif
#if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 5b15b92..8dcd151 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -228,9 +228,7 @@ WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePress
/* Ignore the button click for activation */
if (!bwParamMousePressed) {
data->focus_click_pending &= ~SDL_BUTTON(button);
- if (!data->focus_click_pending) {
- WIN_UpdateClipCursor(data->window);
- }
+ WIN_UpdateClipCursor(data->window);
}
if (WIN_ShouldIgnoreFocusClick()) {
return;
@@ -401,6 +399,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
#endif /* WMMSG_DEBUG */
+ /* Update the clipping rect in case someone else has stolen it */
+ /* FIXME: Is this function cheap enough to call this frequently?
+ WIN_UpdateClipCursor(data->window);
+ */
+
if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
return 0;
@@ -465,6 +468,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
} else {
+ RECT rect;
+
data->in_window_deactivation = SDL_TRUE;
if (SDL_GetKeyboardFocus() == data->window) {
@@ -472,7 +477,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
WIN_ResetDeadKeys();
}
- ClipCursor(NULL);
+ if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect) == 0)) {
+SDL_Log("Windows deactivate, ClipCursor(NULL)\n");
+ ClipCursor(NULL);
+ SDL_zero(data->cursor_clipped_rect);
+ }
data->in_window_deactivation = SDL_FALSE;
}
@@ -653,7 +662,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
case WM_UNICHAR:
- if ( wParam == UNICODE_NOCHAR ) {
+ if (wParam == UNICODE_NOCHAR) {
returnCode = 1;
break;
}
@@ -661,8 +670,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_CHAR:
{
char text[5];
- if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
- SDL_SendKeyboardText( text );
+ if (WIN_ConvertUTF32toUTF8((UINT32)wParam, text)) {
+ SDL_SendKeyboardText(text);
}
}
returnCode = 0;
@@ -1099,9 +1108,9 @@ IsWin10FCUorNewer(void)
SDL_zero(info);
info.dwOSVersionInfoSize = sizeof(info);
if (getVersionPtr(&info) == 0) { /* STATUS_SUCCESS == 0 */
- if ( (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299)
- || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0)
- || (info.dwMajorVersion > 10) )
+ if ((info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299) ||
+ (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) ||
+ (info.dwMajorVersion > 10))
{
return SDL_TRUE;
}
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 753b736..ba5ef05 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -98,9 +98,10 @@ GetWindowStyle(SDL_Window * window)
style |= STYLE_RESIZABLE;
}
- /* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
- if ( window->flags & SDL_WINDOW_MINIMIZED )
- style |= WS_MINIMIZE;
+ /* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
+ if (window->flags & SDL_WINDOW_MINIMIZED) {
+ style |= WS_MINIMIZE;
+ }
}
return style;
}
@@ -334,8 +335,9 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
/* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
- if ( window->flags & SDL_WINDOW_MINIMIZED )
- ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
+ if (window->flags & SDL_WINDOW_MINIMIZED) {
+ ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
+ }
if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
@@ -409,13 +411,11 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
SDL_sscanf(hint, "%p", (void**)&otherWindow);
/* Do some error checking on the pointer */
- if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
- {
+ if (otherWindow != NULL && otherWindow->magic == &_this->window_magic) {
/* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */
- if (otherWindow->flags & SDL_WINDOW_OPENGL)
- {
+ if (otherWindow->flags & SDL_WINDOW_OPENGL) {
window->flags |= SDL_WINDOW_OPENGL;
- if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
+ if (!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
return -1;
}
}
@@ -548,17 +548,17 @@ WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *b
void
WIN_ShowWindow(_THIS, SDL_Window * window)
{
- DWORD style;
- HWND hwnd;
- int nCmdShow;
-
- hwnd = ( (SDL_WindowData *)window->driverdata )->hwnd;
- nCmdShow = SW_SHOW;
- style = GetWindowLong(hwnd, GWL_EXSTYLE);
- if ( style & WS_EX_NOACTIVATE )
- nCmdShow = SW_SHOWNOACTIVATE;
-
- ShowWindow(hwnd, nCmdShow );
+ DWORD style;
+ HWND hwnd;
+ int nCmdShow;
+
+ hwnd = ((SDL_WindowData *)window->driverdata)->hwnd;
+ nCmdShow = SW_SHOW;
+ style = GetWindowLong(hwnd, GWL_EXSTYLE);
+ if (style & WS_EX_NOACTIVATE) {
+ nCmdShow = SW_SHOWNOACTIVATE;
+ }
+ ShowWindow(hwnd, nCmdShow);
}
void
@@ -902,6 +902,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();
+ RECT rect;
if (data->focus_click_pending) {
return;
@@ -911,7 +912,6 @@ WIN_UpdateClipCursor(SDL_Window *window)
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
if (mouse->relative_mode && !mouse->relative_mode_warp) {
LONG cx, cy;
- RECT rect;
GetWindowRect(data->hwnd, &rect);
cx = (rect.left + rect.right) / 2;
@@ -923,17 +923,21 @@ WIN_UpdateClipCursor(SDL_Window *window)
rect.top = cy - 1;
rect.bottom = cy + 1;
- ClipCursor(&rect);
+ if (ClipCursor(&rect)) {
+ data->cursor_clipped_rect = rect;
+ }
} else {
- RECT rect;
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
ClientToScreen(data->hwnd, (LPPOINT) & rect);
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
- ClipCursor(&rect);
+ if (ClipCursor(&rect)) {
+ data->cursor_clipped_rect = rect;
+ }
}
}
- } else {
+ } else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
ClipCursor(NULL);
+ SDL_zero(data->cursor_clipped_rect);
}
}
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index 0ed8759..0dacff6 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -46,6 +46,7 @@ typedef struct
Uint8 focus_click_pending;
SDL_bool windowed_mode_was_maximized;
SDL_bool in_window_deactivation;
+ RECT cursor_clipped_rect;
struct SDL_VideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;