Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPopover to start in a detached state

Is there a way to force the NSPopover to start in the detached state? I only see isDetached which is a read-only property for the state of the popover and an NSPopoverDelegate method detachableWindow(forPopover:) which lets me override the window that gets created. I'd like to essentially click a button and have the NSPopover start in the state in this photo.

The style of this window is exactly what a product requirement is and I can't seem to find any NSWindow style settings that would make a window do something like this (nor an NSPanel)

This detached popover functionality seems special in that it:

  1. non-modal, but stays above main app. Able to still interact with the main app just like in Messages how you can still click around and type a new message.
  2. Clicking another app, AppFoo, puts both the main app and the helper window behind AppFoo.
  3. The helper window can be moved around and isn't hidden on app deactivation (another app gets selected).
  4. Has the little, native, grey X in the top left.

Detached NSPopover from Details button in Messages

like image 770
Kirkova Avatar asked Jun 25 '18 21:06

Kirkova


1 Answers

If you don't mind calling private API, it's actually pretty simple:

let detach = NSSelectorFromString("detach")
if popover.responds(to: detach) {
    popover.perform(detach)
}

No need to even add a delegate. I don't know when this private method was added but it's available at least since macOS 10.13. I suspect it's available since the introduction of NSPopover, though.

like image 138
DarkDust Avatar answered Sep 28 '22 04:09

DarkDust