Skip to content

Commit

Permalink
x11: Properly check for XInput2 support before using it.
Browse files Browse the repository at this point in the history
This specifically fixes a crash in X11_WarpMouseInternal if XInput2 was
missing at runtime, but also cleans up a few other existing checks.

Fixes #8378.

(cherry picked from commit 82f54af)
(cherry picked from commit 2849ca4)
  • Loading branch information
icculus committed Oct 11, 2023
1 parent 2abefb1 commit 5be746a
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/video/x11/SDL_x11mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,16 @@ static void WarpMouseInternal(Window xwindow, const int x, const int y)
Display *display = videodata->display;
#if SDL_VIDEO_DRIVER_X11_XINPUT2
int deviceid = 0;
/* It seems XIWarpPointer() doesn't work correctly on multi-head setups:
* https://developer.blender.org/rB165caafb99c6846e53d11c4e966990aaffc06cea
*/
if (ScreenCount(display) == 1) {
X11_XIGetClientPointer(display, None, &deviceid);
if (X11_Xinput2IsInitialized()) {
/* It seems XIWarpPointer() doesn't work correctly on multi-head setups:
* https://developer.blender.org/rB165caafb99c6846e53d11c4e966990aaffc06cea
*/
if (ScreenCount(display) == 1) {
X11_XIGetClientPointer(display, None, &deviceid);
}
}
if (deviceid != 0) {
SDL_assert(SDL_X11_HAVE_XINPUT2);
X11_XIWarpPointer(display, deviceid, None, xwindow, 0.0, 0.0, 0, 0, (double)x, (double)y);
} else
#endif
Expand Down Expand Up @@ -369,14 +372,7 @@ static int X11_WarpMouseGlobal(int x, int y)

static int X11_SetRelativeMouseMode(SDL_bool enabled)
{
#if SDL_VIDEO_DRIVER_X11_XINPUT2
if (X11_Xinput2IsInitialized()) {
return 0;
}
#else
SDL_Unsupported();
#endif
return -1;
return X11_Xinput2IsInitialized() ? 0 : SDL_Unsupported();
}

static int X11_CaptureMouse(SDL_Window *window)
Expand Down Expand Up @@ -414,12 +410,9 @@ static Uint32 X11_GetGlobalMouseState(int *x, int *y)

/* !!! FIXME: should we XSync() here first? */

#if !SDL_VIDEO_DRIVER_X11_XINPUT2
videodata->global_mouse_changed = SDL_TRUE;
#else
if (!SDL_X11_HAVE_XINPUT2)
if (!X11_Xinput2IsInitialized()) {
videodata->global_mouse_changed = SDL_TRUE;
#endif
}

/* check if we have this cached since XInput last saw the mouse move. */
/* !!! FIXME: can we just calculate this from XInput's events? */
Expand Down

0 comments on commit 5be746a

Please sign in to comment.