Search code examples
macosnswindow

How to get the screen coordinates of the close, miniaturize and maximize buttons?


I have a weird requirement from a client where they want a secondary floating window to point directly at the close, miniaturize or maximize button on the left side of the main window's titlebar. Is there any way programmatically to determine exactly where these buttons are in the window? Or do I just have to assume that the close button is always 10 x 10 and 5px from the top and 10px from the left (or whatever those metrics are)?

Alternatively, is there some places those metrics are documented?


Solution

  • func standardWindowButton(_ b: NSWindow.ButtonType) -> NSButton?
    

    Returns the window button of a given window button kind in the window’s view hierarchy.