Skip to content

Instantly share code, notes, and snippets.

@landonf
Created February 17, 2014 16:56
Show Gist options
  • Save landonf/9054459 to your computer and use it in GitHub Desktop.
Save landonf/9054459 to your computer and use it in GitHub Desktop.
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[NSWindow ex_patchInstanceSelector: @selector(sendEvent:) withReplacementBlock: ^(EXPatchIMP *patch, NSEvent *event) {
NSWindow *window = (__bridge NSWindow *) patch->self;
if (window != self.window && [event type] == NSLeftMouseUp && [window isKeyWindow]) {
/* The last view seen */
static NSView *lastView = nil;
NSPoint point = [window.contentView convertPoint: [event locationInWindow] fromView: nil];
NSView *hitView = [window.contentView hitTest: point];
/* Only send a notification when the view changes */
if (hitView != nil && hitView != lastView) {
lastView = hitView;
[[NSNotificationCenter defaultCenter] postNotificationName: EXViewAnalyzerTargetedViewNotification object: hitView];
}
}
EXPatchIMPFoward(patch, void (*)(id, SEL, NSEvent *), event);
}];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment