src/joystick/SDL_joystick.c
changeset 10281 cb13d22b7f09
parent 9998 f67cf37e9cd4
equal deleted inserted replaced
10280:3134026517cb 10281:cb13d22b7f09
   495     return SDL_FALSE;
   495     return SDL_FALSE;
   496 }
   496 }
   497 
   497 
   498 /* These are global for SDL_sysjoystick.c and SDL_events.c */
   498 /* These are global for SDL_sysjoystick.c and SDL_events.c */
   499 
   499 
       
   500 void SDL_PrivateJoystickAdded(int device_index)
       
   501 {
       
   502 #if !SDL_EVENTS_DISABLED
       
   503     SDL_Event event;
       
   504 
       
   505     event.type = SDL_JOYDEVICEADDED;
       
   506 
       
   507     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   508         event.jdevice.which = device_index;
       
   509         if ( (SDL_EventOK == NULL) ||
       
   510              (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
       
   511             SDL_PushEvent(&event);
       
   512         }
       
   513     }
       
   514 #endif /* !SDL_EVENTS_DISABLED */
       
   515 }
       
   516 
       
   517 /*
       
   518  * If there is an existing add event in the queue, it needs to be modified
       
   519  * to have the right value for which, because the number of controllers in
       
   520  * the system is now one less.
       
   521  */
       
   522 static void UpdateEventsForDeviceRemoval()
       
   523 {
       
   524     int i, num_events;
       
   525     SDL_Event *events;
       
   526 
       
   527     num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
       
   528     if (num_events <= 0) {
       
   529         return;
       
   530     }
       
   531 
       
   532     events = SDL_stack_alloc(SDL_Event, num_events);
       
   533     if (!events) {
       
   534         return;
       
   535     }
       
   536 
       
   537     num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
       
   538     for (i = 0; i < num_events; ++i) {
       
   539         --events[i].jdevice.which;
       
   540     }
       
   541     SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
       
   542 
       
   543     SDL_stack_free(events);
       
   544 }
       
   545 
       
   546 void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
       
   547 {
       
   548 #if !SDL_EVENTS_DISABLED
       
   549     SDL_Event event;
       
   550 
       
   551     event.type = SDL_JOYDEVICEREMOVED;
       
   552 
       
   553     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   554         event.jdevice.which = device_instance;
       
   555         if ( (SDL_EventOK == NULL) ||
       
   556              (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
       
   557             SDL_PushEvent(&event);
       
   558         }
       
   559     }
       
   560 
       
   561     UpdateEventsForDeviceRemoval();
       
   562 #endif /* !SDL_EVENTS_DISABLED */
       
   563 }
       
   564 
   500 int
   565 int
   501 SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
   566 SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
   502 {
   567 {
   503     int posted;
   568     int posted;
   504 
   569