changeset 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 875c3cf1a12c
children 0b1070f2f94d
files src/events/SDL_keyboard.c src/events/SDL_mouse.c src/video/win32/SDL_win32events.c src/video/win32/SDL_win32window.c
diffstat 4 files changed, 49 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/events/SDL_keyboard.c	Sat Jul 08 20:07:08 2006 +0000
+++ b/src/events/SDL_keyboard.c	Sat Jul 08 20:55:39 2006 +0000
@@ -485,7 +485,8 @@
             }
         }
         if (!focus) {
-            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
+            SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
+                                0, 0);
         }
     }
 
@@ -504,7 +505,8 @@
             }
         }
         if (!focus) {
-            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+            SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
+                                0, 0);
         }
     }
 }
--- a/src/events/SDL_mouse.c	Sat Jul 08 20:07:08 2006 +0000
+++ b/src/events/SDL_mouse.c	Sat Jul 08 20:55:39 2006 +0000
@@ -290,7 +290,7 @@
             }
         }
         if (!focus) {
-            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
+            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
         }
     }
 
@@ -309,7 +309,7 @@
             }
         }
         if (!focus) {
-            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
+            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
         }
     }
 }
--- a/src/video/win32/SDL_win32events.c	Sat Jul 08 20:07:08 2006 +0000
+++ b/src/video/win32/SDL_win32events.c	Sat Jul 08 20:55:39 2006 +0000
@@ -441,18 +441,33 @@
                 }
                 if (keyboard && keyboard->focus != data->windowID) {
                     SDL_SetKeyboardFocus(index, data->windowID);
+
+                    if (SDL_GetWindowFlags(data->windowID) &
+                        SDL_WINDOW_INPUT_GRABBED) {
+                        RECT rect;
+
+                        GetClientRect(hwnd, &rect);
+                        ClientToScreen(hwnd, (LPPOINT) & rect);
+                        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
+                        ClipCursor(&rect);
+                    }
                 }
-                /* FIXME: Restore mode state (mode, gamma, grab) */
+                /* FIXME: Restore mode state (mode, gamma) */
                 /* FIXME: Update keyboard state */
             } else {
                 if (keyboard && keyboard->focus == data->windowID) {
                     SDL_SetKeyboardFocus(index, 0);
+
+                    if (SDL_GetWindowFlags(data->windowID) &
+                        SDL_WINDOW_INPUT_GRABBED) {
+                        ClipCursor(NULL);
+                    }
                 }
                 if (minimized) {
                     SDL_SendWindowEvent(data->windowID,
                                         SDL_WINDOWEVENT_MINIMIZED, 0, 0);
                 }
-                /* FIXME: Restore desktop state (mode, gamma, grab) */
+                /* FIXME: Restore desktop state (mode, gamma) */
             }
             return (0);
         }
@@ -749,12 +764,15 @@
             RECT rect;
             int x, y;
             int w, h;
+            Uint32 window_flags;
 
             GetClientRect(hwnd, &rect);
             ClientToScreen(hwnd, (LPPOINT) & rect);
             ClientToScreen(hwnd, (LPPOINT) & rect + 1);
 
-            if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_INPUT_GRABBED) {
+            window_flags = SDL_GetWindowFlags(data->windowID);
+            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
+                (window_flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
                 ClipCursor(&rect);
             }
 
--- 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