src/video/windows/SDL_windowsmouse.c
changeset 8252 3e4846dc97b1
parent 8149 681eb46b8ac4
child 8254 f97b5166c158
equal deleted inserted replaced
8251:833eae6867c2 8252:3e4846dc97b1
   194 
   194 
   195 static int
   195 static int
   196 WIN_SetRelativeMouseMode(SDL_bool enabled)
   196 WIN_SetRelativeMouseMode(SDL_bool enabled)
   197 {
   197 {
   198     RAWINPUTDEVICE rawMouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
   198     RAWINPUTDEVICE rawMouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
   199     HWND hWnd;
   199 
   200     hWnd = GetActiveWindow();
   200     if (!enabled) {
   201 
       
   202     rawMouse.hwndTarget = hWnd;
       
   203     if(!enabled) {
       
   204         rawMouse.dwFlags |= RIDEV_REMOVE;
   201         rawMouse.dwFlags |= RIDEV_REMOVE;
   205         rawMouse.hwndTarget = NULL;
   202     }
   206     }
       
   207 
       
   208 
   203 
   209     /* (Un)register raw input for mice */
   204     /* (Un)register raw input for mice */
   210     if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
   205     if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
   211 
   206 
   212         /* Only return an error when registering. If we unregister and fail, then
   207         /* Only return an error when registering. If we unregister and fail, then
   213         it's probably that we unregistered twice. That's OK. */
   208         it's probably that we unregistered twice. That's OK. */
   214         if(enabled) {
   209         if (enabled) {
   215             return SDL_Unsupported();
   210             return SDL_Unsupported();
   216         }
   211         }
   217     }
       
   218 
       
   219     if (enabled) {
       
   220         LONG cx, cy;
       
   221         RECT rect;
       
   222         GetWindowRect(hWnd, &rect);
       
   223 
       
   224         cx = (rect.left + rect.right) / 2;
       
   225         cy = (rect.top + rect.bottom) / 2;
       
   226 
       
   227         /* Make an absurdly small clip rect */
       
   228         rect.left = cx-1;
       
   229         rect.right = cx+1;
       
   230         rect.top = cy-1;
       
   231         rect.bottom = cy+1;
       
   232 
       
   233         ClipCursor(&rect);
       
   234     } else {
       
   235         ClipCursor(NULL);
       
   236     }
   212     }
   237     return 0;
   213     return 0;
   238 }
   214 }
   239 
   215 
   240 void
   216 void