mirror of
https://github.com/encounter/SDL.git
synced 2025-12-13 15:16:13 +00:00
Minor input grab clarifications.
Clarify that grabbing the mouse only works with one window at a time; this was always true at the system level, though SDL could previously get confused by multiple simultaneous grabs, so now we explicitly break any existing grab before starting a new one and document it as such. Also track the window that is currently grabbed, and provide an API to query for that window. This makes it easy to automate mouse ungrabbing at breakpoints with gdb7's scripting, since the scripts can now know which window to ungrab. In 2.1, we should probably change this API to SDL_GrabInput(win) and SDL_UngrabInput(void), or something.
This commit is contained in:
@@ -591,3 +591,4 @@
|
||||
#define SDL_QueueAudio SDL_QueueAudio_REAL
|
||||
#define SDL_GetQueuedAudioSize SDL_GetQueuedAudioSize_REAL
|
||||
#define SDL_ClearQueuedAudio SDL_ClearQueuedAudio_REAL
|
||||
#define SDL_GetGrabbedWindow SDL_GetGrabbedWindow_REAL
|
||||
|
||||
@@ -623,3 +623,4 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX2,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_QueueAudio,(SDL_AudioDeviceID a, const void *b, Uint32 c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),)
|
||||
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)
|
||||
|
||||
@@ -274,6 +274,7 @@ struct SDL_VideoDevice
|
||||
int num_displays;
|
||||
SDL_VideoDisplay *displays;
|
||||
SDL_Window *windows;
|
||||
SDL_Window *grabbed_window;
|
||||
Uint8 window_magic;
|
||||
Uint32 next_object_id;
|
||||
char * clipboard_text;
|
||||
|
||||
@@ -2116,6 +2116,7 @@ void
|
||||
SDL_UpdateWindowGrab(SDL_Window * window)
|
||||
{
|
||||
if (_this->SetWindowGrab) {
|
||||
SDL_Window *grabbed_window;
|
||||
SDL_bool grabbed;
|
||||
if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
|
||||
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
@@ -2123,6 +2124,19 @@ SDL_UpdateWindowGrab(SDL_Window * window)
|
||||
} else {
|
||||
grabbed = SDL_FALSE;
|
||||
}
|
||||
|
||||
grabbed_window = _this->grabbed_window;
|
||||
if (grabbed) {
|
||||
if (grabbed_window && (grabbed_window != window)) {
|
||||
/* stealing a grab from another window! */
|
||||
grabbed_window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
|
||||
_this->SetWindowGrab(_this, grabbed_window, SDL_FALSE);
|
||||
}
|
||||
_this->grabbed_window = window;
|
||||
} else if (grabbed_window == window) {
|
||||
_this->grabbed_window = NULL; /* ungrabbing. */
|
||||
}
|
||||
|
||||
_this->SetWindowGrab(_this, window, grabbed);
|
||||
}
|
||||
}
|
||||
@@ -2147,8 +2161,15 @@ SDL_bool
|
||||
SDL_GetWindowGrab(SDL_Window * window)
|
||||
{
|
||||
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
||||
SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
|
||||
return window == _this->grabbed_window;
|
||||
}
|
||||
|
||||
return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
|
||||
SDL_Window *
|
||||
SDL_GetGrabbedWindow(void)
|
||||
{
|
||||
SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
|
||||
return _this->grabbed_window;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user