-void input_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDValueRef value) {
- JoystickController* self = (JoystickController*)inContext;
- IOHIDDeviceRef device = IOHIDQueueGetDevice((IOHIDQueueRef) inSender);
-
- Joystick* js = [self findJoystickByRef: device];
- if([[[NSApplication sharedApplication] delegate] active]) {
- // for reals
- JSAction* mainAction = [js actionForEvent: value];
- if(!mainAction)
- return;
-
- [mainAction notifyEvent: value];
- NSArray* subactions = [mainAction subActions];
- if(!subactions)
- subactions = [NSArray arrayWithObject:mainAction];
- for(id subaction in subactions) {
- Target* target = [[self->configsController currentConfig] getTargetForAction:subaction];
- if(!target)
- continue;
- /* target application? doesn't seem to be any need since we are only active when it's in front */
- /* might be required for some strange actions */
- if ([target running] != [subaction active]) {
- if ([subaction active]) {
- [target trigger: self];
- }
- else {
- [target untrigger: self];
- }
- [target setRunning: [subaction active]];
- }
-
- if ([mainAction isKindOfClass: [JSActionAnalog class]]) {
- double realValue = [(JSActionAnalog*)mainAction getRealValue: IOHIDValueGetIntegerValue(value)];
- [target setInputValue: realValue];
-
- // Add to list of running targets
- if ([target isContinuous] && [target running]) {
- if (!objInArray([self runningTargets], target)) {
- [[self runningTargets] addObject: target];
- }
- }
+static int findAvailableIndex(NSArray *list, Joystick *js) {
+ for (int index = 1; ; index++) {
+ BOOL available = YES;
+ for (Joystick *used in list) {
+ if ([used.productName isEqualToString:js.productName] && used.index == index) {
+ available = NO;
+ break;