Skip to content

Commit 69255b8

Browse files
committed
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.
1 parent a4de176 commit 69255b8

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

src/video/x11/SDL_x11events.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,13 +1011,10 @@ static int XLookupStringAsUTF8(XKeyEvent *event_struct, char *buffer_return, int
10111011
return result;
10121012
}
10131013

1014-
SDL_WindowData *X11_FindWindow(SDL_VideoDevice *_this, Window window)
1014+
SDL_WindowData *X11_FindWindow(SDL_VideoData *videodata, Window window)
10151015
{
1016-
const SDL_VideoData *videodata = _this->internal;
1017-
int i;
1018-
10191016
if (videodata && videodata->windowlist) {
1020-
for (i = 0; i < videodata->numwindows; ++i) {
1017+
for (int i = 0; i < videodata->numwindows; ++i) {
10211018
if ((videodata->windowlist[i] != NULL) &&
10221019
(videodata->windowlist[i]->xwindow == window)) {
10231020
return videodata->windowlist[i];
@@ -1341,7 +1338,7 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
13411338
// xsettings internally filters events for the windows it watches
13421339
X11_HandleXsettingsEvent(_this, xevent);
13431340

1344-
data = X11_FindWindow(_this, xevent->xany.window);
1341+
data = X11_FindWindow(videodata, xevent->xany.window);
13451342

13461343
if (!data) {
13471344
// The window for KeymapNotify, etc events is 0

src/video/x11/SDL_x11events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern Uint64 X11_GetEventTimestamp(unsigned long time);
3333
extern void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_KeyboardID keyboardID, XEvent *xevent);
3434
extern void X11_HandleButtonPress(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_MouseID mouseID, int button, float x, float y, unsigned long time);
3535
extern void X11_HandleButtonRelease(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_MouseID mouseID, int button, unsigned long time);
36-
extern SDL_WindowData *X11_FindWindow(SDL_VideoDevice *_this, Window window);
36+
extern SDL_WindowData *X11_FindWindow(SDL_VideoData *videodata, Window window);
3737
extern bool X11_ProcessHitTest(SDL_VideoDevice *_this, SDL_WindowData *data, const float x, const float y, bool force_new_result);
3838
extern bool X11_TriggerHitTestAction(SDL_VideoDevice *_this, SDL_WindowData *data, const float x, const float y);
3939
extern bool X11_IsWheelEvent(int button, int *xticks, int *yticks);

src/video/x11/SDL_x11xinput2.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,9 @@ static bool xinput2_version_atleast(const int version, const int wantmajor, cons
130130
return version >= ((wantmajor * 1000) + wantminor);
131131
}
132132

133-
// !!! FIXME: isn't this just X11_FindWindow?
134-
static SDL_WindowData *xinput2_get_sdlwindowdata(SDL_VideoData *videodata, Window window)
135-
{
136-
int i;
137-
for (i = 0; i < videodata->numwindows; i++) {
138-
SDL_WindowData *d = videodata->windowlist[i];
139-
if (d->xwindow == window) {
140-
return d;
141-
}
142-
}
143-
return NULL;
144-
}
145-
146133
static SDL_Window *xinput2_get_sdlwindow(SDL_VideoData *videodata, Window window)
147134
{
148-
const SDL_WindowData *windowdata = xinput2_get_sdlwindowdata(videodata, window);
135+
const SDL_WindowData *windowdata = X11_FindWindow(videodata, window);
149136
return windowdata ? windowdata->window : NULL;
150137
}
151138

@@ -519,7 +506,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
519506
// Handle pen proximity enter/leave
520507
if (proev->what == XIPropertyModified && proev->property == videodata->atoms.pen_atom_wacom_serial_ids) {
521508
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
522-
SDL_WindowData *windowdata = X11_FindWindow(_this, xev->event);
509+
SDL_WindowData *windowdata = X11_FindWindow(videodata, xev->event);
523510
X11_NotifyPenProximityChange(_this, windowdata ? windowdata->window : NULL, proev->deviceid);
524511
}
525512
} break;
@@ -546,7 +533,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
546533
case XI_KeyRelease:
547534
{
548535
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
549-
SDL_WindowData *windowdata = X11_FindWindow(_this, xev->event);
536+
SDL_WindowData *windowdata = X11_FindWindow(videodata, xev->event);
550537
XEvent xevent;
551538

552539
if (xev->deviceid != xev->sourceid) {
@@ -615,7 +602,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
615602
}
616603
} else if (!pointer_emulated) {
617604
// Otherwise assume a regular mouse
618-
SDL_WindowData *windowdata = xinput2_get_sdlwindowdata(videodata, xev->event);
605+
SDL_WindowData *windowdata = X11_FindWindow(videodata, xev->event);
619606
int x_ticks = 0, y_ticks = 0;
620607

621608
// Slave pointer devices don't have button remapping applied automatically, so do it manually.

0 commit comments

Comments
 (0)