Skip to content

Commit 1abac3c

Browse files
committed
Revert "x11: Better handle XInput2 mouse tracking outside the window"
This reverts commit 8c733d1.
1 parent 85d2345 commit 1abac3c

File tree

3 files changed

+15
-43
lines changed

3 files changed

+15
-43
lines changed

src/video/x11/SDL_x11events.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,7 @@ static void X11_DispatchFocusOut(SDL_VideoDevice *_this, SDL_WindowData *data)
492492
/* If another window has already processed a focus in, then don't try to
493493
* remove focus here. Doing so will incorrectly remove focus from that
494494
* window, and the focus lost event for this window will have already
495-
* been dispatched anyway.
496-
*/
497-
if (data->tracking_mouse_outside_window && data->window == SDL_GetMouseFocus()) {
498-
// If tracking the pointer and keyboard focus is lost, raise all buttons and relinquish mouse focus.
499-
SDL_SendMouseButton(0, data->window, SDL_GLOBAL_MOUSE_ID, SDL_BUTTON_LEFT, false);
500-
SDL_SendMouseButton(0, data->window, SDL_GLOBAL_MOUSE_ID, SDL_BUTTON_MIDDLE, false);
501-
SDL_SendMouseButton(0, data->window, SDL_GLOBAL_MOUSE_ID, SDL_BUTTON_RIGHT, false);
502-
SDL_SendMouseButton(0, data->window, SDL_GLOBAL_MOUSE_ID, SDL_BUTTON_X1, false);
503-
SDL_SendMouseButton(0, data->window, SDL_GLOBAL_MOUSE_ID, SDL_BUTTON_X2, false);
504-
SDL_SetMouseFocus(NULL);
505-
}
495+
* been dispatched anyway. */
506496
if (data->window == SDL_GetKeyboardFocus()) {
507497
SDL_SetKeyboardFocus(NULL);
508498
}
@@ -1084,16 +1074,6 @@ void X11_HandleButtonRelease(SDL_VideoDevice *_this, SDL_WindowData *windowdata,
10841074
// see explanation at case ButtonPress
10851075
button -= (8 - SDL_BUTTON_X1);
10861076
}
1087-
1088-
/* If the mouse is captured and all buttons are now released, clear the capture
1089-
* flag so the focus will be cleared if the mouse is outside the window.
1090-
*/
1091-
if ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) &&
1092-
!(SDL_GetMouseState(NULL, NULL) & ~SDL_BUTTON_MASK(button))) {
1093-
window->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
1094-
windowdata->tracking_mouse_outside_window = false;
1095-
}
1096-
10971077
SDL_SendMouseButton(timestamp, window, mouseID, button, false);
10981078
}
10991079
}
@@ -1339,8 +1319,6 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
13391319
SDL_Log("Mode: NotifyUngrab");
13401320
}
13411321
#endif
1342-
data->tracking_mouse_outside_window = false;
1343-
13441322
SDL_SetMouseFocus(data->window);
13451323

13461324
mouse->last_x = xevent->xcrossing.x;
@@ -1387,17 +1365,14 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
13871365
if (xevent->xcrossing.mode != NotifyGrab &&
13881366
xevent->xcrossing.mode != NotifyUngrab &&
13891367
xevent->xcrossing.detail != NotifyInferior) {
1390-
if (!(data->window->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
1391-
/* In order for interaction with the window decorations and menu to work properly
1392-
on Mutter, we need to ungrab the keyboard when the mouse leaves. */
1393-
if (!(data->window->flags & SDL_WINDOW_FULLSCREEN)) {
1394-
X11_SetWindowKeyboardGrab(_this, data->window, false);
1395-
}
13961368

1397-
SDL_SetMouseFocus(NULL);
1398-
} else {
1399-
data->tracking_mouse_outside_window = true;
1369+
/* In order for interaction with the window decorations and menu to work properly
1370+
on Mutter, we need to ungrab the keyboard when the mouse leaves. */
1371+
if (!(data->window->flags & SDL_WINDOW_FULLSCREEN)) {
1372+
X11_SetWindowKeyboardGrab(_this, data->window, false);
14001373
}
1374+
1375+
SDL_SetMouseFocus(NULL);
14011376
}
14021377
} break;
14031378

src/video/x11/SDL_x11window.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ struct SDL_WindowData
117117
bool fullscreen_borders_forced_on;
118118
bool was_shown;
119119
bool emit_size_move_after_property_notify;
120-
bool tracking_mouse_outside_window;
121120
SDL_HitTestResult hit_test_result;
122121

123122
XPoint xim_spot;

src/video/x11/SDL_x11xinput2.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,15 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
467467
SDL_SendPenAxis(0, pen->pen, window, (SDL_PenAxis) i, axes[i]);
468468
}
469469
}
470-
} else {
470+
} else if (!pointer_emulated && xev->deviceid == videodata->xinput_master_pointer_device) {
471+
// Use the master device for non-relative motion, as the slave devices can seemingly lag behind.
471472
SDL_Mouse *mouse = SDL_GetMouse();
472-
SDL_Window *window = xinput2_get_sdlwindow(videodata, xev->event);
473-
if (!mouse->relative_mode && !pointer_emulated && window &&
474-
(xev->deviceid == videodata->xinput_master_pointer_device || window->internal->tracking_mouse_outside_window)) {
475-
/* Use the master device for non-relative motion, as the slave devices can seemingly lag behind, unless
476-
* tracking the mouse outside the window, in which case the slave devices deliver coordinates, while the
477-
* master does not.
478-
*/
479-
X11_ProcessHitTest(_this, window->internal, (float)xev->event_x, (float)xev->event_y, false);
480-
SDL_SendMouseMotion(0, window, SDL_GLOBAL_MOUSE_ID, false, (float)xev->event_x, (float)xev->event_y);
473+
if (!mouse->relative_mode) {
474+
SDL_Window *window = xinput2_get_sdlwindow(videodata, xev->event);
475+
if (window) {
476+
X11_ProcessHitTest(_this, window->internal, (float)xev->event_x, (float)xev->event_y, false);
477+
SDL_SendMouseMotion(0, window, SDL_GLOBAL_MOUSE_ID, false, (float)xev->event_x, (float)xev->event_y);
478+
}
481479
}
482480
}
483481
} break;

0 commit comments

Comments
 (0)