Whimsical tooltips behaviour in popover (Appkit)

In this app I use tooltips extensively.

They work perfectly well, except in a popover where they may appear or not (just some flash and immediately disappear).

In the popover there are 12 colour buttons, each with its own tracking area and 3 control buttons, with their tracking areas.

Here when it works, hovering over "C" button or "Annuler" button:

But then, when I move to another colour button, a few 2 or 3 may work, but most don't display their tooltip at all.

I know that the tooltip is set because I replicate the message in a help line at the bottom of the screen and this line always update:

            Let messageForColor = "Choisir la couleur…"  
            if button.isEnabled  { //  show tooltip
                button.toolTip = messageForColor
            } else {
                button.toolTip = nil
            }
            if button.isEnabled { // Shows helpline at the bottom of screen
                button.helpMessage = messageForColor
            }

Maybe it comes from some useDefault (I modified NSInitialTool TipDelay and I'm not sure I have reset to the default value)

I noted that if I wait for 10 seconds or so (keeping the popover opened), everything seems to work properly again. Just as if there was some lengthy initialisation going on.

So questions:

  • Is there a known issue of Tooltips in a popover ?
  • Are there other parameters to set in userDefaults to avoid immediate disparition of the tooltip in popover ?
  • How to reset the factory setting for the UserDefaults in the app ?
Answered by Claude31 in 875422022

I've solved the issue with a workaround (until I understand what is causing the initial issue).

I mimic clicking in windowA by sending a mouseDownEvent, and it works.

self.window?.makeFirstResponder(self.window)
self.theViewToClick.perform(#selector(NSResponder.self.mouseDown(with:)), with: newMouseDownEvent!)

Same problem if the tooltips are defined in Storyboard vs in code.

I tested in another popover which only contains a TextField and 2 buttons: same issue.

I found something and potential solution.

The NSPopover is created inside a windowController (window A).

If I click in window A after opening the popover, all tooltips work correctly.

What is the reason ?

  • Could it be I did not set delegate for the popover ?

I have tried to no avail

  • I tried to make the window front and key

No success either

  • So there would be a workaround: simulate a click in window A

What is the simplest way to achieve this click programmatically (if possible without showing mouse movement) ?

Should I use

mouseEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:)

and then

postEvent(_:atStart:)
Accepted Answer

I've solved the issue with a workaround (until I understand what is causing the initial issue).

I mimic clicking in windowA by sending a mouseDownEvent, and it works.

self.window?.makeFirstResponder(self.window)
self.theViewToClick.perform(#selector(NSResponder.self.mouseDown(with:)), with: newMouseDownEvent!)

There is however a problem with this solution.

If there is a TextField in the popover, typing in makes it firstResponder ; and the parent window controller do not receive mouseEnter events that triggers the tooltips.

Which means I do not need to simulate mouseDown but just makeFirstResponder.

So at the end, the question boils down to: how to manage the conflict between popover and its parent window about FirstResponder.

Is it possible to have first and "second" responder, I mean forwarding the mouse messages to the parent ?

Considering that

The shared NSApplication object performs the important task of receiving events from the window server and distributing them to the proper NSResponder objects. NSApp translates an event into an NSEvent object, then forwards the event object to the affected NSWindow object. All keyboard and mouse events go directly to the NSWindow object associated with the event. … When a window object receives an NSEvent object from NSApp, it distributes it to the objects in its view hierarchy.

Could (should I) make both windows (parent and popover) receive the mouseEnter and mouseExit events which are needed for tooltips (up to me in that case to manage side effects).

I may have found a solution.

I subclass NSView to use as the popover viewController view. All IBOutlets are declared there.

And I set the tooltips there.

Whimsical tooltips behaviour in popover (Appkit)
 
 
Q