-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([(ApplicationController *)[[NSApplication sharedApplication] delegate] active]) {
- // for reals
- JSAction* mainAction = [js actionForEvent: value];
- if(!mainAction)
- return;
-
- [mainAction notifyEvent: value];
- NSArray* subactions = [mainAction subActions];
- if(!subactions)
- subactions = @[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]];
+static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) {
+ 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 ? mainAction.children : @[mainAction];
+ for (JSAction *subaction in children) {
+ Target *target = [[controller->configsController currentConfig] getTargetForAction:subaction];
+ if (!target)
+ continue;
+ // TODO: Can we just trigger based on setRunning:?
+ if (target.running != subaction.active) {
+ if (subaction.active)
+ [target trigger:controller];
+ else
+ [target untrigger:controller];
+ target.running = subaction.active;