Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Implemented Win32 input grab

  • Loading branch information
slouken committed Jul 8, 2006
1 parent e800aa1 commit e5f56341092351b3123661ea1886ef7b3a9498cb
Showing with 49 additions and 8 deletions.
  1. +4 −2 src/events/SDL_keyboard.c
  2. +2 −2 src/events/SDL_mouse.c
  3. +21 −3 src/video/win32/SDL_win32events.c
  4. +22 −1 src/video/win32/SDL_win32window.c
@@ -485,7 +485,8 @@ SDL_SetKeyboardFocus(int index, SDL_WindowID windowID)
}
}
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 @@ SDL_SetKeyboardFocus(int index, SDL_WindowID windowID)
}
}
if (!focus) {
SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
0, 0);
}
}
}
@@ -290,7 +290,7 @@ SDL_SetMouseFocus(int index, SDL_WindowID windowID)
}
}
if (!focus) {
SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
}
}

@@ -309,7 +309,7 @@ SDL_SetMouseFocus(int index, SDL_WindowID windowID)
}
}
if (!focus) {
SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
}
}
}
@@ -441,18 +441,33 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
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);
}

@@ -106,6 +106,11 @@ SetupWindowData(SDL_Window * window, HWND hwnd, BOOL created)
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 @@ WIN_RestoreWindow(_THIS, SDL_Window * window)
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

0 comments on commit e5f5634

Please sign in to comment.