Mouse move event between two window..

I use NSTrackingArea and monitor mouseEntered to simulate hover of the NSButton.

But I met a problem between two windows. I have a first window A that was a modal window, then I click a button of window A and popup a window B as a dialog (NSPanel with workWhenModal = true). No matter I use [modal] or [show] setting in segue, I got similar result, when hover is available in window A, then it failed on button of window B. If hover is available in window B, then it failed on button of window A.

Is there any way that I can detect mouse move event in both window correctly? Or I need to have different implementation to make mouse move event been detected in both window?

Thanks,

Eric
What do you mean by "available" ?

when hover is available in window A, then it failed on button of window B

You have to define NSTracking for each button.
Did you do it ?

Could you show your code please ?


Here is my code, all objects in both windows are derived from same base class with set tracking area , but I think this issue is not related to tracking area because one of the object always worked, mouseEntered was called on working item and another didn't. The mouse move event just captured by one window and didn't dispatch to another window when leaving current window's area.

Code Block
private func setupTrackingArea() {
    trackingArea = NSTrackingArea.init(rect: bounds, options: [.mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self, userInfo: nil)
    addTrackingArea(trackingArea)
  }
override func mouseEntered(with event: NSEvent) {
    isHovered = true
  }

Where is this private func setupTrackingArea() ?
Is it in an NSButton subclass ?
Who is the owner ?

You need to have a different owner for each button.
But you show so limited code it is very difficult to assess what's going on.
I think the code related to tracking area is not the problem, because I have two buttons, button A is in window A, button B is in window B, the window B is opened by click button A, when I use "show" in segue to open the window B, then button B can't receive mouseEntered event (button A is OK). When I use "modal" to open the window B, then button A can't receive the mouseEntered event (button B is OK).

So I may need to find some way that can make mouseEntered been detected in both windows to fix my problem.


There is a special behavior I forget to mention above, I think my problem caused by the first window was opened by the modal mode.

Code Block
NSApplication.shared.runModal(for: windowController.window!)


Why I do this is because I need to make back window temporary disable when window A open.
Then when second window, window B may meet following situation:
  1. Open by "modal", then the button B in window B receive mouseEntered event, and button A in window A can't.

  2. Open by "show", then the button A in window A receive mouseEntered event, and button B in window B can't.

If I use
Code Block
windowController.showWindow(self)

to open window A, then both button can receive mouseEntered event, but the back window is still working.
This isn't what I want.

I am not sure what the correct relation I should set to these three window to achieve I purpose: disable back window and window A and window B can receive mouseEntered event correctly.

I am sorry for the incomplete information to make you confuse.

Eric



I am sorry to post this question after I found the root cause of my problem. This problem caused by the event was captured in a third party code I used, not caused by the system. worksWhenModal setting in NSPanel already provided what I want.
So you should now close the thread.

And for future posts, don't forget to mention if you use third party libraries and explain what they are essentially doing.
Mouse move event between two window..
 
 
Q