Skip to content

Commit

Permalink
Fixed grab interaction with Windows Classic theme
Browse files Browse the repository at this point in the history
Testing:
* For each theme in Windows 7, Windows 7 Basic, and Windows 7 Classic:
- Ran testsprite2
- Pressed Ctrl-G to grab the mouse
- Alt-tabbed away, verified mouse is no longer grabbed
- Alt-tabbed back, verified that mouse was grabbed
- Alt-tabbed away
- Clicked in the window, verified mouse was grabbed
- Alt-tabbed away
- Grabbed the title bar and dragged the window around successfully, verified that mouse was grabbed when move modal loop completed
- Alt-tabbed away
- Clicked the minimize button on the title bar, the window was successfully minimized
- Clicked on the icon in the task bar, the window was restored and the mouse grabbed again
- Alt-tabbed away
- Clicked the close button on the title bar, the window was successfully closed
  • Loading branch information
slouken committed Jun 23, 2014
1 parent 9e2a263 commit 67e5565
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
30 changes: 9 additions & 21 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -196,6 +196,11 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
void void
WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button) WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button)
{ {
if (data->focus_click_pending && button == SDL_BUTTON_LEFT && !bwParamMousePressed) {
data->focus_click_pending = SDL_FALSE;
WIN_UpdateClipCursor(data->window);
}

if (bwParamMousePressed && !bSDLMousePressed) { if (bwParamMousePressed && !bSDLMousePressed) {
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button); SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
} else if (!bwParamMousePressed && bSDLMousePressed) { } else if (!bwParamMousePressed && bSDLMousePressed) {
Expand Down Expand Up @@ -371,11 +376,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)


minimized = HIWORD(wParam); minimized = HIWORD(wParam);
if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
data->focus_click_pending = (GetAsyncKeyState(VK_LBUTTON) != 0);

SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
if (SDL_GetKeyboardFocus() != data->window) { if (SDL_GetKeyboardFocus() != data->window) {
SDL_SetKeyboardFocus(data->window); SDL_SetKeyboardFocus(data->window);
} }
WIN_UpdateClipCursor(data->window);


GetCursorPos(&cursorPos); GetCursorPos(&cursorPos);
ScreenToClient(hwnd, &cursorPos); ScreenToClient(hwnd, &cursorPos);
Expand Down Expand Up @@ -584,32 +590,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_NCLBUTTONDOWN: case WM_NCLBUTTONDOWN:
{ {
data->in_title_click = SDL_TRUE; data->in_title_click = SDL_TRUE;
WIN_UpdateClipCursor(data->window);
} }
break; break;


case WM_NCMOUSELEAVE: case WM_CAPTURECHANGED:
{ {
data->in_title_click = SDL_FALSE; data->in_title_click = SDL_FALSE;
WIN_UpdateClipCursor(data->window);
}
break;

case WM_ENTERSIZEMOVE:
case WM_ENTERMENULOOP:
{
data->in_modal_loop = SDL_TRUE;
WIN_UpdateClipCursor(data->window);
}
break;

case WM_EXITSIZEMOVE:
case WM_EXITMENULOOP:
{
data->in_modal_loop = SDL_FALSE;
WIN_UpdateClipCursor(data->window);


/* The mouse may have been released during the modal loop */ /* The mouse may have been released during a modal loop */
WIN_CheckAsyncMouseRelease(data); WIN_CheckAsyncMouseRelease(data);
} }
break; break;
Expand Down
2 changes: 1 addition & 1 deletion src/video/windows/SDL_windowsmouse.c
Expand Up @@ -188,7 +188,7 @@ WIN_WarpMouse(SDL_Window * window, int x, int y)
POINT pt; POINT pt;


/* Don't warp the mouse while we're doing a modal interaction */ /* Don't warp the mouse while we're doing a modal interaction */
if (data->in_title_click || data->in_modal_loop) { if (data->in_title_click || data->focus_click_pending) {
return; return;
} }


Expand Down
4 changes: 1 addition & 3 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -751,9 +751,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();


/* Don't clip the cursor while we're in the modal resize or move loop */ if (data->focus_click_pending) {
if (data->in_title_click || data->in_modal_loop) {
ClipCursor(NULL);
return; return;
} }


Expand Down
2 changes: 1 addition & 1 deletion src/video/windows/SDL_windowswindow.h
Expand Up @@ -40,7 +40,7 @@ typedef struct
SDL_bool expected_resize; SDL_bool expected_resize;
SDL_bool in_border_change; SDL_bool in_border_change;
SDL_bool in_title_click; SDL_bool in_title_click;
SDL_bool in_modal_loop; SDL_bool focus_click_pending;
struct SDL_VideoData *videodata; struct SDL_VideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface; EGLSurface egl_surface;
Expand Down

0 comments on commit 67e5565

Please sign in to comment.