From f6388b5f387db53bc0611310750347a9945aae55 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Thu, 10 Sep 2026 12:09:07 -0400 Subject: [PATCH] x11: Move the xinput2 device info to the xinput2 source file It was declared in the mouse header, but is not actually needed there aside from cleanup, which can be moved to the xinput2 quit function. (cherry picked from commit 4d9cd867750043a6620b8dd386d8dda6f96a657a) --- src/video/x11/SDL_x11mouse.c | 19 +++--------- src/video/x11/SDL_x11mouse.h | 12 -------- src/video/x11/SDL_x11video.h | 1 - src/video/x11/SDL_x11xinput2.c | 54 +++++++++++++++++++++++----------- 4 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index 7ad974b132..ffea01e88d 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -585,24 +585,13 @@ void X11_InitMouse(SDL_VideoDevice *_this) void X11_QuitMouse(SDL_VideoDevice *_this) { - SDL_VideoData *data = _this->internal; - SDL_XInput2DeviceInfo *i; - SDL_XInput2DeviceInfo *next; - int j; - - for (j = 0; j < SDL_arraysize(sys_cursors); j++) { - if (sys_cursors[j]) { - X11_FreeCursor(sys_cursors[j]); - sys_cursors[j] = NULL; + for (int i = 0; i < SDL_arraysize(sys_cursors); i++) { + if (sys_cursors[i]) { + X11_FreeCursor(sys_cursors[i]); + sys_cursors[i] = NULL; } } - for (i = data->mouse_device_info; i; i = next) { - next = i->next; - SDL_free(i); - } - data->mouse_device_info = NULL; - X11_DestroyEmptyCursor(); } diff --git a/src/video/x11/SDL_x11mouse.h b/src/video/x11/SDL_x11mouse.h index 27540cb75a..21279e2fd4 100644 --- a/src/video/x11/SDL_x11mouse.h +++ b/src/video/x11/SDL_x11mouse.h @@ -23,18 +23,6 @@ #ifndef SDL_x11mouse_h_ #define SDL_x11mouse_h_ -typedef struct SDL_XInput2DeviceInfo -{ - int device_id; - int number[2]; - bool relative[2]; - bool prev_coord_valid[2]; - double minval[2]; - double maxval[2]; - double prev_coords[2]; - struct SDL_XInput2DeviceInfo *next; -} SDL_XInput2DeviceInfo; - extern void X11_InitMouse(SDL_VideoDevice *_this); extern void X11_QuitMouse(SDL_VideoDevice *_this); extern void X11_SetHitTestCursor(SDL_HitTestResult rc); diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index afb7487d55..c3b3bb55c5 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -136,7 +136,6 @@ struct SDL_VideoData SDL_Point global_mouse_position; Uint32 global_mouse_buttons; - SDL_XInput2DeviceInfo *mouse_device_info; unsigned long xinput_last_button_serial; int xinput_master_pointer_device; bool xinput_hierarchy_changed; diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index c396115273..2661de7ad7 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -80,6 +80,20 @@ static SDL_XInput2ScrollableDevice *scrollable_devices; static int scrollable_device_count; #endif +typedef struct SDL_XInput2DeviceInfo +{ + int device_id; + int number[2]; + bool relative[2]; + bool prev_coord_valid[2]; + double minval[2]; + double maxval[2]; + double prev_coords[2]; + struct SDL_XInput2DeviceInfo *next; +} SDL_XInput2DeviceInfo; + +static SDL_XInput2DeviceInfo *xinput2_device_info; + static void parse_relative_valuators(SDL_XInput2DeviceInfo *devinfo, const XIRawEvent *rawev) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -321,6 +335,12 @@ bool X11_InitXinput2(SDL_VideoDevice *_this) void X11_QuitXinput2(SDL_VideoDevice *_this) { + for (SDL_XInput2DeviceInfo *i = xinput2_device_info, *next = NULL; i; i = next) { + next = i->next; + SDL_free(i); + } + xinput2_device_info = NULL; + #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2 SDL_free(xinput2_pointer_button_map); xinput2_pointer_button_map = NULL; @@ -362,16 +382,16 @@ void X11_Xinput2UpdatePointerMapping(SDL_VideoDevice *_this) #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2 // xi2 device went away? take it out of the list. -static void xinput2_remove_device_info(SDL_VideoData *videodata, const int device_id) +static void xinput2_remove_device_info(const int device_id) { SDL_XInput2DeviceInfo *prev = NULL; SDL_XInput2DeviceInfo *devinfo; - for (devinfo = videodata->mouse_device_info; devinfo; devinfo = devinfo->next) { + for (devinfo = xinput2_device_info; devinfo; devinfo = devinfo->next) { if (devinfo->device_id == device_id) { - SDL_assert((devinfo == videodata->mouse_device_info) == (prev == NULL)); + SDL_assert((devinfo == xinput2_device_info) == (prev == NULL)); if (!prev) { - videodata->mouse_device_info = devinfo->next; + xinput2_device_info = devinfo->next; } else { prev->next = devinfo->next; } @@ -382,9 +402,9 @@ static void xinput2_remove_device_info(SDL_VideoData *videodata, const int devic } } -static void xinput2_reset_relative_valuators(SDL_VideoData *videodata) +static void xinput2_reset_relative_valuators() { - for (SDL_XInput2DeviceInfo *devinfo = videodata->mouse_device_info; devinfo; devinfo = devinfo->next) { + for (SDL_XInput2DeviceInfo *devinfo = xinput2_device_info; devinfo; devinfo = devinfo->next) { devinfo->prev_coord_valid[0] = false; devinfo->prev_coord_valid[1] = false; } @@ -443,15 +463,15 @@ static void xinput2_update_relative_valuators(SDL_XInput2DeviceInfo *devinfo, XI } } -static SDL_XInput2DeviceInfo *xinput2_get_cached_device_info(SDL_VideoData *videodata, const int device_id) +static SDL_XInput2DeviceInfo *xinput2_get_cached_device_info(const int device_id) { - for (SDL_XInput2DeviceInfo *devinfo = videodata->mouse_device_info, *prev = NULL; devinfo; devinfo = devinfo->next) { + for (SDL_XInput2DeviceInfo *devinfo = xinput2_device_info, *prev = NULL; devinfo; devinfo = devinfo->next) { if (devinfo->device_id == device_id) { - SDL_assert((devinfo == videodata->mouse_device_info) == (prev == NULL)); + SDL_assert((devinfo == xinput2_device_info) == (prev == NULL)); if (prev) { // move this to the front of the list, assuming we'll get more from this one. prev->next = devinfo->next; - devinfo->next = videodata->mouse_device_info; - videodata->mouse_device_info = devinfo; + devinfo->next = xinput2_device_info; + xinput2_device_info = devinfo; } return devinfo; } @@ -464,7 +484,7 @@ static SDL_XInput2DeviceInfo *xinput2_get_cached_device_info(SDL_VideoData *vide static SDL_XInput2DeviceInfo *xinput2_get_device_info(SDL_VideoData *videodata, const int device_id) { // Cache device info as we see new devices. - SDL_XInput2DeviceInfo *devinfo = xinput2_get_cached_device_info(videodata, device_id); + SDL_XInput2DeviceInfo *devinfo = xinput2_get_cached_device_info(device_id); if (devinfo) { return devinfo; } @@ -486,8 +506,8 @@ static SDL_XInput2DeviceInfo *xinput2_get_device_info(SDL_VideoData *videodata, X11_XIFreeDeviceInfo(xidevinfo); devinfo->device_id = device_id; - devinfo->next = videodata->mouse_device_info; - videodata->mouse_device_info = devinfo; + devinfo->next = xinput2_device_info; + xinput2_device_info = devinfo; return devinfo; } @@ -516,7 +536,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie) // not pen stuff... if (hierev->info[i].flags & XISlaveRemoved) { - xinput2_remove_device_info(videodata, hierev->info[i].deviceid); + xinput2_remove_device_info(hierev->info[i].deviceid); } } videodata->xinput_hierarchy_changed = true; @@ -528,7 +548,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie) { const XIDeviceChangedEvent *dcev = (const XIDeviceChangedEvent *)cookie->data; if (dcev->reason == XISlaveSwitch) { - SDL_XInput2DeviceInfo *devinfo = xinput2_get_cached_device_info(videodata, dcev->deviceid); + SDL_XInput2DeviceInfo *devinfo = xinput2_get_cached_device_info(dcev->deviceid); if (devinfo) { xinput2_update_relative_valuators(devinfo, dcev->classes, dcev->num_classes); } @@ -676,7 +696,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie) #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_SCROLLINFO case XI_Enter: xinput2_reset_scrollable_valuators(); - xinput2_reset_relative_valuators(videodata); + xinput2_reset_relative_valuators(); break; #endif