BOOL active;
}
-@synthesize jsController;
-@synthesize targetController;
-@synthesize configsController;
-
- (void)didSwitchApplication:(NSNotification *)notification {
NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey];
[self.configsController activateConfigForProcess:currentApp.localizedName];
- (void)chooseConfig:(id)sender {
int idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex];
Config *chosen = self.configsController.configs[idx];
- [configsController activateConfig:chosen];
+ [_configsController activateConfig:chosen];
}
@end
@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;
#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;
- (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];
-(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 {
}
- (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];
@"entries": cfgEntries,
}];
}
- NSUInteger current = currentConfig ? [configs indexOfObject:currentConfig] : 0;
+ NSUInteger current = _currentConfig ? [_configs indexOfObject:_currentConfig] : 0;
return @{ @"configurationList": ary,
@"selectedConfiguration": @(current) };
}
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]];
}
}
@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;
}
- (NSString *)uid {
- return [NSString stringWithFormat:@"%@~%@", [self.base uid], self.name];
+ return [NSString stringWithFormat:@"%@~%@", [_base uid], _name];
}
- (void)notifyEvent:(IOHIDValueRef)value {
- (id)initWithName:(NSString *)name idx:(int)idx max:(int)max;
-@property (assign) int max;
-
@end
#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];
}
}
- (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
@interface Joystick : NSObject
-@property (assign) int vendorId;
-@property (assign) int productId;
@property (assign) int index;
@property (copy) NSString *productName;
@property (assign) IOHIDDeviceRef device;
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 {
}
- (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;
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;
}
- (Joystick *)findJoystickByRef:(IOHIDDeviceRef)device {
- for (Joystick *js in joysticks)
+ for (Joystick *js in _joysticks)
if (js.device == device)
return js;
return nil;
}
- (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 {
}
- (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 {
IBOutlet TargetController *targetController;
}
-@property (copy) NSString* descr;
@property (assign) int vk;
@property (readonly) BOOL hasKey;
@property (assign) BOOL enabled;
BOOL enabled;
}
-@synthesize descr;
-
- (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) {
self.alignment = NSCenterTextAlignment;
}
- (BOOL)acceptsFirstResponder {
- return enabled;
+ return self.enabled;
}
- (BOOL)becomeFirstResponder {
- (void)setVk:(int)key {
vk = key;
- descr = [KeyInputTextView stringForKeyCode:key];
- [self setStringValue:descr];
+ [self setStringValue:[KeyInputTextView stringForKeyCode:key]];
if (self.hasKey)
[targetController keyChanged];
}
- (void)keyDown:(NSEvent *)evt {
if (!evt.isARepeat) {
self.vk = evt.keyCode;
- [[self window] makeFirstResponder:nil];
+ [self.window makeFirstResponder:nil];
}
}
BOOL running;
}
-@synthesize magnitude;
-
+ (NSString *)serializationCode {
[self doesNotRecognizeSelector:_cmd];
return nil;
}
- (NSDictionary *)serialize {
- return self.config
- ? @{ @"type": @"cfg", @"name": self.config.name }
+ return _config
+ ? @{ @"type": @"cfg", @"name": _config.name }
: @{};
}
}
- (void)trigger {
- [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:self.config];
+ [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:_config];
}
@end
@interface TargetKeyboard : Target
@property (assign) CGKeyCode vk;
-@property (readonly) NSString* descr;
@end
@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
@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
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);
}
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);
}
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
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;
@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
CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
kCGScrollEventUnitLine,
1,
- self.amount);
+ _amount);
CGEventPost(kCGHIDEventTap, scroll);
CFRelease(scroll);
}