A year or two ago, I was finding that a new document window would be opened at top=0
and the titlebar was under the menus.
I started adding if self.top < 50 then self.top = 50
which worked for a while.
However, on my new machine (m2 macbook air with notch) ,that isnt enough.
It would need to be 65 to work.
Is there some API call I can make to find out what that number should be/height of the menus?
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.
(i.e something/2)
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
End If
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
Return iDisplay
End If
Next
End Function
I’m using the window centre to work out which screen you are on and then adjusting accordingly.