src/joystick/iphoneos/SDL_sysjoystick.m
changeset 10281 cb13d22b7f09
parent 9998 f67cf37e9cd4
child 10283 9a277db2806d
equal deleted inserted replaced
10280:3134026517cb 10281:cb13d22b7f09
    29 #include "SDL_joystick.h"
    29 #include "SDL_joystick.h"
    30 #include "SDL_hints.h"
    30 #include "SDL_hints.h"
    31 #include "SDL_stdinc.h"
    31 #include "SDL_stdinc.h"
    32 #include "../SDL_sysjoystick.h"
    32 #include "../SDL_sysjoystick.h"
    33 #include "../SDL_joystick_c.h"
    33 #include "../SDL_joystick_c.h"
    34 
       
    35 #if !SDL_EVENTS_DISABLED
       
    36 #include "../../events/SDL_events_c.h"
       
    37 #endif
       
    38 
    34 
    39 #import <CoreMotion/CoreMotion.h>
    35 #import <CoreMotion/CoreMotion.h>
    40 
    36 
    41 #ifdef SDL_JOYSTICK_MFI
    37 #ifdef SDL_JOYSTICK_MFI
    42 #import <GameController/GameController.h>
    38 #import <GameController/GameController.h>
   125 
   121 
   126 static void
   122 static void
   127 SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
   123 SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
   128 {
   124 {
   129     SDL_JoystickDeviceItem *device = deviceList;
   125     SDL_JoystickDeviceItem *device = deviceList;
   130 #if !SDL_EVENTS_DISABLED
       
   131     SDL_Event event;
       
   132 #endif
       
   133 
   126 
   134     while (device != NULL) {
   127     while (device != NULL) {
   135         if (device->controller == controller) {
   128         if (device->controller == controller) {
   136             return;
   129             return;
   137         }
   130         }
   170         lastdevice->next = device;
   163         lastdevice->next = device;
   171     }
   164     }
   172 
   165 
   173     ++numjoysticks;
   166     ++numjoysticks;
   174 
   167 
   175 #if !SDL_EVENTS_DISABLED
   168     SDL_PrivateJoystickAdded(numjoysticks - 1);
   176     event.type = SDL_JOYDEVICEADDED;
       
   177 
       
   178     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   179         event.jdevice.which = numjoysticks - 1;
       
   180         if ((SDL_EventOK == NULL) ||
       
   181             (*SDL_EventOK)(SDL_EventOKParam, &event)) {
       
   182             SDL_PushEvent(&event);
       
   183         }
       
   184     }
       
   185 #endif /* !SDL_EVENTS_DISABLED */
       
   186 }
   169 }
   187 
   170 
   188 static SDL_JoystickDeviceItem *
   171 static SDL_JoystickDeviceItem *
   189 SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
   172 SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
   190 {
   173 {
   191     SDL_JoystickDeviceItem *prev = NULL;
   174     SDL_JoystickDeviceItem *prev = NULL;
   192     SDL_JoystickDeviceItem *next = NULL;
   175     SDL_JoystickDeviceItem *next = NULL;
   193     SDL_JoystickDeviceItem *item = deviceList;
   176     SDL_JoystickDeviceItem *item = deviceList;
   194 #if !SDL_EVENTS_DISABLED
       
   195     SDL_Event event;
       
   196 #endif
       
   197 
   177 
   198     if (device == NULL) {
   178     if (device == NULL) {
   199         return NULL;
   179         return NULL;
   200     }
   180     }
   201 
   181 
   232     }
   212     }
   233 #endif /* SDL_JOYSTICK_MFI */
   213 #endif /* SDL_JOYSTICK_MFI */
   234 
   214 
   235     --numjoysticks;
   215     --numjoysticks;
   236 
   216 
   237 #if !SDL_EVENTS_DISABLED
   217 	SDL_PrivateJoystickRemoved(device->instance_id);
   238     event.type = SDL_JOYDEVICEREMOVED;
       
   239 
       
   240     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   241         event.jdevice.which = device->instance_id;
       
   242         if ((SDL_EventOK == NULL) ||
       
   243             (*SDL_EventOK)(SDL_EventOKParam, &event)) {
       
   244             SDL_PushEvent(&event);
       
   245         }
       
   246     }
       
   247 #endif /* !SDL_EVENTS_DISABLED */
       
   248 
   218 
   249     SDL_free(device->name);
   219     SDL_free(device->name);
   250     SDL_free(device);
   220     SDL_free(device);
   251 
   221 
   252     return next;
   222     return next;