src/joystick/linux/SDL_sysjoystick.c
changeset 10226 cb13d22b7f09
parent 10225 3134026517cb
child 10595 9da2701eeb4a
equal deleted inserted replaced
10225:3134026517cb 10226:cb13d22b7f09
    40 #include "SDL_endian.h"
    40 #include "SDL_endian.h"
    41 #include "../SDL_sysjoystick.h"
    41 #include "../SDL_sysjoystick.h"
    42 #include "../SDL_joystick_c.h"
    42 #include "../SDL_joystick_c.h"
    43 #include "SDL_sysjoystick_c.h"
    43 #include "SDL_sysjoystick_c.h"
    44 
    44 
    45 /* !!! FIXME: move this somewhere else. */
       
    46 #if !SDL_EVENTS_DISABLED
       
    47 #include "../../events/SDL_events_c.h"
       
    48 #endif
       
    49 
       
    50 /* This isn't defined in older Linux kernel headers */
    45 /* This isn't defined in older Linux kernel headers */
    51 #ifndef SYN_DROPPED
    46 #ifndef SYN_DROPPED
    52 #define SYN_DROPPED 3
    47 #define SYN_DROPPED 3
    53 #endif
    48 #endif
    54 
    49 
   174     int fd = -1;
   169     int fd = -1;
   175     int isstick = 0;
   170     int isstick = 0;
   176     char namebuf[128];
   171     char namebuf[128];
   177     SDL_JoystickGUID guid;
   172     SDL_JoystickGUID guid;
   178     SDL_joylist_item *item;
   173     SDL_joylist_item *item;
   179 #if !SDL_EVENTS_DISABLED
       
   180     SDL_Event event;
       
   181 #endif
       
   182 
   174 
   183     if (path == NULL) {
   175     if (path == NULL) {
   184         return -1;
   176         return -1;
   185     }
   177     }
   186 
   178 
   237     }
   229     }
   238 
   230 
   239     /* Need to increment the joystick count before we post the event */
   231     /* Need to increment the joystick count before we post the event */
   240     ++numjoysticks;
   232     ++numjoysticks;
   241 
   233 
   242     /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
   234     SDL_PrivateJoystickAdded(numjoysticks - 1);
   243 #if !SDL_EVENTS_DISABLED
       
   244     event.type = SDL_JOYDEVICEADDED;
       
   245 
       
   246     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   247         event.jdevice.which = (numjoysticks - 1);
       
   248         if ( (SDL_EventOK == NULL) ||
       
   249              (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
       
   250             SDL_PushEvent(&event);
       
   251         }
       
   252     }
       
   253 #endif /* !SDL_EVENTS_DISABLED */
       
   254 
   235 
   255     return numjoysticks;
   236     return numjoysticks;
   256 }
   237 }
   257 
   238 
   258 #if SDL_USE_LIBUDEV
   239 #if SDL_USE_LIBUDEV
   260 static int
   241 static int
   261 MaybeRemoveDevice(const char *path)
   242 MaybeRemoveDevice(const char *path)
   262 {
   243 {
   263     SDL_joylist_item *item;
   244     SDL_joylist_item *item;
   264     SDL_joylist_item *prev = NULL;
   245     SDL_joylist_item *prev = NULL;
   265 #if !SDL_EVENTS_DISABLED
       
   266     SDL_Event event;
       
   267 #endif
       
   268 
   246 
   269     if (path == NULL) {
   247     if (path == NULL) {
   270         return -1;
   248         return -1;
   271     }
   249     }
   272 
   250 
   288             }
   266             }
   289 
   267 
   290             /* Need to decrement the joystick count before we post the event */
   268             /* Need to decrement the joystick count before we post the event */
   291             --numjoysticks;
   269             --numjoysticks;
   292 
   270 
   293             /* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
   271             SDL_PrivateJoystickRemoved(item->device_instance);
   294 #if !SDL_EVENTS_DISABLED
       
   295             event.type = SDL_JOYDEVICEREMOVED;
       
   296 
       
   297             if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   298 				SDL_Event peeped;
       
   299 
       
   300 				/* If there is an existing add event in the queue, it
       
   301 				 * needs to be modified to have the right value for which,
       
   302 				 * because the number of controllers in the system is now
       
   303 				 * one less.
       
   304 				 */
       
   305 				if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) {
       
   306 					peeped.jdevice.which--;
       
   307 					SDL_PushEvent(&peeped);
       
   308 				}
       
   309 
       
   310                 event.jdevice.which = item->device_instance;
       
   311                 if ( (SDL_EventOK == NULL) ||
       
   312                      (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
       
   313                     SDL_PushEvent(&event);
       
   314                 }
       
   315             }
       
   316 #endif /* !SDL_EVENTS_DISABLED */
       
   317 
   272 
   318             SDL_free(item->path);
   273             SDL_free(item->path);
   319             SDL_free(item->name);
   274             SDL_free(item->name);
   320             SDL_free(item);
   275             SDL_free(item);
   321             return retval;
   276             return retval;