Post active mapping changes through notification center rather than to the applicatio...
[enjoyable.git] / TargetMouseBtn.m
index 2f56f7e..951715d 100644 (file)
@@ -3,21 +3,18 @@
 //  Enjoy
 //
 //  Created by Yifeng Huang on 7/27/12.
-//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
 //
 
 #import "TargetMouseBtn.h"
 
 @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
 }
 
 -(void) trigger {
-    NSRect screenRect = [[NSScreen mainScreen] frame];
-    NSInteger height = screenRect.size.height;
-    NSPoint mouseLoc = [NSEvent mouseLocation];
-    CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
+    CGFloat height = NSScreen.mainScreen.frame.size.height;
+    NSPoint mouseLoc = NSEvent.mouseLocation;
+    CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
                                                CGPointMake(mouseLoc.x, height - mouseLoc.y),
-                                               button);
+                                               _button);
     CGEventPost(kCGHIDEventTap, click);
     CFRelease(click);
 }
 
 -(void) untrigger {
-    NSRect screenRect = [[NSScreen mainScreen] frame];
-    NSInteger height = screenRect.size.height;
-    NSPoint mouseLoc = [NSEvent mouseLocation];
-    CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
+    CGFloat height = NSScreen.mainScreen.frame.size.height;
+    NSPoint mouseLoc = NSEvent.mouseLocation;
+    CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
                                                CGPointMake(mouseLoc.x, height - mouseLoc.y),
-                                               button);
+                                               _button);
     CGEventPost(kCGHIDEventTap, click);
     CFRelease(click);
 }