Implemented Win32 input grab SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Sat, 08 Jul 2006 20:55:39 +0000
branchSDL-1.3
changeset 1732fd65f12b6de6
parent 1731 875c3cf1a12c
child 1733 0b1070f2f94d
Implemented Win32 input grab
src/events/SDL_keyboard.c
src/events/SDL_mouse.c
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32window.c
     1.1 --- a/src/events/SDL_keyboard.c	Sat Jul 08 20:07:08 2006 +0000
     1.2 +++ b/src/events/SDL_keyboard.c	Sat Jul 08 20:55:39 2006 +0000
     1.3 @@ -485,7 +485,8 @@
     1.4              }
     1.5          }
     1.6          if (!focus) {
     1.7 -            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
     1.8 +            SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
     1.9 +                                0, 0);
    1.10          }
    1.11      }
    1.12  
    1.13 @@ -504,7 +505,8 @@
    1.14              }
    1.15          }
    1.16          if (!focus) {
    1.17 -            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
    1.18 +            SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
    1.19 +                                0, 0);
    1.20          }
    1.21      }
    1.22  }
     2.1 --- a/src/events/SDL_mouse.c	Sat Jul 08 20:07:08 2006 +0000
     2.2 +++ b/src/events/SDL_mouse.c	Sat Jul 08 20:55:39 2006 +0000
     2.3 @@ -290,7 +290,7 @@
     2.4              }
     2.5          }
     2.6          if (!focus) {
     2.7 -            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
     2.8 +            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
     2.9          }
    2.10      }
    2.11  
    2.12 @@ -309,7 +309,7 @@
    2.13              }
    2.14          }
    2.15          if (!focus) {
    2.16 -            SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
    2.17 +            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
    2.18          }
    2.19      }
    2.20  }
     3.1 --- a/src/video/win32/SDL_win32events.c	Sat Jul 08 20:07:08 2006 +0000
     3.2 +++ b/src/video/win32/SDL_win32events.c	Sat Jul 08 20:55:39 2006 +0000
     3.3 @@ -441,18 +441,33 @@
     3.4                  }
     3.5                  if (keyboard && keyboard->focus != data->windowID) {
     3.6                      SDL_SetKeyboardFocus(index, data->windowID);
     3.7 +
     3.8 +                    if (SDL_GetWindowFlags(data->windowID) &
     3.9 +                        SDL_WINDOW_INPUT_GRABBED) {
    3.10 +                        RECT rect;
    3.11 +
    3.12 +                        GetClientRect(hwnd, &rect);
    3.13 +                        ClientToScreen(hwnd, (LPPOINT) & rect);
    3.14 +                        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
    3.15 +                        ClipCursor(&rect);
    3.16 +                    }
    3.17                  }
    3.18 -                /* FIXME: Restore mode state (mode, gamma, grab) */
    3.19 +                /* FIXME: Restore mode state (mode, gamma) */
    3.20                  /* FIXME: Update keyboard state */
    3.21              } else {
    3.22                  if (keyboard && keyboard->focus == data->windowID) {
    3.23                      SDL_SetKeyboardFocus(index, 0);
    3.24 +
    3.25 +                    if (SDL_GetWindowFlags(data->windowID) &
    3.26 +                        SDL_WINDOW_INPUT_GRABBED) {
    3.27 +                        ClipCursor(NULL);
    3.28 +                    }
    3.29                  }
    3.30                  if (minimized) {
    3.31                      SDL_SendWindowEvent(data->windowID,
    3.32                                          SDL_WINDOWEVENT_MINIMIZED, 0, 0);
    3.33                  }
    3.34 -                /* FIXME: Restore desktop state (mode, gamma, grab) */
    3.35 +                /* FIXME: Restore desktop state (mode, gamma) */
    3.36              }
    3.37              return (0);
    3.38          }
    3.39 @@ -749,12 +764,15 @@
    3.40              RECT rect;
    3.41              int x, y;
    3.42              int w, h;
    3.43 +            Uint32 window_flags;
    3.44  
    3.45              GetClientRect(hwnd, &rect);
    3.46              ClientToScreen(hwnd, (LPPOINT) & rect);
    3.47              ClientToScreen(hwnd, (LPPOINT) & rect + 1);
    3.48  
    3.49 -            if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_INPUT_GRABBED) {
    3.50 +            window_flags = SDL_GetWindowFlags(data->windowID);
    3.51 +            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
    3.52 +                (window_flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
    3.53                  ClipCursor(&rect);
    3.54              }
    3.55  
     4.1 --- a/src/video/win32/SDL_win32window.c	Sat Jul 08 20:07:08 2006 +0000
     4.2 +++ b/src/video/win32/SDL_win32window.c	Sat Jul 08 20:55:39 2006 +0000
     4.3 @@ -106,6 +106,11 @@
     4.4              window->flags &= ~SDL_WINDOW_MINIMIZED;
     4.5          }
     4.6      }
     4.7 +    if (GetFocus() == hwnd) {
     4.8 +        int index = data->videodata->keyboard;
     4.9 +        window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
    4.10 +        SDL_SetKeyboardFocus(index, data->windowID);
    4.11 +    }
    4.12  
    4.13      /* All done! */
    4.14      window->driverdata = data;
    4.15 @@ -374,7 +379,23 @@
    4.16  void
    4.17  WIN_SetWindowGrab(_THIS, SDL_Window * window)
    4.18  {
    4.19 -    /* FIXME! */
    4.20 +    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    4.21 +
    4.22 +    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
    4.23 +        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
    4.24 +            RECT rect;
    4.25 +            GetClientRect(hwnd, &rect);
    4.26 +            ClientToScreen(hwnd, (LPPOINT) & rect);
    4.27 +            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
    4.28 +            ClipCursor(&rect);
    4.29 +        } else {
    4.30 +            SetFocus(hwnd);
    4.31 +        }
    4.32 +    } else {
    4.33 +        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
    4.34 +            ClipCursor(NULL);
    4.35 +        }
    4.36 +    }
    4.37  }
    4.38  
    4.39  void