x11: Don't loop forever if the X server refuses a pointer grab.

This commit is contained in:
Ryan C. Gordon 2016-12-26 23:02:14 -05:00
parent 76f2ae3ca2
commit 7c31636666
2 changed files with 20 additions and 7 deletions

View File

@ -124,6 +124,8 @@ typedef struct SDL_VideoData
SDL_Scancode key_layout[256]; SDL_Scancode key_layout[256];
SDL_bool selection_waiting; SDL_bool selection_waiting;
SDL_bool broken_pointer_grab; /* true if XGrabPointer seems unreliable. */
Uint32 last_mode_change_deadline; Uint32 last_mode_change_deadline;
SDL_bool global_mouse_changed; SDL_bool global_mouse_changed;

View File

@ -41,6 +41,7 @@
#include "SDL_timer.h" #include "SDL_timer.h"
#include "SDL_syswm.h" #include "SDL_syswm.h"
#include "SDL_assert.h" #include "SDL_assert.h"
#include "SDL_log.h"
#define _NET_WM_STATE_REMOVE 0l #define _NET_WM_STATE_REMOVE 0l
#define _NET_WM_STATE_ADD 1l #define _NET_WM_STATE_ADD 1l
@ -1483,9 +1484,13 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
if (oldstyle_fullscreen || grabbed) { if (oldstyle_fullscreen || grabbed) {
/* Try to grab the mouse */ /* Try to grab the mouse */
for (;;) { if (!data->videodata->broken_pointer_grab) {
int result = int attempts;
X11_XGrabPointer(display, data->xwindow, True, 0, GrabModeAsync, int result;
/* Try for up to ~250ms to grab. If it still fails, stop trying. */
for (attempts = 0; attempts < 5; attempts++) {
result = X11_XGrabPointer(display, data->xwindow, True, 0, GrabModeAsync,
GrabModeAsync, data->xwindow, None, CurrentTime); GrabModeAsync, data->xwindow, None, CurrentTime);
if (result == GrabSuccess) { if (result == GrabSuccess) {
break; break;
@ -1493,6 +1498,12 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
SDL_Delay(50); SDL_Delay(50);
} }
if (result != GrabSuccess) {
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "The X server refused to let us grab the mouse. You might experience input bugs.");
data->videodata->broken_pointer_grab = SDL_TRUE; /* don't try again. */
}
}
/* Raise the window if we grab the mouse */ /* Raise the window if we grab the mouse */
X11_XRaiseWindow(display, data->xwindow); X11_XRaiseWindow(display, data->xwindow);