|
@@ -30,6 +30,7 @@
|
|
|
#include "../../events/SDL_events_c.h"
|
|
|
#include "../../events/SDL_touch_c.h"
|
|
|
#include "../../events/scancodes_windows.h"
|
|
|
+#include "SDL_assert.h"
|
|
|
|
|
|
/* Dropfile support */
|
|
|
#include <shellapi.h>
|
|
@@ -428,33 +429,55 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
HRAWINPUT hRawInput = (HRAWINPUT)lParam;
|
|
|
RAWINPUT inp;
|
|
|
UINT size = sizeof(inp);
|
|
|
+ const SDL_bool isRelative = mouse->relative_mode || mouse->relative_mode_warp;
|
|
|
+ const SDL_bool isCapture = ((data->window->flags & SDL_WINDOW_MOUSE_CAPTURE) != 0);
|
|
|
|
|
|
- if (!mouse->relative_mode || mouse->relative_mode_warp || mouse->focus != data->window) {
|
|
|
- break;
|
|
|
+ if (!isRelative || mouse->focus != data->window) {
|
|
|
+ if (!isCapture) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
|
|
|
|
|
|
/* Mouse data */
|
|
|
if (inp.header.dwType == RIM_TYPEMOUSE) {
|
|
|
- RAWMOUSE* mouse = &inp.data.mouse;
|
|
|
+ if (isRelative) {
|
|
|
+ RAWMOUSE* mouse = &inp.data.mouse;
|
|
|
+
|
|
|
+ if ((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) {
|
|
|
+ SDL_SendMouseMotion(data->window, 0, 1, (int)mouse->lLastX, (int)mouse->lLastY);
|
|
|
+ } else {
|
|
|
+ /* synthesize relative moves from the abs position */
|
|
|
+ static SDL_Point initialMousePoint;
|
|
|
+ if (initialMousePoint.x == 0 && initialMousePoint.y == 0) {
|
|
|
+ initialMousePoint.x = mouse->lLastX;
|
|
|
+ initialMousePoint.y = mouse->lLastY;
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
|
|
|
|
|
|
- if ((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) {
|
|
|
- SDL_SendMouseMotion(data->window, 0, 1, (int)mouse->lLastX, (int)mouse->lLastY);
|
|
|
- } else {
|
|
|
- /* synthesize relative moves from the abs position */
|
|
|
- static SDL_Point initialMousePoint;
|
|
|
- if (initialMousePoint.x == 0 && initialMousePoint.y == 0) {
|
|
|
initialMousePoint.x = mouse->lLastX;
|
|
|
initialMousePoint.y = mouse->lLastY;
|
|
|
}
|
|
|
-
|
|
|
- SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
|
|
|
-
|
|
|
- initialMousePoint.x = mouse->lLastX;
|
|
|
- initialMousePoint.y = mouse->lLastY;
|
|
|
+ WIN_CheckRawMouseButtons( mouse->usButtonFlags, data );
|
|
|
+ } else if (isCapture) {
|
|
|
+ /* we check for where Windows thinks the system cursor lives in this case, so we don't really lose mouse accel, etc. */
|
|
|
+ POINT pt;
|
|
|
+ HWND hwnd = data->hwnd;
|
|
|
+ GetCursorPos(&pt);
|
|
|
+ if (WindowFromPoint(pt) != hwnd) { /* if in the window, WM_MOUSEMOVE, etc, will cover it. */
|
|
|
+ ScreenToClient(data->hwnd, &pt);
|
|
|
+ SDL_SendMouseMotion(data->window, 0, 0, (int) pt.x, (int) pt.y);
|
|
|
+ SDL_SendMouseButton(data->window, 0, GetKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT);
|
|
|
+ SDL_SendMouseButton(data->window, 0, GetKeyState(VK_RBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT);
|
|
|
+ SDL_SendMouseButton(data->window, 0, GetKeyState(VK_MBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE);
|
|
|
+ SDL_SendMouseButton(data->window, 0, GetKeyState(VK_XBUTTON1) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_X1);
|
|
|
+ SDL_SendMouseButton(data->window, 0, GetKeyState(VK_XBUTTON2) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_X2);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SDL_assert(0 && "Shouldn't happen");
|
|
|
}
|
|
|
- WIN_CheckRawMouseButtons( mouse->usButtonFlags, data );
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -499,7 +522,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
#ifdef WM_MOUSELEAVE
|
|
|
case WM_MOUSELEAVE:
|
|
|
- if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode) {
|
|
|
+ if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode && !(data->window->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
|
|
|
if (!IsIconic(hwnd)) {
|
|
|
POINT cursorPos;
|
|
|
GetCursorPos(&cursorPos);
|