- JoystickController *controller = (__bridge JoystickController *)ctx;
- IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender);
-
- Joystick *js = [controller findJoystickByRef:device];
- if([(ApplicationController *)[[NSApplication sharedApplication] delegate] active]) {
- JSAction* mainAction = [js actionForEvent: value];
- if(!mainAction)
- return;
-
- [mainAction notifyEvent: value];
- NSArray* children = [mainAction children];
- if(!children)
- children = @[mainAction];
- for(id subaction in children) {
- Target* target = [[controller->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: controller];
- }
- else {
- [target untrigger: controller];
- }
- [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 (![controller.runningTargets containsObject:target]) {
- [[controller runningTargets] addObject: target];
- }
- }
+ JoystickController *controller = (__bridge JoystickController *)ctx;
+ IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender);
+
+ if (controller.sendingRealEvents) {
+ [controller runTargetForDevice:device value:value];
+ } else if ([NSApplication sharedApplication].mainWindow.isVisible) {
+ [controller showTargetForDevice:device value:value];
+ }
+}
+
+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;