Setting the mouse in relative mode implies grabbing the mouse. This fixes getting mouse button events in raw input relative mode on X11.
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
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index ff80891..46f8ffc 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -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;
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index a06f11f..103a9bf 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -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)
{
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 990c0cb..8529cea 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -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"
@@ -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;
@@ -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: */
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index ed30445..1cf1145 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -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 */