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.
This commit is contained in:
@@ -1011,13 +1011,10 @@ static int XLookupStringAsUTF8(XKeyEvent *event_struct, char *buffer_return, int
|
|||||||
return result;
|
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) {
|
if (videodata && videodata->windowlist) {
|
||||||
for (i = 0; i < videodata->numwindows; ++i) {
|
for (int i = 0; i < videodata->numwindows; ++i) {
|
||||||
if ((videodata->windowlist[i] != NULL) &&
|
if ((videodata->windowlist[i] != NULL) &&
|
||||||
(videodata->windowlist[i]->xwindow == window)) {
|
(videodata->windowlist[i]->xwindow == window)) {
|
||||||
return videodata->windowlist[i];
|
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
|
// xsettings internally filters events for the windows it watches
|
||||||
X11_HandleXsettingsEvent(_this, xevent);
|
X11_HandleXsettingsEvent(_this, xevent);
|
||||||
|
|
||||||
data = X11_FindWindow(_this, xevent->xany.window);
|
data = X11_FindWindow(videodata, xevent->xany.window);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
// The window for KeymapNotify, etc events is 0
|
// The window for KeymapNotify, etc events is 0
|
||||||
|
|||||||
@@ -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_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_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 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_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_TriggerHitTestAction(SDL_VideoDevice *_this, SDL_WindowData *data, const float x, const float y);
|
||||||
extern bool X11_IsWheelEvent(int button, int *xticks, int *yticks);
|
extern bool X11_IsWheelEvent(int button, int *xticks, int *yticks);
|
||||||
|
|||||||
@@ -130,22 +130,9 @@ static bool xinput2_version_atleast(const int version, const int wantmajor, cons
|
|||||||
return version >= ((wantmajor * 1000) + wantminor);
|
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)
|
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;
|
return windowdata ? windowdata->window : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,7 +506,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
|
|||||||
// Handle pen proximity enter/leave
|
// Handle pen proximity enter/leave
|
||||||
if (proev->what == XIPropertyModified && proev->property == videodata->atoms.pen_atom_wacom_serial_ids) {
|
if (proev->what == XIPropertyModified && proev->property == videodata->atoms.pen_atom_wacom_serial_ids) {
|
||||||
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
|
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);
|
X11_NotifyPenProximityChange(_this, windowdata ? windowdata->window : NULL, proev->deviceid);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@@ -546,7 +533,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
|
|||||||
case XI_KeyRelease:
|
case XI_KeyRelease:
|
||||||
{
|
{
|
||||||
const XIDeviceEvent *xev = (const XIDeviceEvent *)cookie->data;
|
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;
|
XEvent xevent;
|
||||||
|
|
||||||
if (xev->deviceid != xev->sourceid) {
|
if (xev->deviceid != xev->sourceid) {
|
||||||
@@ -615,7 +602,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
|
|||||||
}
|
}
|
||||||
} else if (!pointer_emulated) {
|
} else if (!pointer_emulated) {
|
||||||
// Otherwise assume a regular mouse
|
// 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;
|
int x_ticks = 0, y_ticks = 0;
|
||||||
|
|
||||||
// Slave pointer devices don't have button remapping applied automatically, so do it manually.
|
// Slave pointer devices don't have button remapping applied automatically, so do it manually.
|
||||||
|
|||||||
Reference in New Issue
Block a user