void SDL_SYS_JoystickDetect() { #if SDL_USE_LIBUDEV struct udev_device *dev = NULL; const char *devnode = NULL; const char *action = NULL; const char *val = NULL; while (HotplugUpdateAvailable()) { dev = UDEV_udev_monitor_receive_device(udev_mon); if (dev == NULL) { break; } val = UDEV_udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK"); if ((!val) || (SDL_strcmp(val, "1") != 0)) { continue; } action = UDEV_udev_device_get_action(dev); devnode = UDEV_udev_device_get_devnode(dev); if (SDL_strcmp(action, "add") == 0) { const int device_index = MaybeAddDevice(devnode); if (device_index != -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 = device_index; if ( (SDL_EventOK == NULL) || (*SDL_EventOK) (SDL_EventOKParam, &event) ) { SDL_PushEvent(&event); } } #endif // !SDL_EVENTS_DISABLED } } else if (SDL_strcmp(action, "remove") == 0) { const int inst = MaybeRemoveDevice(devnode); if (inst != -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 = inst; if ( (SDL_EventOK == NULL) || (*SDL_EventOK) (SDL_EventOKParam, &event) ) { SDL_PushEvent(&event); } } #endif // !SDL_EVENTS_DISABLED } } UDEV_udev_device_unref(dev); } #endif }
void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, SDL_UDEV_deviceclass udev_class, const char *devpath) { int instance; if (devpath == NULL || udev_class != SDL_UDEV_DEVICE_JOYSTICK) { return; } switch( udev_type ) { case SDL_UDEV_DEVICEADDED: instance = 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; case SDL_UDEV_DEVICEREMOVED: instance = 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; default: break; } }
void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath) { if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) { return; } switch( udev_type ) { case SDL_UDEV_DEVICEADDED: MaybeAddDevice(devpath); break; case SDL_UDEV_DEVICEREMOVED: MaybeRemoveDevice(devpath); break; default: break; } }