How about this?
Sample code in the open event of a TextArea:
Declare Function NSClassFromString Lib "AppKit" (classname As CFStringRef) As ptr
Declare Function sharedApplication Lib "AppKit" Selector "sharedApplication" (classRef As Ptr) As Ptr
Declare Function mainMenu Lib "AppKit" Selector "mainMenu" (classRef As Ptr) As Ptr
Declare Function menuBarHeight Lib "AppKit" Selector "menuBarHeight" (classRef As Ptr) As CGFloat
Var sharedApp As Ptr = sharedApplication(NSClassFromString("NSApplication"))
Var mBar As Ptr = mainMenu(sharedApp)
Var mh As CGFloat = menuBarHeight(mBar)
Me.AddText("height: " + Str(mh) + EndOfLine)
But now, it looks like my actual problem was screen scaling.
If I set the window top to be something, then it ends up in the wrong place.
By removing the code that handles the placement, OSX puts it under the menu anyway again now.
Position: Parent Window Screen places the window correctly for all my apps. Position: Default stands out and places things under the menu bar for some of our colleagues who refuse to change this value.
Hm perhaps we need a ticket / bug report for the Default / Stagger setting.
Parent Window Screen is [NSWindow center] (that slightly north of center position) on the screen of the last in-focus window. Not technically correct for document based apps like VersionTracker, but solves the under-the-menubar problem.
Var iDisplay As Integer = WhichScreen( Self.Left + ( Self.Width / 2 ), Self.Top + ( Self.Height / 2 ) )
Var DisplayMinWinTop As Integer = DesktopDisplay.DisplayAt( iDisplay ).AvailableTop + ( Self.Top - Self.Bounds.Top )
If Self.Top < DisplayMinWinTop Then
Self.Top = DisplayMinWinTop
Public Function WhichScreen(x As Integer, y As Integer) As Integer
Var oDisplay As DesktopDisplay
For iDisplay As Integer = 0 To DesktopDisplay.LastDisplayIndex
oDisplay = DesktopDisplay.DisplayAt( iDisplay )
If x >= oDisplay.AvailableLeft And x <= oDisplay.AvailableWidth + oDisplay.AvailableLeft And _
y >= oDisplay.AvailableTop And y <= oDisplay.AvailableHeight + oDisplay.AvailableTop Then
I’m using the window centre to work out which screen you are on and then adjusting accordingly.