Skip to content

Commit

Permalink
Setting the mouse in relative mode implies grabbing the mouse.
Browse files Browse the repository at this point in the history
This fixes getting mouse button events in raw input relative mode on X11.
  • Loading branch information
slouken committed Dec 24, 2013
1 parent 7aef235 commit 2521e49
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 55 deletions.
5 changes: 2 additions & 3 deletions src/video/SDL_video.c
Expand Up @@ -2055,9 +2055,8 @@ SDL_UpdateWindowGrab(SDL_Window * window)
{
if (_this->SetWindowGrab) {
SDL_bool grabbed;
if (SDL_GetMouse()->relative_mode_warp ||
((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS))) {
if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
grabbed = SDL_TRUE;
} else {
grabbed = SDL_FALSE;
Expand Down
41 changes: 0 additions & 41 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -286,47 +286,6 @@ WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
return SDL_TRUE;
}

static void
WIN_UpdateClipCursor(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();

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

if (mouse->relative_mode && !mouse->relative_mode_warp) {
LONG cx, cy;
RECT rect;
GetWindowRect(data->hwnd, &rect);

cx = (rect.left + rect.right) / 2;
cy = (rect.top + rect.bottom) / 2;

/* Make an absurdly small clip rect */
rect.left = cx-1;
rect.right = cx+1;
rect.top = cy-1;
rect.bottom = cy+1;

ClipCursor(&rect);
} else if (mouse->relative_mode_warp ||
((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS))) {
RECT rect;
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
ClientToScreen(data->hwnd, (LPPOINT) & rect);
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
ClipCursor(&rect);
}
} else {
ClipCursor(NULL);
}
}

LRESULT CALLBACK
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Expand Down
55 changes: 44 additions & 11 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -28,6 +28,7 @@
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"

#include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h"
Expand Down Expand Up @@ -571,17 +572,7 @@ WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
void
WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;

if (grabbed) {
RECT rect;
GetClientRect(hwnd, &rect);
ClientToScreen(hwnd, (LPPOINT) & rect);
ClientToScreen(hwnd, (LPPOINT) & rect + 1);
ClipCursor(&rect);
} else {
ClipCursor(NULL);
}
WIN_UpdateClipCursor(window);

if (window->flags & SDL_WINDOW_FULLSCREEN) {
UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
Expand Down Expand Up @@ -722,6 +713,48 @@ void WIN_OnWindowEnter(_THIS, SDL_Window * window)
#endif /* WM_MOUSELEAVE */
}

void
WIN_UpdateClipCursor(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();

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

if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
(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;
cy = (rect.top + rect.bottom) / 2;

/* Make an absurdly small clip rect */
rect.left = cx - 1;
rect.right = cx + 1;
rect.top = cy - 1;
rect.bottom = cy + 1;

ClipCursor(&rect);
} else {
RECT rect;
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
ClientToScreen(data->hwnd, (LPPOINT) & rect);
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
ClipCursor(&rect);
}
}
} else {
ClipCursor(NULL);
}
}

#endif /* SDL_VIDEO_DRIVER_WINDOWS */

/* vi: set ts=4 sw=4 expandtab: */
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowswindow.h
Expand Up @@ -66,6 +66,7 @@ extern void WIN_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
extern void WIN_UpdateClipCursor(SDL_Window *window);

#endif /* _SDL_windowswindow_h */

Expand Down

0 comments on commit 2521e49

Please sign in to comment.