Is there a way to get to know the height of the macOS menubar?
For my Desktop app I use a window.top of minimum 45, but this is on my MacBook beneath the menubar.
So I’d like to set it like:
if window.top <= menubar.height then window.top = menubar.height+1
DesktopDisplay.AvailableTop tells you where the top most part of the available area on the screen is. This should do the trick:
var oBounds as Rect = self.Bounds
oBounds.Top = DesktopDisplay.DisplayAt(0).AvailableTop
self.Bounds = oBounds
(remember that Window.Top
is the window’s content area top)
Edit: I forgot that you can’t manipulate Window.Bounds directly.
Thanks. Ok, so another factor for the window title must be added, which is a standard value (?)
if window.top <= DesktopDisplay.DisplayAt(0).AvailableTop+25 then
window.top = DesktopDisplay.DisplayAt(0).AvailableTop+26
end
This works nicely.
I already gave you a working solution. Do not use Window.Top
, it is the top of the content area. You need to use the Window.Bounds
to position correctly.
Your are right. With that I can calculate the difference.
Then one last question:
The window could be behind the dock (e.g. on the bottom). You certainly know how to get the size of it, to shift the window away from the dock.
Position the window with Window.Bounds and there should be no calculation necessary. The documentation for Window.Top says exactly what I have said.
This information would be available from DesktopDisplay.AvailableHeight. The dock height will be subtracted from the available height. (The same goes for the taskbar should someone be reading this wondering about Windows.)
In short, the DesktopDisplay.Available{*} properties tell you the space on the screen you have to work with.
The blue items are links to the documentation in case that wasn’t clear.