src/joystick/windows/SDL_windowsjoystick.c
changeset 10281 cb13d22b7f09
parent 10147 ddbdc9c1b92f
equal deleted inserted replaced
10280:3134026517cb 10281:cb13d22b7f09
    40 #include "SDL_events.h"
    40 #include "SDL_events.h"
    41 #include "SDL_hints.h"
    41 #include "SDL_hints.h"
    42 #include "SDL_joystick.h"
    42 #include "SDL_joystick.h"
    43 #include "../SDL_sysjoystick.h"
    43 #include "../SDL_sysjoystick.h"
    44 #include "../../thread/SDL_systhread.h"
    44 #include "../../thread/SDL_systhread.h"
    45 #if !SDL_EVENTS_DISABLED
       
    46 #include "../../events/SDL_events_c.h"
       
    47 #endif
       
    48 #include "../../core/windows/SDL_windows.h"
    45 #include "../../core/windows/SDL_windows.h"
    49 #if !defined(__WINRT__)
    46 #if !defined(__WINRT__)
    50 #include <dbt.h>
    47 #include <dbt.h>
    51 #endif
    48 #endif
    52 
    49 
   325 /* detect any new joysticks being inserted into the system */
   322 /* detect any new joysticks being inserted into the system */
   326 void
   323 void
   327 SDL_SYS_JoystickDetect()
   324 SDL_SYS_JoystickDetect()
   328 {
   325 {
   329     JoyStick_DeviceData *pCurList = NULL;
   326     JoyStick_DeviceData *pCurList = NULL;
   330 #if !SDL_EVENTS_DISABLED
       
   331     SDL_Event event;
       
   332 #endif
       
   333 
   327 
   334     /* only enum the devices if the joystick thread told us something changed */
   328     /* only enum the devices if the joystick thread told us something changed */
   335     if (!s_bDeviceAdded && !s_bDeviceRemoved) {
   329     if (!s_bDeviceAdded && !s_bDeviceRemoved) {
   336         return;  /* thread hasn't signaled, nothing to do right now. */
   330         return;  /* thread hasn't signaled, nothing to do right now. */
   337     }
   331     }
   359             SDL_XINPUT_MaybeRemoveDevice(pCurList->XInputUserId);
   353             SDL_XINPUT_MaybeRemoveDevice(pCurList->XInputUserId);
   360         } else {
   354         } else {
   361             SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
   355             SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
   362         }
   356         }
   363 
   357 
   364 #if !SDL_EVENTS_DISABLED
   358         SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
   365         SDL_zero(event);
       
   366         event.type = SDL_JOYDEVICEREMOVED;
       
   367 
       
   368         if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   369             event.jdevice.which = pCurList->nInstanceID;
       
   370             if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
       
   371                 SDL_PushEvent(&event);
       
   372             }
       
   373         }
       
   374 #endif /* !SDL_EVENTS_DISABLED */
       
   375 
   359 
   376         pListNext = pCurList->pNext;
   360         pListNext = pCurList->pNext;
   377         SDL_free(pCurList->joystickname);
   361         SDL_free(pCurList->joystickname);
   378         SDL_free(pCurList);
   362         SDL_free(pCurList);
   379         pCurList = pListNext;
   363         pCurList = pListNext;
   390                     SDL_XINPUT_MaybeAddDevice(pNewJoystick->XInputUserId);
   374                     SDL_XINPUT_MaybeAddDevice(pNewJoystick->XInputUserId);
   391                 } else {
   375                 } else {
   392                     SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
   376                     SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
   393                 }
   377                 }
   394 
   378 
   395 #if !SDL_EVENTS_DISABLED
   379                 SDL_PrivateJoystickAdded(device_index);
   396                 SDL_zero(event);
   380 
   397                 event.type = SDL_JOYDEVICEADDED;
       
   398 
       
   399                 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   400                     event.jdevice.which = device_index;
       
   401                     if ((!SDL_EventOK) || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
       
   402                         SDL_PushEvent(&event);
       
   403                     }
       
   404                 }
       
   405 #endif /* !SDL_EVENTS_DISABLED */
       
   406                 pNewJoystick->send_add_event = SDL_FALSE;
   381                 pNewJoystick->send_add_event = SDL_FALSE;
   407             }
   382             }
   408             device_index++;
   383             device_index++;
   409             pNewJoystick = pNewJoystick->pNext;
   384             pNewJoystick = pNewJoystick->pNext;
   410         }
   385         }