X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJDeviceController.m;h=6fc4d13267a2ee060745f1a6dd600e9d67cd3d84;hp=610c07b5a4f29c925572a850209c3b4e3d6bfc9d;hb=79b05c3cf1c75bc4f7078acde43aaf4215c6408a;hpb=402a1b679ced5422e46c7a5caeecc45e5ed878db diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 610c07b..6fc4d13 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -81,7 +81,7 @@ [_continuousOutputsTick invalidate]; } -- (void)expandRecursive:(id )pathElement { +- (void)expandRecursive:(NJInputPathElement *)pathElement { if (pathElement) { [self expandRecursive:pathElement.base]; [outlineView expandItem:pathElement]; @@ -210,11 +210,23 @@ static int findAvailableIndex(NSArray *list, NJDevice *dev) { } - (void)hidManager:(NJHIDManager *)manager didError:(NSError *)error { - [outlineView.window presentError:error - modalForWindow:outlineView.window - delegate:nil - didPresentSelector:nil - contextInfo:nil]; + // Since the error shows the window, it can trigger another attempt + // to re-open the HID manager, which will also probably fail and error, + // so don't bother repeating ourselves. + if (!outlineView.window.attachedSheet) { + [NSApplication.sharedApplication activateIgnoringOtherApps:YES]; + [outlineView.window makeKeyAndOrderFront:nil]; + [outlineView.window presentError:error + modalForWindow:outlineView.window + delegate:nil + didPresentSelector:nil + contextInfo:nil]; + } + self.translatingEvents = NO; + if (manager.running) + [self hidManagerDidStart:manager]; + else + [self hidManagerDidStop:manager]; } - (void)hidManagerDidStart:(NJHIDManager *)manager { @@ -238,34 +250,34 @@ static int findAvailableIndex(NSArray *list, NJDevice *dev) { } - (NJInput *)selectedInput { - id item = [outlineView itemAtRow:outlineView.selectedRow]; - return (!item.children && item.base) ? item : nil; + NJInputPathElement *item = [outlineView itemAtRow:outlineView.selectedRow]; + return (NJInput *)((!item.children && item.base) ? item : nil); } - (NSInteger)outlineView:(NSOutlineView *)outlineView - numberOfChildrenOfItem:(id )item { + numberOfChildrenOfItem:(NJInputPathElement *)item { return item ? item.children.count : _devices.count; } - (BOOL)outlineView:(NSOutlineView *)outlineView - isItemExpandable:(id )item { + isItemExpandable:(NJInputPathElement *)item { return item ? [[item children] count] > 0: YES; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index - ofItem:(id )item { + ofItem:(NJInputPathElement *)item { return item ? item.children[index] : _devices[index]; } - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn - byItem:(id )item { + byItem:(NJInputPathElement *)item { return item ? item.name : @"root"; } - (void)outlineViewSelectionDidChange:(NSNotification *)notification { - id item = [outlineView itemAtRow:outlineView.selectedRow]; + NJInputPathElement *item = [outlineView itemAtRow:outlineView.selectedRow]; if (item) [NSUserDefaults.standardUserDefaults setObject:item.uid forKey:@"selected input"]; @@ -273,17 +285,17 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } - (BOOL)outlineView:(NSOutlineView *)outlineView - isGroupItem:(id )item { + isGroupItem:(NJInputPathElement *)item { return [item isKindOfClass:NJDevice.class]; } - (BOOL)outlineView:(NSOutlineView *)outlineView_ - shouldSelectItem:(id )item { + shouldSelectItem:(NJInputPathElement *)item { return ![self outlineView:outlineView_ isGroupItem:item]; } - (void)outlineViewItemDidExpand:(NSNotification *)notification { - id item = notification.userInfo[@"NSObject"]; + NJInputPathElement *item = notification.userInfo[@"NSObject"]; NSString *uid = item.uid; if (![_expanded containsObject:uid]) [_expanded addObject:uid]; @@ -294,7 +306,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } - (void)outlineViewItemDidCollapse:(NSNotification *)notification { - id item = notification.userInfo[@"NSObject"]; + NJInputPathElement *item = notification.userInfo[@"NSObject"]; [_expanded removeObject:item.uid]; [NSUserDefaults.standardUserDefaults setObject:_expanded forKey:@"expanded rows"]; @@ -313,7 +325,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn if (!translatingEvents && !NSApplication.sharedApplication.isActive) [self stopHid]; - else if (translatingEvents || NSApplication.sharedApplication.isActive) + else [self startHid]; } }