Report joystick added/removed events even if we don't have udev.
T. Joseph Carter As discussed (possibly to death), the Linux joystick driver does not actually report events for added or removed joysticks when you haven't got udev support. We simply cannot know about removed joysticks without udev. But we can (and we should) report adding them. This brings the legacy case in line with pretty much the rest of SDL's joystick drivers.
This commit is contained in:
parent
daf4ca1ac2
commit
e63559cffd
1 changed files with 35 additions and 34 deletions
|
@ -138,8 +138,6 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
|
||||||
#if SDL_USE_LIBUDEV
|
#if SDL_USE_LIBUDEV
|
||||||
void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
|
void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
|
||||||
{
|
{
|
||||||
int instance;
|
|
||||||
|
|
||||||
if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
|
if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -147,41 +145,11 @@ void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, cons
|
||||||
switch( udev_type )
|
switch( udev_type )
|
||||||
{
|
{
|
||||||
case SDL_UDEV_DEVICEADDED:
|
case SDL_UDEV_DEVICEADDED:
|
||||||
instance = MaybeAddDevice(devpath);
|
MaybeAddDevice(devpath);
|
||||||
if (instance != -1) {
|
|
||||||
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
|
|
||||||
#if !SDL_EVENTS_DISABLED
|
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_JOYDEVICEADDED;
|
|
||||||
|
|
||||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
|
||||||
event.jdevice.which = instance;
|
|
||||||
if ( (SDL_EventOK == NULL) ||
|
|
||||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
|
||||||
SDL_PushEvent(&event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !SDL_EVENTS_DISABLED */
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_UDEV_DEVICEREMOVED:
|
case SDL_UDEV_DEVICEREMOVED:
|
||||||
instance = MaybeRemoveDevice(devpath);
|
MaybeRemoveDevice(devpath);
|
||||||
if (instance != -1) {
|
|
||||||
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
|
|
||||||
#if !SDL_EVENTS_DISABLED
|
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_JOYDEVICEREMOVED;
|
|
||||||
|
|
||||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
|
||||||
event.jdevice.which = instance;
|
|
||||||
if ( (SDL_EventOK == NULL) ||
|
|
||||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
|
||||||
SDL_PushEvent(&event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !SDL_EVENTS_DISABLED */
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -202,6 +170,9 @@ MaybeAddDevice(const char *path)
|
||||||
char namebuf[128];
|
char namebuf[128];
|
||||||
SDL_JoystickGUID guid;
|
SDL_JoystickGUID guid;
|
||||||
SDL_joylist_item *item;
|
SDL_joylist_item *item;
|
||||||
|
#if !SDL_EVENTS_DISABLED
|
||||||
|
SDL_Event event;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -259,6 +230,19 @@ MaybeAddDevice(const char *path)
|
||||||
SDL_joylist_tail = item;
|
SDL_joylist_tail = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
|
||||||
|
#if !SDL_EVENTS_DISABLED
|
||||||
|
event.type = SDL_JOYDEVICEADDED;
|
||||||
|
|
||||||
|
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||||
|
event.jdevice.which = numjoysticks;
|
||||||
|
if ( (SDL_EventOK == NULL) ||
|
||||||
|
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !SDL_EVENTS_DISABLED */
|
||||||
|
|
||||||
return numjoysticks++;
|
return numjoysticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +253,9 @@ MaybeRemoveDevice(const char *path)
|
||||||
{
|
{
|
||||||
SDL_joylist_item *item;
|
SDL_joylist_item *item;
|
||||||
SDL_joylist_item *prev = NULL;
|
SDL_joylist_item *prev = NULL;
|
||||||
|
#if !SDL_EVENTS_DISABLED
|
||||||
|
SDL_Event event;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -290,6 +277,20 @@ MaybeRemoveDevice(const char *path)
|
||||||
if (item == SDL_joylist_tail) {
|
if (item == SDL_joylist_tail) {
|
||||||
SDL_joylist_tail = prev;
|
SDL_joylist_tail = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
|
||||||
|
#if !SDL_EVENTS_DISABLED
|
||||||
|
event.type = SDL_JOYDEVICEREMOVED;
|
||||||
|
|
||||||
|
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||||
|
event.jdevice.which = item->device_instance;
|
||||||
|
if ( (SDL_EventOK == NULL) ||
|
||||||
|
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !SDL_EVENTS_DISABLED */
|
||||||
|
|
||||||
SDL_free(item->path);
|
SDL_free(item->path);
|
||||||
SDL_free(item->name);
|
SDL_free(item->name);
|
||||||
SDL_free(item);
|
SDL_free(item);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue