Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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