From 69255b870d805a5cf7feb81748c9ab521f413100 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Mon, 8 Dec 2025 12:31:30 -0500
Subject: [PATCH] x11: Dedup the X11_FindWindow() function
The was duplicated in the XInput2 code, but taking an SDL_VideoData parameter instead of SDL_VideoDevice. Remove the duplicated XInput2 function, and use an SDL_VideoData parameter for X11_FindWindow to avoid an unnecessary dereference.
---
src/video/x11/SDL_x11events.c | 9 +++------
src/video/x11/SDL_x11events.h | 2 +-
src/video/x11/SDL_x11xinput2.c | 21 ++++-----------------
3 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index eec3f4cd56e7f..fbff514ac23e9 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -1011,13 +1011,10 @@ static int XLookupStringAsUTF8(XKeyEvent *event_struct, char *buffer_return, int
return result;
}
-SDL_WindowData *X11_FindWindow(SDL_VideoDevice *_this, Window window)
+SDL_WindowData *X11_FindWindow(SDL_VideoData *videodata, Window window)
{
- const SDL_VideoData *videodata = _this->internal;
- int i;
-
if (videodata && videodata->windowlist) {
- for (i = 0; i < videodata->numwindows; ++i) {
+ for (int i = 0; i < videodata->numwindows; ++i) {
if ((videodata->windowlist[i] != NULL) &&
(videodata->windowlist[i]->xwindow == window)) {
return videodata->windowlist[i];
@@ -1341,7 +1338,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
// xsettings internally filters events for the windows it watches
X11_HandleXsettingsEvent(_this, xevent);
- data = X11_FindWindow(_this, xevent->xany.window);
+ data = X11_FindWindow(videodata, xevent->xany.window);
if (!data) {
// The window for KeymapNotify, etc events is 0
diff --git a/src/video/x11/SDL_x11events.h b/src/video/x11/SDL_x11events.h
index bc0c226dfa46e..fde745f1488af 100644
--- a/src/video/x11/SDL_x11events.h
+++ b/src/video/x11/SDL_x11events.h
@@ -33,7 +33,7 @@ extern Uint64 X11_GetEventTimestamp(unsigned long time);
extern void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_KeyboardID keyboardID, XEvent *xevent);
extern void X11_HandleButtonPress(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_MouseID mouseID, int button, float x, float y, unsigned long time);
extern void X11_HandleButtonRelease(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_MouseID mouseID, int button, unsigned long time);
-extern SDL_WindowData *X11_FindWindow(SDL_VideoDevice *_this, Window window);
+extern SDL_WindowData *X11_FindWindow(SDL_VideoData *videodata, Window window);
extern bool X11_ProcessHitTest(SDL_VideoDevice *_this, SDL_WindowData *data, const float x, const float y, bool force_new_result);
extern bool X11_TriggerHitTestAction(SDL_VideoDevice *_this, SDL_WindowData *data, const float x, const float y);
extern bool X11_IsWheelEvent(int button, int *xticks, int *yticks);
diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c
index 18a60bd60e1a5..eb56912580f54 100644
--- a/src/video/x11/SDL_x11xinput2.c
+++ b/src/video/x11/SDL_x11xinput2.c
@@ -130,22 +130,9 @@ static bool xinput2_version_atleast(const int version, const int wantmajor, cons
return version >= ((wantmajor * 1000) + wantminor);
}
-// !!! FIXME: isn't this just X11_FindWindow?
-static SDL_WindowData *xinput2_get_sdlwindowdata(SDL_VideoData *videodata, Window window)
-{
- int i;
- for (i = 0; i < videodata->numwindows; i++) {
- SDL_WindowData *d = videodata->windowlist[i];
- if (d->xwindow == window) {
- return d;
- }
- }
- return NULL;
-}
-
static SDL_Window *xinput2_get_sdlwindow(SDL_VideoData *videodata, Window window)
{
- const SDL_WindowData *windowdata = xinput2_get_sdlwindowdata(videodata, window);
+ const SDL_WindowData *windowdata = X11_FindWindow(videodata, window);
return windowdata ? windowdata->window : NULL;
}
@@ -519,7 +506,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
// Handle pen proximity enter/leave
if (proev->what == XIPropertyModified && proev->property == videodata->atoms.pen_atom_wacom_serial_ids) {
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
- SDL_WindowData *windowdata = X11_FindWindow(_this, xev->event);
+ SDL_WindowData *windowdata = X11_FindWindow(videodata, xev->event);
X11_NotifyPenProximityChange(_this, windowdata ? windowdata->window : NULL, proev->deviceid);
}
} break;
@@ -546,7 +533,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
case XI_KeyRelease:
{
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
- SDL_WindowData *windowdata = X11_FindWindow(_this, xev->event);
+ SDL_WindowData *windowdata = X11_FindWindow(videodata, xev->event);
XEvent xevent;
if (xev->deviceid != xev->sourceid) {
@@ -615,7 +602,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
}
} else if (!pointer_emulated) {
// Otherwise assume a regular mouse
- SDL_WindowData *windowdata = xinput2_get_sdlwindowdata(videodata, xev->event);
+ SDL_WindowData *windowdata = X11_FindWindow(videodata, xev->event);
int x_ticks = 0, y_ticks = 0;
// Slave pointer devices don't have button remapping applied automatically, so do it manually.