# HG changeset patch # User Sam Lantinga # Date 1152392139 0 # Node ID fd65f12b6de6c8bd5e7353a1b69d16c5d1e4836c # Parent 875c3cf1a12caf2731bbc1ae8c891ec3baaa7af1 Implemented Win32 input grab diff -r 875c3cf1a12c -r fd65f12b6de6 src/events/SDL_keyboard.c --- 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); } } } diff -r 875c3cf1a12c -r fd65f12b6de6 src/events/SDL_mouse.c --- 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); } } } diff -r 875c3cf1a12c -r fd65f12b6de6 src/video/win32/SDL_win32events.c --- 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); } diff -r 875c3cf1a12c -r fd65f12b6de6 src/video/win32/SDL_win32window.c --- 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