From: Joe Wreschnig Date: Thu, 28 Feb 2013 21:11:53 +0000 (+0100) Subject: Clean up a bunch of properties; remove unused ones, use automatic ones where possible... X-Git-Tag: version-1.0~83 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=15a3aec049658f4a1c3c6e8c9f8a549fb8de0782;p=enjoyable.git Clean up a bunch of properties; remove unused ones, use automatic ones where possible, bypass them internally for serialization for speed. --- diff --git a/ApplicationController.m b/ApplicationController.m index aa51eeb..6a34916 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -16,10 +16,6 @@ BOOL active; } -@synthesize jsController; -@synthesize targetController; -@synthesize configsController; - - (void)didSwitchApplication:(NSNotification *)notification { NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey]; [self.configsController activateConfigForProcess:currentApp.localizedName]; @@ -81,6 +77,6 @@ - (void)chooseConfig:(id)sender { int idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex]; Config *chosen = self.configsController.configs[idx]; - [configsController activateConfig:chosen]; + [_configsController activateConfig:chosen]; } @end diff --git a/ConfigsController.h b/ConfigsController.h index a408d3b..e616e1e 100644 --- a/ConfigsController.h +++ b/ConfigsController.h @@ -10,22 +10,19 @@ @class TargetController; @interface ConfigsController : NSObject { - IBOutlet NSButton *removeButton; - IBOutlet NSTableView *tableView; - IBOutlet TargetController *targetController; + IBOutlet NSButton *removeButton; + IBOutlet NSTableView *tableView; + IBOutlet TargetController *targetController; } +@property (readonly) Config *currentConfig; +@property (readonly) NSArray *configs; + - (IBAction)addPressed:(id)sender; - (IBAction)removePressed:(id)sender; - (void)activateConfig:(Config *)config; - (void)activateConfigForProcess:(NSString *)processName; -- (NSDictionary *)dumpAll; -- (void)loadAllFrom:(NSDictionary*) dict; - -@property (readonly) Config *currentConfig; -@property (readonly) NSArray *configs; - - (void)save; - (void)load; diff --git a/ConfigsController.m b/ConfigsController.m index 4227d43..769fabd 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -14,25 +14,22 @@ #import "TargetController.h" @implementation ConfigsController { - NSMutableArray *configs; + NSMutableArray *_configs; Config *manualConfig; } -@synthesize currentConfig; -@synthesize configs; - - (id)init { if ((self = [super init])) { - configs = [[NSMutableArray alloc] init]; - currentConfig = [[Config alloc] initWithName:@"(default)"]; - manualConfig = currentConfig; - [configs addObject:currentConfig]; + _configs = [[NSMutableArray alloc] init]; + _currentConfig = [[Config alloc] initWithName:@"(default)"]; + manualConfig = _currentConfig; + [_configs addObject:_currentConfig]; } return self; } - (Config *)objectForKeyedSubscript:(NSString *)name { - for (Config *config in configs) + for (Config *config in _configs) if ([name isEqualToString:config.name]) return config; return nil; @@ -47,37 +44,37 @@ - (void)activateConfig:(Config *)config { if (!config) config = manualConfig; - if (currentConfig == config) + if (_currentConfig == config) return; manualConfig = config; - currentConfig = config; + _currentConfig = config; [targetController reset]; - [removeButton setEnabled:configs[0] != config]; + [removeButton setEnabled:_configs[0] != config]; [targetController load]; [(ApplicationController *)[[NSApplication sharedApplication] delegate] configChanged]; - [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[configs indexOfObject:config]] byExtendingSelection:NO]; + [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[_configs indexOfObject:config]] byExtendingSelection:NO]; } - (IBAction)addPressed:(id)sender { Config *newConfig = [[Config alloc] initWithName:@"Untitled"]; - [configs addObject:newConfig]; + [_configs addObject:newConfig]; [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; [tableView reloadData]; - [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:configs.count - 1] byExtendingSelection:NO]; - [tableView editColumn:0 row:[configs count] - 1 withEvent:nil select:YES]; + [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_configs.count - 1] byExtendingSelection:NO]; + [tableView editColumn:0 row:[_configs count] - 1 withEvent:nil select:YES]; } - (IBAction)removePressed:(id)sender { if (tableView.selectedRow == 0) return; - Config *toRemove = configs[tableView.selectedRow]; - [configs removeObjectAtIndex:tableView.selectedRow]; + Config *toRemove = _configs[tableView.selectedRow]; + [_configs removeObjectAtIndex:tableView.selectedRow]; - if (toRemove == currentConfig) - currentConfig = configs[0]; + if (toRemove == _currentConfig) + _currentConfig = _configs[0]; if (toRemove == manualConfig) - manualConfig = configs[0]; + manualConfig = _configs[0]; [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; [tableView reloadData]; @@ -85,22 +82,22 @@ -(void)tableViewSelectionDidChange:(NSNotification *)notify { if (tableView.selectedRow >= 0) - [self activateConfig:configs[tableView.selectedRow]]; + [self activateConfig:_configs[tableView.selectedRow]]; } - (id)tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)column row:(int)index { - return [configs[index] name]; + return [_configs[index] name]; } - (void)tableView:(NSTableView *)view setObjectValue:(NSString *)obj forTableColumn:(NSTableColumn *)col row:(int)index { - [(Config *)configs[index] setName:obj]; + [(Config *)_configs[index] setName:obj]; [targetController refreshConfigsPreservingSelection:YES]; [tableView reloadData]; [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; } - (int)numberOfRowsInTableView:(NSTableView*)table { - return [configs count]; + return [_configs count]; } - (BOOL)tableView:(NSTableView *)view shouldEditTableColumn:(NSTableColumn *)column row:(int)index { @@ -117,8 +114,8 @@ } - (NSDictionary *)dumpAll { - NSMutableArray *ary = [[NSMutableArray alloc] initWithCapacity:configs.count]; - for (Config *config in configs) { + NSMutableArray *ary = [[NSMutableArray alloc] initWithCapacity:_configs.count]; + for (Config *config in _configs) { NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] initWithCapacity:config.entries.count]; for (id key in config.entries) cfgEntries[key] = [config.entries[key] serialize]; @@ -126,7 +123,7 @@ @"entries": cfgEntries, }]; } - NSUInteger current = currentConfig ? [configs indexOfObject:currentConfig] : 0; + NSUInteger current = _currentConfig ? [_configs indexOfObject:_currentConfig] : 0; return @{ @"configurationList": ary, @"selectedConfiguration": @(current) }; } @@ -153,10 +150,10 @@ int current = [envelope[@"selectedConfiguration"] unsignedIntValue]; if (current >= newConfigs.count) current = 0; - configs = newConfigs; + _configs = newConfigs; [tableView reloadData]; [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; - [self activateConfig:configs[current]]; + [self activateConfig:_configs[current]]; } } diff --git a/JSAction.m b/JSAction.m index 0216e58..6903c56 100644 --- a/JSAction.m +++ b/JSAction.m @@ -9,12 +9,6 @@ @implementation JSAction -@synthesize cookie; -@synthesize children; -@synthesize base; -@synthesize name; -@synthesize active; - - (id)initWithName:(NSString *)newName base:(JSAction *)newBase { if ((self = [super init])) { self.name = newName; @@ -28,7 +22,7 @@ } - (NSString *)uid { - return [NSString stringWithFormat:@"%@~%@", [self.base uid], self.name]; + return [NSString stringWithFormat:@"%@~%@", [_base uid], _name]; } - (void)notifyEvent:(IOHIDValueRef)value { diff --git a/JSActionButton.h b/JSActionButton.h index c4ba063..927606d 100644 --- a/JSActionButton.h +++ b/JSActionButton.h @@ -12,6 +12,4 @@ - (id)initWithName:(NSString *)name idx:(int)idx max:(int)max; -@property (assign) int max; - @end diff --git a/JSActionButton.m b/JSActionButton.m index 12449ce..c74c0e2 100644 --- a/JSActionButton.m +++ b/JSActionButton.m @@ -8,17 +8,14 @@ #import "JSActionButton.h" @implementation JSActionButton { - BOOL active; + int _max; } -@synthesize max; -@synthesize active; - -- (id)initWithName:(NSString *)name_ idx:(int)idx max:(int)max_ { +- (id)initWithName:(NSString *)name idx:(int)idx max:(int)max { if ((self = [super init])) { - self.max = max_; - if (name_.length) - self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name_]; + _max = max; + if (name.length) + self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name]; else self.name = [NSString stringWithFormat:@"Button %d", idx]; } @@ -26,11 +23,11 @@ } - (id)findSubActionForValue:(IOHIDValueRef)val { - return (IOHIDValueGetIntegerValue(val) == max) ? self : nil; + return (IOHIDValueGetIntegerValue(val) == _max) ? self : nil; } - (void)notifyEvent:(IOHIDValueRef)value { - active = IOHIDValueGetIntegerValue(value) == max; + self.active = IOHIDValueGetIntegerValue(value) == _max; } @end diff --git a/Joystick.h b/Joystick.h index 2aea487..1c254a7 100644 --- a/Joystick.h +++ b/Joystick.h @@ -10,8 +10,6 @@ @interface Joystick : NSObject -@property (assign) int vendorId; -@property (assign) int productId; @property (assign) int index; @property (copy) NSString *productName; @property (assign) IOHIDDeviceRef device; diff --git a/Joystick.m b/Joystick.m index ae278b3..35b40c5 100644 --- a/Joystick.m +++ b/Joystick.m @@ -60,28 +60,24 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) { return children; } -@implementation Joystick - -@synthesize vendorId; -@synthesize productId; -@synthesize productName; -@synthesize index; -@synthesize device; -@synthesize children; +@implementation Joystick { + int vendorId; + int productId; +} - (id)initWithDevice:(IOHIDDeviceRef)dev { if ((self = [super init])) { self.device = dev; self.productName = (__bridge NSString *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductKey)); - self.vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; - self.productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; + vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; + productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; self.children = ActionsForElement(dev, self); } return self; } - (NSString *)name { - return [NSString stringWithFormat:@"%@ #%d", productName, index]; + return [NSString stringWithFormat:@"%@ #%d", _productName, _index]; } - (id)base { @@ -89,11 +85,11 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) { } - (NSString *)uid { - return [NSString stringWithFormat: @"%d:%d:%d", vendorId, productId, index]; + return [NSString stringWithFormat: @"%d:%d:%d", vendorId, productId, _index]; } - (JSAction *)findActionByCookie:(void *)cookie { - for (JSAction *child in children) + for (JSAction *child in _children) if (child.cookie == cookie) return child; return nil; diff --git a/JoystickController.m b/JoystickController.m index 13db938..84366ef 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -20,15 +20,9 @@ NSMutableArray *runningTargets; } -@synthesize joysticks; -@synthesize selectedAction; -@synthesize frontWindowOnly; -@synthesize mouseLoc; -@synthesize sendingRealEvents; - - (id)init { if ((self = [super init])) { - joysticks = [[NSMutableArray alloc] initWithCapacity:16]; + _joysticks = [[NSMutableArray alloc] initWithCapacity:16]; runningTargets = [[NSMutableArray alloc] initWithCapacity:32]; } return self; @@ -112,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; @@ -183,7 +177,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 { @@ -191,7 +185,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 { diff --git a/KeyInputTextView.h b/KeyInputTextView.h index a3cd4ff..485af1c 100644 --- a/KeyInputTextView.h +++ b/KeyInputTextView.h @@ -13,7 +13,6 @@ IBOutlet TargetController *targetController; } -@property (copy) NSString* descr; @property (assign) int vk; @property (readonly) BOOL hasKey; @property (assign) BOOL enabled; diff --git a/KeyInputTextView.m b/KeyInputTextView.m index 7bda696..1bb7952 100644 --- a/KeyInputTextView.m +++ b/KeyInputTextView.m @@ -14,8 +14,6 @@ BOOL enabled; } -@synthesize descr; - - (id)initWithFrame:(NSRect)frameRect { if ((self = [super initWithFrame:frameRect])) { self.alignment = NSCenterTextAlignment; @@ -157,7 +155,7 @@ } - (BOOL)acceptsFirstResponder { - return enabled; + return self.enabled; } - (BOOL)becomeFirstResponder { @@ -176,8 +174,7 @@ - (void)setVk:(int)key { vk = key; - descr = [KeyInputTextView stringForKeyCode:key]; - [self setStringValue:descr]; + [self setStringValue:[KeyInputTextView stringForKeyCode:key]]; if (self.hasKey) [targetController keyChanged]; } @@ -189,7 +186,7 @@ - (void)keyDown:(NSEvent *)evt { if (!evt.isARepeat) { self.vk = evt.keyCode; - [[self window] makeFirstResponder:nil]; + [self.window makeFirstResponder:nil]; } } diff --git a/Target.m b/Target.m index 35af184..36da021 100644 --- a/Target.m +++ b/Target.m @@ -18,8 +18,6 @@ BOOL running; } -@synthesize magnitude; - + (NSString *)serializationCode { [self doesNotRecognizeSelector:_cmd]; return nil; diff --git a/TargetConfig.m b/TargetConfig.m index 1fef7a9..e9c374e 100644 --- a/TargetConfig.m +++ b/TargetConfig.m @@ -18,8 +18,8 @@ } - (NSDictionary *)serialize { - return self.config - ? @{ @"type": @"cfg", @"name": self.config.name } + return _config + ? @{ @"type": @"cfg", @"name": _config.name } : @{}; } @@ -37,7 +37,7 @@ } - (void)trigger { - [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:self.config]; + [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:_config]; } @end diff --git a/TargetKeyboard.h b/TargetKeyboard.h index 6599332..a4766e1 100644 --- a/TargetKeyboard.h +++ b/TargetKeyboard.h @@ -11,6 +11,5 @@ @interface TargetKeyboard : Target @property (assign) CGKeyCode vk; -@property (readonly) NSString* descr; @end diff --git a/TargetKeyboard.m b/TargetKeyboard.m index 0d0583e..a3a0b51 100644 --- a/TargetKeyboard.m +++ b/TargetKeyboard.m @@ -11,37 +11,31 @@ @implementation TargetKeyboard -@synthesize vk; - + (NSString *)serializationCode { return @"key"; } - (NSDictionary *)serialize { - return @{ @"type": @"key", @"key": @(self.vk) }; + return @{ @"type": @"key", @"key": @(_vk) }; } + (Target *)targetDeserialize:(NSDictionary *)serialization withConfigs:(NSArray *)configs { - TargetKeyboard *target = [[TargetKeyboard alloc] init]; + TargetKeyboard *target = [[TargetKeyboard alloc] init]; target.vk = [serialization[@"key"] intValue]; - return target; -} - --(void) trigger { - CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, vk, YES); - CGEventPost(kCGHIDEventTap, keyDown); - CFRelease(keyDown); + return target; } --(void) untrigger { - CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, vk, NO); - CGEventPost(kCGHIDEventTap, keyUp); - CFRelease(keyUp); +- (void)trigger { + CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, _vk, YES); + CGEventPost(kCGHIDEventTap, keyDown); + CFRelease(keyDown); } -- (NSString *)descr { - return [KeyInputTextView stringForKeyCode:self.vk]; +- (void)untrigger { + CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, _vk, NO); + CGEventPost(kCGHIDEventTap, keyUp); + CFRelease(keyUp); } @end diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 2f56f7e..3efb88a 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -10,14 +10,12 @@ @implementation TargetMouseBtn -@synthesize button; - + (NSString *)serializationCode { return @"mbtn"; } - (NSDictionary *)serialize { - return @{ @"type": @"mbtn", @"button": @(self.button) }; + return @{ @"type": @"mbtn", @"button": @(_button) }; } + (Target *)targetDeserialize:(NSDictionary *)serialization @@ -31,11 +29,11 @@ NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - button); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } @@ -44,11 +42,11 @@ NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - button); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } diff --git a/TargetMouseMove.m b/TargetMouseMove.m index 893bbb6..8bbfd42 100644 --- a/TargetMouseMove.m +++ b/TargetMouseMove.m @@ -18,14 +18,12 @@ return YES; } -@synthesize axis; - + (NSString *)serializationCode { return @"mmove"; } - (NSDictionary *)serialize { - return @{ @"type": @"mmove", @"axis": @(self.axis) }; + return @{ @"type": @"mmove", @"axis": @(_axis) }; } + (Target *)targetDeserialize:(NSDictionary *)serialization @@ -57,7 +55,7 @@ if ([jc frontWindowOnly]) speed = 12.f; float dx = 0.f, dy = 0.f; - if (axis == 0) + if (_axis == 0) dx = self.magnitude * speed; else dy = self.magnitude * speed; diff --git a/TargetMouseScroll.m b/TargetMouseScroll.m index 4d6f409..6986004 100644 --- a/TargetMouseScroll.m +++ b/TargetMouseScroll.m @@ -10,14 +10,12 @@ @implementation TargetMouseScroll -@synthesize amount; - + (NSString *)serializationCode { return @"mscroll"; } - (NSDictionary *)serialize { - return @{ @"type": @"mscroll", @"amount": @(self.amount) }; + return @{ @"type": @"mscroll", @"amount": @(_amount) }; } + (Target *)targetDeserialize:(NSDictionary *)serialization @@ -30,7 +28,7 @@ CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, 1, - self.amount); + _amount); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); }