Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/sdl/patches/0008-fix-linux-joycon-serial-num.patch
21807 views
1
diff --git a/thirdparty/sdl/core/linux/SDL_udev.c b/thirdparty/sdl/core/linux/SDL_udev.c
2
index fbf2ff0444..d9e7e11849 100644
3
--- a/thirdparty/sdl/core/linux/SDL_udev.c
4
+++ b/thirdparty/sdl/core/linux/SDL_udev.c
5
@@ -277,6 +277,43 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *pr
6
return true;
7
}
8
9
+bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
10
+{
11
+ struct stat statbuf;
12
+ char type;
13
+ struct udev_device *dev;
14
+ const char *val;
15
+
16
+ if (!_this) {
17
+ return false;
18
+ }
19
+
20
+ if (stat(device_path, &statbuf) < 0) {
21
+ return false;
22
+ }
23
+
24
+ if (S_ISBLK(statbuf.st_mode)) {
25
+ type = 'b';
26
+ } else if (S_ISCHR(statbuf.st_mode)) {
27
+ type = 'c';
28
+ } else {
29
+ return false;
30
+ }
31
+
32
+ dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
33
+ if (!dev) {
34
+ return false;
35
+ }
36
+
37
+ val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
38
+ if (val) {
39
+ *serial = val;
40
+ return true;
41
+ }
42
+
43
+ return false;
44
+}
45
+
46
void SDL_UDEV_UnloadLibrary(void)
47
{
48
if (!_this) {
49
diff --git a/thirdparty/sdl/core/linux/SDL_udev.h b/thirdparty/sdl/core/linux/SDL_udev.h
50
index 50bed36248..05b79342cd 100644
51
--- a/thirdparty/sdl/core/linux/SDL_udev.h
52
+++ b/thirdparty/sdl/core/linux/SDL_udev.h
53
@@ -104,6 +104,7 @@ extern bool SDL_UDEV_LoadLibrary(void);
54
extern void SDL_UDEV_Poll(void);
55
extern bool SDL_UDEV_Scan(void);
56
extern bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class);
57
+extern bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial);
58
extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
59
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
60
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
61
diff --git a/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c b/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
62
index ea73821c06..70fed1cf57 100644
63
--- a/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
64
+++ b/thirdparty/sdl/joystick/linux/SDL_sysjoystick.c
65
@@ -1587,6 +1587,13 @@ static bool LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
66
item_sensor->hwdata = joystick->hwdata;
67
}
68
69
+ #ifdef SDL_USE_LIBUDEV
70
+ const char *serial = NULL;
71
+ if (SDL_UDEV_GetProductSerial(item->path, &serial)) {
72
+ joystick->serial = SDL_strdup(serial);
73
+ }
74
+ #endif
75
+
76
// mark joystick as fresh and ready
77
joystick->hwdata->fresh = true;
78
79
80