Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Updated the removal code to iterate over all joystick add messages instead of just the first one.
This commit is contained in:
parent
c69bce6774
commit
ad1bfea5a0
9 changed files with 114 additions and 217 deletions
|
@ -42,11 +42,6 @@
|
|||
#include "../SDL_joystick_c.h"
|
||||
#include "SDL_sysjoystick_c.h"
|
||||
|
||||
/* !!! FIXME: move this somewhere else. */
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#endif
|
||||
|
||||
/* This isn't defined in older Linux kernel headers */
|
||||
#ifndef SYN_DROPPED
|
||||
#define SYN_DROPPED 3
|
||||
|
@ -176,9 +171,6 @@ MaybeAddDevice(const char *path)
|
|||
char namebuf[128];
|
||||
SDL_JoystickGUID guid;
|
||||
SDL_joylist_item *item;
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
SDL_Event event;
|
||||
#endif
|
||||
|
||||
if (path == NULL) {
|
||||
return -1;
|
||||
|
@ -239,18 +231,7 @@ MaybeAddDevice(const char *path)
|
|||
/* Need to increment the joystick count before we post the event */
|
||||
++numjoysticks;
|
||||
|
||||
/* !!! 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 - 1);
|
||||
if ( (SDL_EventOK == NULL) ||
|
||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
#endif /* !SDL_EVENTS_DISABLED */
|
||||
SDL_PrivateJoystickAdded(numjoysticks - 1);
|
||||
|
||||
return numjoysticks;
|
||||
}
|
||||
|
@ -262,9 +243,6 @@ MaybeRemoveDevice(const char *path)
|
|||
{
|
||||
SDL_joylist_item *item;
|
||||
SDL_joylist_item *prev = NULL;
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
SDL_Event event;
|
||||
#endif
|
||||
|
||||
if (path == NULL) {
|
||||
return -1;
|
||||
|
@ -290,30 +268,7 @@ MaybeRemoveDevice(const char *path)
|
|||
/* Need to decrement the joystick count before we post the event */
|
||||
--numjoysticks;
|
||||
|
||||
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
event.type = SDL_JOYDEVICEREMOVED;
|
||||
|
||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||
SDL_Event peeped;
|
||||
|
||||
/* If there is an existing add event in the queue, it
|
||||
* needs to be modified to have the right value for which,
|
||||
* because the number of controllers in the system is now
|
||||
* one less.
|
||||
*/
|
||||
if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) {
|
||||
peeped.jdevice.which--;
|
||||
SDL_PushEvent(&peeped);
|
||||
}
|
||||
|
||||
event.jdevice.which = item->device_instance;
|
||||
if ( (SDL_EventOK == NULL) ||
|
||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
#endif /* !SDL_EVENTS_DISABLED */
|
||||
SDL_PrivateJoystickRemoved(item->device_instance);
|
||||
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue