Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Forked from landonf/EXPatchMasterExample.m
Last active August 29, 2015 13:56
Show Gist options
  • Save jspahrsummers/9054650 to your computer and use it in GitHub Desktop.
Save jspahrsummers/9054650 to your computer and use it in GitHub Desktop.
[NSWindow ex_patchInstanceSelector: @selector(sendEvent:) withReplacementBlock: ^(EXPatchIMP *patch) {
return ^(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];
}
}
((void (*)(id, SEL, NSEvent *))patch->origIMP)(event);
};
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment