osx - How to test if the mouse is inside a specified window? -


with cocoa, how check if mouse inside specified window of mine? have following code detects if it's within bounds of window, incorrectly prints it's inside if window closed/hidden mouse still in rectangle. incorrectly it's inside if window on top of it, mouse within region of window i'm testing below it.

nspoint mouse = [nsevent mouselocation];  bool mouseinside = nspointinrect(mouse, self.window.frame);  if (!mouseinside) {     nslog(@"mouse isn't inside"); } else {     nslog(@"mouse inside"); } 

i've tried this:

while ((screen = [screenenum nextobject]) && !nsmouseinrect(mouse, [screen frame], no));  if (screen != self.window.screen && mouseinside) {     nslog(@"mouse inside."); } 

but print "mouse inside".

any ideas? or setting tracking area way?

mikeash on freenode pointed me nswindow's windownumberatpoint:

the following code appears work needed:

if ([nswindow windownumberatpoint:mouse belowwindowwithwindownumber:0] != self.window.windownumber) {      nslog(@"mouse outside"); } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -