diff src/video/win32/SDL_win32window.c @ 1732:fd65f12b6de6 SDL-1.3

Implemented Win32 input grab
author Sam Lantinga <slouken@libsdl.org>
date Sat, 08 Jul 2006 20:55:39 +0000
parents 6c63fc2bd986
children 0b1070f2f94d
line wrap: on
line diff
--- a/src/video/win32/SDL_win32window.c	Sat Jul 08 20:07:08 2006 +0000
+++ b/src/video/win32/SDL_win32window.c	Sat Jul 08 20:55:39 2006 +0000
@@ -106,6 +106,11 @@
             window->flags &= ~SDL_WINDOW_MINIMIZED;
         }
     }
+    if (GetFocus() == hwnd) {
+        int index = data->videodata->keyboard;
+        window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
+        SDL_SetKeyboardFocus(index, data->windowID);
+    }
 
     /* All done! */
     window->driverdata = data;
@@ -374,7 +379,23 @@
 void
 WIN_SetWindowGrab(_THIS, SDL_Window * window)
 {
-    /* FIXME! */
+    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+
+    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
+        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
+            RECT rect;
+            GetClientRect(hwnd, &rect);
+            ClientToScreen(hwnd, (LPPOINT) & rect);
+            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
+            ClipCursor(&rect);
+        } else {
+            SetFocus(hwnd);
+        }
+    } else {
+        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
+            ClipCursor(NULL);
+        }
+    }
 }
 
 void