X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=JoystickController.m;h=97ca74b6e10e7e42d86264d70ae50f66e2408c5a;hp=6acc5456a197e8c8d377f492bcdef9cbaa0b0216;hb=60710a84810cfbfa39ada9a9e44f61ceb2f144c5;hpb=ada313d7e31dd509c8c7be01f364c9a2ad9860d4 diff --git a/JoystickController.m b/JoystickController.m index 6acc545..97ca74b 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -7,7 +7,6 @@ #import "JoystickController.h" -#import "ApplicationController.h" #import "Config.h" #import "ConfigsController.h" #import "Joystick.h" @@ -21,14 +20,9 @@ NSMutableArray *runningTargets; } -@synthesize joysticks; -@synthesize selectedAction; -@synthesize frontWindowOnly; -@synthesize mouseLoc; - - (id)init { if ((self = [super init])) { - joysticks = [[NSMutableArray alloc] initWithCapacity:16]; + _joysticks = [[NSMutableArray alloc] initWithCapacity:16]; runningTargets = [[NSMutableArray alloc] initWithCapacity:32]; } return self; @@ -65,7 +59,7 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender); Joystick *js = [controller findJoystickByRef:device]; - if (((ApplicationController *)[NSApplication sharedApplication].delegate).active) { + if (controller.sendingRealEvents) { JSAction *mainAction = [js actionForEvent:value]; [mainAction notifyEvent:value]; NSArray *children = mainAction.children ? mainAction.children : mainAction ? @[mainAction] : @[]; @@ -78,7 +72,6 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa } } else if ([NSApplication sharedApplication].isActive && [NSApplication sharedApplication].mainWindow.isVisible) { - // joysticks not active, use it to select stuff JSAction *handler = [js handlerForEvent:value]; if (!handler) return; @@ -113,7 +106,7 @@ static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDevi } - (Joystick *)findJoystickByRef:(IOHIDDeviceRef)device { - for (Joystick *js in joysticks) + for (Joystick *js in _joysticks) if (js.device == device) return js; return nil; @@ -134,7 +127,6 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD for (Target *target in [runningTargets copy]) { if (![target update:self]) { [runningTargets removeObject:target]; - NSLog(@"Removing action, now running %lu.", runningTargets.count); } } if (!runningTargets.count) { @@ -158,7 +150,17 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD IOHIDManagerSetDeviceMatchingMultiple(hidManager, (__bridge CFArrayRef)criteria); IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); // FIXME: If an error happens, report it! + IOReturn ret = IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); + if (ret != kIOReturnSuccess) { + [[NSAlert alertWithMessageText:@"Input devices are unavailable" + defaultButton:nil + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. " + @"Input may not be correctly detected or mapped.", + ret] + runModal]; + } IOHIDManagerRegisterDeviceMatchingCallback(hidManager, add_callback, (__bridge void *)self); IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void *)self); @@ -174,7 +176,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD } - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { - return item ? [[item children] count] : [joysticks count]; + return item ? [[item children] count] : _joysticks.count; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { @@ -182,7 +184,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD } - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item { - return item ? [item children][index] : joysticks[index]; + return item ? [item children][index] : _joysticks[index]; } - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { @@ -191,9 +193,8 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD return [item name]; } -- (void)outlineViewSelectionDidChange: (NSNotification*) notification { - [targetController reset]; - [targetController load]; +- (void)outlineViewSelectionDidChange:(NSNotification *)notification { + [targetController loadCurrent]; } @end