Created
December 28, 2012 02:49
-
-
Save joshaber/4394046 to your computer and use it in GitHub Desktop.
NSEvent+RACSignals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSEvent (RACSignals) | |
+ (id<RACSignal>)rac_signalForEventsMatchingMask:(NSEventMask)eventMask { | |
return [RACSignal createSignal:^(id<RACSubscriber> subscriber) { | |
id monitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *event) { | |
[subscriber sendNext:event]; | |
return event; | |
}]; | |
return [RACDisposable disposableWithBlock:^{ | |
[NSEvent removeMonitor:monitor]; | |
}]; | |
}]; | |
} | |
+ (id<RACSignal>)rac_mouseLocation { | |
return [[[NSEvent | |
rac_signalForEventsMatchingMask:NSMouseMovedMask] | |
map:^(id _) { | |
return [NSValue valueWithPoint:NSEvent.mouseLocation]; | |
}] | |
startWith:[NSValue valueWithPoint:NSEvent.mouseLocation]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment