-
Notifications
You must be signed in to change notification settings - Fork 1
/
FingerMouseAppDelegate.m
91 lines (76 loc) · 2.31 KB
/
FingerMouseAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// FingerMouseAppDelegate.m
// FingerMouse
//
// Created by bia on 12/9/10.
// Copyright 2010 bianca cheng costanzo. All rights reserved.
//
#import "FingerMouseAppDelegate.h"
@implementation FingerMouseAppDelegate
@synthesize window;
- (void)_updateWindowPosition
{
NSPoint p = [NSEvent mouseLocation];
[pointerOverlay setFrameOrigin:NSMakePoint(p.x - 25, p.y - 25)];
}
- (void)mouseDown
{
[pointerOverlay setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"Active"]]];
}
- (void)mouseUp
{
[pointerOverlay setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"Hover"]]];
}
- (void)mouseMoved
{
[self _updateWindowPosition];
}
- (void)mouseDragged
{
[self _updateWindowPosition];
}
CGEventRef tapCallBack(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *info)
{
FingerMouseAppDelegate *delegate = (FingerMouseAppDelegate *)info;
switch(type)
{
case kCGEventLeftMouseDown:
[delegate mouseDown];
break;
case kCGEventLeftMouseUp:
[delegate mouseUp];
break;
case kCGEventLeftMouseDragged:
[delegate mouseDragged];
break;
case kCGEventMouseMoved:
[delegate mouseMoved];
break;
}
return event;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
pointerOverlay = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 50, 50) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[pointerOverlay setAlphaValue:0.8];
[pointerOverlay setOpaque:NO];
[pointerOverlay setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"Hover"]]];
[pointerOverlay setLevel:NSFloatingWindowLevel];
[pointerOverlay setIgnoresMouseEvents:YES];
[self _updateWindowPosition];
[pointerOverlay orderFront:nil];
CGEventMask mask = CGEventMaskBit(kCGEventLeftMouseDown) |
CGEventMaskBit(kCGEventLeftMouseUp) |
CGEventMaskBit(kCGEventLeftMouseDragged) |
CGEventMaskBit(kCGEventMouseMoved);
CFMachPortRef tap = CGEventTapCreate(kCGAnnotatedSessionEventTap,
kCGTailAppendEventTap,
kCGEventTapOptionListenOnly,
mask,
tapCallBack,
self);
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(NULL, tap, 0);
CFRunLoopAddSource(CFRunLoopGetMain(), runLoopSource, kCFRunLoopCommonModes);
CFRelease(runLoopSource);
CFRelease(tap);
}
@end