X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJDeviceController.m;h=0b0fe9289c30fa9267f6335e3eed9ff410b206e0;hp=2f1736b4b2e2ebd12fc50943fadb83ebc369b664;hb=6dddafbcf505939751ddb2d66ffb586d150aaaa8;hpb=bda2aa3a8897f574b97c0bd125e84374087017a9 diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 2f1736b..0b0fe92 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -81,9 +81,9 @@ [_continuousOutputsTick invalidate]; } -- (void)expandRecursive:(id )pathElement { +- (void)expandRecursive:(NJInputPathElement *)pathElement { if (pathElement) { - [self expandRecursive:pathElement.base]; + [self expandRecursive:pathElement.parent]; [outlineView expandItem:pathElement]; } } @@ -138,13 +138,15 @@ [self expandRecursive:handler]; [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[outlineView rowForItem:handler]] byExtendingSelection: NO]; - [outputController focusKey]; + if (!self.simulatingEvents) + [outputController focusKey]; } - (void)hidManager:(NJHIDManager *)manager valueChanged:(IOHIDValueRef)value fromDevice:(IOHIDDeviceRef)device { - if (self.translatingEvents) { + if (self.simulatingEvents + && !NSApplication.sharedApplication.isActive) { [self runOutputForDevice:device value:value]; } else { [self showOutputForDevice:device value:value]; @@ -222,7 +224,7 @@ static int findAvailableIndex(NSArray *list, NJDevice *dev) { didPresentSelector:nil contextInfo:nil]; } - self.translatingEvents = NO; + self.simulatingEvents = NO; if (manager.running) [self hidManagerDidStart:manager]; else @@ -250,34 +252,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.parent) ? 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"]; @@ -285,17 +287,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]; @@ -306,24 +308,24 @@ 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"]; } -- (void)setTranslatingEvents:(BOOL)translatingEvents { - if (translatingEvents != _translatingEvents) { - _translatingEvents = translatingEvents; - NSInteger state = translatingEvents ? NSOnState : NSOffState; +- (void)setSimulatingEvents:(BOOL)simulatingEvents { + if (simulatingEvents != _simulatingEvents) { + _simulatingEvents = simulatingEvents; + NSInteger state = simulatingEvents ? NSOnState : NSOffState; translatingEventsButton.state = state; - NSString *name = translatingEvents - ? NJEventTranslationActivated - : NJEventTranslationDeactivated; + NSString *name = simulatingEvents + ? NJEventSimulationStarted + : NJEventSimulationStopped; [NSNotificationCenter.defaultCenter postNotificationName:name object:self]; - if (!translatingEvents && !NSApplication.sharedApplication.isActive) + if (!simulatingEvents && !NSApplication.sharedApplication.isActive) [self stopHid]; else [self startHid]; @@ -343,12 +345,12 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } - (void)stopHidIfDisabled:(NSNotification *)application { - if (!self.translatingEvents) + if (!self.simulatingEvents) [self stopHid]; } -- (IBAction)translatingEventsChanged:(NSButton *)sender { - self.translatingEvents = sender.state == NSOnState; +- (IBAction)simulatingEventsChanged:(NSButton *)sender { + self.simulatingEvents = sender.state == NSOnState; } @end