ApplicationController* self = (ApplicationController*)userData;
NSDictionary* currentApp = [[NSWorkspace sharedWorkspace] activeApplication];
ProcessSerialNumber psn;
- psn.lowLongOfPSN = [[currentApp objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
- psn.highLongOfPSN = [[currentApp objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
- [self->configsController applicationSwitchedTo: [currentApp objectForKey:@"NSApplicationName"] withPsn: psn];
+ psn.lowLongOfPSN = [currentApp[@"NSApplicationProcessSerialNumberLow"] longValue];
+ psn.highLongOfPSN = [currentApp[@"NSApplicationProcessSerialNumberHigh"] longValue];
+ [self->configsController applicationSwitchedTo: currentApp[@"NSApplicationName"] withPsn: psn];
return noErr;
}
Config* current = [configsController currentConfig];
NSArray* configs = [configsController configs];
for(int i=0; i<[configs count]; i++)
- [[dockMenuBase itemAtIndex: (2+i)] setState: (([configs objectAtIndex:i] == current) ? YES : NO)];
+ [[dockMenuBase itemAtIndex: (2+i)] setState: ((configs[i] == current) ? YES : NO)];
}
-(void) chooseConfig: (id) sender {
- [configsController activateConfig: [[configsController configs] objectAtIndex: ([dockMenuBase indexOfItem: sender]-2)] forApplication: NULL];
+ [configsController activateConfig: [configsController configs][([dockMenuBase indexOfItem: sender]-2)] forApplication: NULL];
}
@end
[entries setValue:target forKey: [jsa stringify]];
}
-(Target*) getTargetForAction: (id) jsa {
- return [entries objectForKey: [jsa stringify]];
+ return entries[[jsa stringify]];
}
@end
-(IBAction) removePressed: (id)sender {
// save changes first
[tableView reloadData];
- Config* current_config = [configs objectAtIndex: [tableView selectedRow]];
+ Config* current_config = configs[[tableView selectedRow]];
if([current_config protect])
return;
[configs removeObjectAtIndex: [tableView selectedRow]];
// remove all "switch to configuration" actions
for(int i=0; i<[configs count]; i++) {
- NSMutableDictionary* entries = [(Config*)[configs objectAtIndex:i] entries];
+ NSMutableDictionary* entries = [(Config*)configs[i] entries];
for(id key in entries) {
- Target* target = (Target*) [entries objectForKey: key];
+ Target* target = (Target*) entries[key];
if([target isKindOfClass: [TargetConfig class]] && [(TargetConfig*)target config] == current_config)
[entries removeObjectForKey: key];
}
-(void)tableViewSelectionDidChange:(NSNotification*) notify {
if (tableView.selectedRow < configs.count)
- [self activateConfig: (Config*)[configs objectAtIndex:[tableView selectedRow]] forApplication: NULL];
+ [self activateConfig: (Config*)configs[[tableView selectedRow]] forApplication: NULL];
}
-(id) tableView: (NSTableView*)view objectValueForTableColumn: (NSTableColumn*) column row: (int) index {
NSParameterAssert(index >= 0 && index < [configs count]);
- return [[configs objectAtIndex: index] name];
+ return [configs[index] name];
}
-(void) tableView: (NSTableView*) view setObjectValue:obj forTableColumn:(NSTableColumn*) col row: (int)index {
NSParameterAssert(index >= 0 && index < [configs count]);
/* ugly hack so stringification doesn't fail */
NSString* newName = [(NSString*)obj stringByReplacingOccurrencesOfString: @"~" withString: @""];
- [(Config*)[configs objectAtIndex: index] setName: newName];
+ [(Config*)configs[index] setName: newName];
[targetController refreshConfigsPreservingSelection:YES];
[tableView reloadData];
[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
}
-(BOOL)tableView: (NSTableView*)view shouldEditTableColumn: (NSTableColumn*) column row: (int) index {
- return ![[configs objectAtIndex: index] protect];
+ return ![configs[index] protect];
}
-(Config*) currentConfig {
NSMutableArray* ary = [[NSMutableArray alloc] init];
for(Config* config in configs) {
NSMutableDictionary* cfgInfo = [[NSMutableDictionary alloc] init];
- [cfgInfo setObject:[config name] forKey:@"name"];
+ cfgInfo[@"name"] = [config name];
NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] init];
for(id key in [config entries]) {
- [cfgEntries setObject:[[[config entries]objectForKey:key]stringify] forKey: key];
+ cfgEntries[key] = [[config entries][key]stringify];
}
- [cfgInfo setObject: cfgEntries forKey: @"entries"];
+ cfgInfo[@"entries"] = cfgEntries;
[ary addObject: cfgInfo];
}
- [envelope setObject: ary forKey: @"configurationList"];
- [envelope setObject: [NSNumber numberWithInt: [configs indexOfObject: [self currentNeutralConfig] ] ] forKey: @"selectedIndex"];
+ envelope[@"configurationList"] = ary;
+ envelope[@"selectedIndex"] = [NSNumber numberWithInt: [configs indexOfObject: [self currentNeutralConfig] ] ];
return envelope;
}
-(void) loadAllFrom: (NSDictionary*) envelope{
if(envelope == NULL)
return;
- NSArray* ary = [envelope objectForKey: @"configurationList"];
+ NSArray* ary = envelope[@"configurationList"];
NSMutableArray* newConfigs = [[NSMutableArray alloc] init];
// have to do two passes in case config1 refers to config2 via a TargetConfig
for(int i=0; i<[ary count]; i++) {
Config* cfg = [[Config alloc] init];
- [cfg setName: [[ary objectAtIndex:i] objectForKey:@"name"]];
+ [cfg setName: ary[i][@"name"]];
[newConfigs addObject: cfg];
}
- [[configs objectAtIndex:0] setProtect: YES];
+ [configs[0] setProtect: YES];
for(int i=0; i<[ary count]; i++) {
- NSDictionary* dict = [[ary objectAtIndex:i] objectForKey:@"entries"];
+ NSDictionary* dict = ary[i][@"entries"];
for(id key in dict) {
- [[[newConfigs objectAtIndex:i] entries]
- setObject: [Target unstringify: [dict objectForKey: key] withConfigList: newConfigs]
- forKey: key];
+ [newConfigs[i] entries][key] = [Target unstringify: dict[key] withConfigList: newConfigs];
}
}
currentConfig = NULL;
[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
- int index = [[envelope objectForKey: @"selectedIndex"] intValue];
+ int index = [envelope[@"selectedIndex"] intValue];
if (index < configs.count)
- [self activateConfig: [configs objectAtIndex:index] forApplication: NULL];
+ [self activateConfig: configs[index] forApplication: NULL];
}
-(void) applicationSwitchedTo: (NSString*) name withPsn: (ProcessSerialNumber) psn {
for(int i=0; i<[configs count]; i++) {
- Config* cfg = [configs objectAtIndex:i];
+ Config* cfg = configs[i];
if([[cfg name] isEqualToString: name]) {
[self activateConfig: cfg forApplication: &psn];
return;
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
GCC_PREFIX_HEADER = Enjoy_Prefix.pch;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
- MACOSX_DEPLOYMENT_TARGET = 10.6;
+ MACOSX_DEPLOYMENT_TARGET = 10.6.8;
PRODUCT_NAME = Enjoy;
};
name = Debug;
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
GCC_PREFIX_HEADER = Enjoy_Prefix.pch;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
- MACOSX_DEPLOYMENT_TARGET = 10.6;
+ MACOSX_DEPLOYMENT_TARGET = 10.6.8;
PRODUCT_NAME = Enjoy;
};
name = Release;
- (id) initWithIndex: (int)newIndex {
if(self = [super init]) {
- subActions = [NSArray arrayWithObjects:
- [[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
+ subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
[[SubAction alloc] initWithIndex: 1 name: @"High" base: self],
- [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self],
- nil
- ];
+ [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self]];
[subActions retain];
index = newIndex;
name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
}
-(id) findSubActionForValue: (IOHIDValueRef) value {
- if ([[subActions objectAtIndex: 2] active]) {
- return [subActions objectAtIndex: 2]; // TODO?
+ if ([subActions[2] active]) {
+ return subActions[2]; // TODO?
}
//Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];
double parsed = [self getRealValue: raw];
if(parsed < -0.3) // fixed?!
- return [subActions objectAtIndex: 0];
+ return subActions[0];
else if(parsed > 0.3)
- return [subActions objectAtIndex: 1];
+ return subActions[1];
return NULL;
}
-(void) notifyEvent: (IOHIDValueRef) value {
// Analog action is always active
- [[subActions objectAtIndex: 2] setActive: true];
+ [subActions[2] setActive: true];
int raw = IOHIDValueGetIntegerValue(value);
double parsed = [self getRealValue: raw];
- [[subActions objectAtIndex: 0] setActive: (parsed < -0.3)];
- [[subActions objectAtIndex: 1] setActive: (parsed > 0.3)];
+ [subActions[0] setActive: (parsed < -0.3)];
+ [subActions[1] setActive: (parsed > 0.3)];
}
-(double) getRealValue: (int)value {
- (id) init {
if(self = [super init]) {
- subActions = [NSArray arrayWithObjects:
- [[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
+ subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
[[SubAction alloc] initWithIndex: 1 name: @"Down" base: self],
[[SubAction alloc] initWithIndex: 2 name: @"Left" base: self],
- [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self],
- nil
- ];
+ [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self]];
[subActions retain];
name = @"Hat switch";
}
if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 7) {
// 8-way
switch(parsed) {
- case 0: return [subActions objectAtIndex: 0];
- case 4: return [subActions objectAtIndex: 1];
- case 6: return [subActions objectAtIndex: 2];
- case 2: return [subActions objectAtIndex: 3];
+ case 0: return subActions[0];
+ case 4: return subActions[1];
+ case 6: return subActions[2];
+ case 2: return subActions[3];
}
} else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 8) {
// 8-way
switch(parsed) {
- case 1: return [subActions objectAtIndex: 0];
- case 5: return [subActions objectAtIndex: 1];
- case 7: return [subActions objectAtIndex: 2];
- case 3: return [subActions objectAtIndex: 3];
+ case 1: return subActions[0];
+ case 5: return subActions[1];
+ case 7: return subActions[2];
+ case 3: return subActions[3];
}
} else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 3) {
// 4-way
switch(parsed) {
- case 0: return [subActions objectAtIndex: 0];
- case 2: return [subActions objectAtIndex: 1];
- case 3: return [subActions objectAtIndex: 2];
- case 1: return [subActions objectAtIndex: 3];
+ case 0: return subActions[0];
+ case 2: return subActions[1];
+ case 3: return subActions[2];
+ case 1: return subActions[3];
}
} else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 4) {
// 4-way
switch(parsed) {
- case 1: return [subActions objectAtIndex: 0];
- case 3: return [subActions objectAtIndex: 1];
- case 4: return [subActions objectAtIndex: 2];
- case 2: return [subActions objectAtIndex: 3];
+ case 1: return subActions[0];
+ case 3: return subActions[1];
+ case 4: return subActions[2];
+ case 2: return subActions[3];
}
}
return NULL;
}
BOOL* activeSubactions = (size == 8) ? active_eightway : active_fourway;
for(int i=0; i<4; i++)
- [[subActions objectAtIndex: i] setActive: activeSubactions[parsed * 4 + i]];
+ [subActions[i] setActive: activeSubactions[parsed * 4 + i]];
}
@end
int axes = 0;
for(int i=0; i<[elements count]; i++) {
- IOHIDElementRef element = (IOHIDElementRef)[elements objectAtIndex: i];
+ IOHIDElementRef element = (IOHIDElementRef)elements[i];
int type = IOHIDElementGetType(element);
int usage = IOHIDElementGetUsage(element);
int usagePage = IOHIDElementGetUsagePage(element);
- (JSAction*) findActionByCookie: (void*) cookie {
for(int i=0; i<[children count]; i++)
- if([[children objectAtIndex:i]cookie] == cookie)
- return (JSAction*)[children objectAtIndex:i];
+ if([children[i]cookie] == cookie)
+ return (JSAction*)children[i];
return NULL;
}
-(void) finalize {
for(int i=0; i<[joysticks count]; i++) {
- [[joysticks objectAtIndex:i] invalidate];
+ [joysticks[i] invalidate];
}
IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone);
CFRelease(hidManager);
static NSMutableDictionary* create_criterion( UInt32 inUsagePage, UInt32 inUsage )
{
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- [dict setObject: [NSNumber numberWithInt: inUsagePage] forKey: (NSString*)CFSTR(kIOHIDDeviceUsagePageKey)];
- [dict setObject: [NSNumber numberWithInt: inUsage] forKey: (NSString*)CFSTR(kIOHIDDeviceUsageKey)];
+ dict[(NSString*)CFSTR(kIOHIDDeviceUsagePageKey)] = [NSNumber numberWithInt: inUsagePage];
+ dict[(NSString*)CFSTR(kIOHIDDeviceUsageKey)] = [NSNumber numberWithInt: inUsage];
return dict;
}
[mainAction notifyEvent: value];
NSArray* subactions = [mainAction subActions];
if(!subactions)
- subactions = [NSArray arrayWithObject:mainAction];
+ subactions = @[mainAction];
for(id subaction in subactions) {
Target* target = [[self->configsController currentConfig] getTargetForAction:subaction];
if(!target)
for(int index=0;;index++) {
available = YES;
for(int i=0; i<[list count]; i++) {
- js2 = [list objectAtIndex: i];
+ js2 = list[i];
if([js2 vendorId] == [js vendorId] && [js2 productId] == [js productId] && [js index] == index) {
available = NO;
break;
-(void) setup {
hidManager = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone);
- NSArray *criteria = [NSArray arrayWithObjects:
- create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick),
+ NSArray *criteria = @[create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick),
create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad),
- create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController),
- //create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard),
- nil];
+ create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController)];
IOHIDManagerSetDeviceMatchingMultiple(hidManager, (CFArrayRef)criteria);
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
if(item == nil)
- return [joysticks objectAtIndex: index];
+ return joysticks[index];
if([item isKindOfClass: [Joystick class]])
- return [[item children] objectAtIndex: index];
+ return [item children][index];
if([item isKindOfClass: [JSAction class]])
- return [[item subActions] objectAtIndex:index];
+ return [item subActions][index];
return NULL;
}
+(Target*) unstringify: (NSString*) str withConfigList: (NSArray*) configs {
NSArray* components = [str componentsSeparatedByString:@"~"];
NSParameterAssert([components count]);
- NSString* typeTag = [components objectAtIndex:0];
+ NSString* typeTag = components[0];
if([typeTag isEqualToString:@"key"])
return [TargetKeyboard unstringifyImpl:components];
if([typeTag isEqualToString:@"cfg"])
+(TargetConfig*) unstringifyImpl: (NSArray*) comps withConfigList: (NSArray*) configs {
NSParameterAssert([comps count] == 2);
- NSString* name = [comps objectAtIndex: 1];
+ NSString* name = comps[1];
TargetConfig* target = [[TargetConfig alloc] init];
for(int i=0; i<[configs count]; i++)
- if([[[configs objectAtIndex:i] name] isEqualToString:name]) {
- [target setConfig: [configs objectAtIndex:i]];
+ if([[configs[i] name] isEqualToString:name]) {
+ [target setConfig: configs[i]];
return target;
}
NSLog(@"Warning: couldn't find matching config to restore from: %@",name);
case 2:
{
TargetConfig* c = [[TargetConfig alloc] init];
- [c setConfig: [[configsController configs] objectAtIndex: [configPopup indexOfSelectedItem]]];
+ [c setConfig: [configsController configs][[configPopup indexOfSelectedItem]]];
return c;
}
case 3: {
NSArray* configs = [configsController configs];
[configPopup removeAllItems];
for(int i=0; i<[configs count]; i++) {
- [configPopup addItemWithTitle: [[configs objectAtIndex:i]name]];
+ [configPopup addItemWithTitle: [configs[i]name]];
}
if(preserve)
[configPopup selectItemAtIndex:initialIndex];
+(TargetKeyboard*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 3);
TargetKeyboard* target = [[TargetKeyboard alloc] init];
- [target setVk: [[comps objectAtIndex:1] integerValue]];
- [target setDescr: [comps objectAtIndex:2]];
+ [target setVk: [comps[1] integerValue]];
+ [target setDescr: comps[2]];
return target;
}
+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 2);
TargetMouseBtn* target = [[TargetMouseBtn alloc] init];
- [target setWhich: [[comps objectAtIndex:1] integerValue]];
+ [target setWhich: [comps[1] integerValue]];
return target;
}
+(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 2);
TargetMouseMove* target = [[TargetMouseMove alloc] init];
- [target setDir: [[comps objectAtIndex:1] integerValue]];
+ [target setDir: [comps[1] integerValue]];
return target;
}
+(TargetMouseScroll*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 2);
TargetMouseScroll* target = [[TargetMouseScroll alloc] init];
- [target setHowMuch: [[comps objectAtIndex:1] integerValue]];
+ [target setHowMuch: [comps[1] integerValue]];
return target;
}