Getting the title bar height in a windows/osx app

Hi, is there any way to get the title bar height from inside the editor windows created by the standalone filter?

thx

2 Likes

bump

2 Likes

This would also be useful in resizable DocumentWindows with native title bars: the heights passed to setResizeLimitis() are enforced including the height of the native title bar, but we have no way of knowing it, so if the content of the window must stay e.g. between 100 and 200 pixel height, it’s impossible to determine the precise constraint to call setResizeLimits() with

1 Like

ComponentPeer::getFrameSize() will give you the window frame size.

4 Likes

thanks

1 Like

Cool!

1 Like

I’m afraid I would forget it beforethe next time I use it, so the icing on the cake would be the addition to the documentation of setUsingNativeTitleBar() of a note like: “when using a native title bar, use ComponentPeer::getFrameSize() to obtain its height and the size of the native border possibly added around the window”

1 Like

For future readers: the value you want is the bottom one:grinning_face_with_smiling_eyes:

That looks like a bug to me! I’ll try to get that fixed shortly.

You mean it should be getTop()?

That’s right. I’ve fixed it here:

1 Like

Is it supposed to work on Linux also? At first look i always have zero with native title bar.

This should work on Linux, however, it may not work immediately (synchronously) after making a window visible. The window borders are communicated by the window manager setting the _NET_FRAME_EXTENTS property on the window, which must happen after the window has been created. For example, if I add the following to the constructor of the DemoRunner’s MainAppWindow then I see the expected frame size values:

Timer::callAfterDelay (2000, [this]
{
    DBG (getPeer()->getFrameSize().getTop());
    DBG (getPeer()->getFrameSize().getBottom());
});

If I omit the callAfterDelay and print the values directly inside the constructor, then both values are reported as 0.

It looks like at the moment we only update the frame extents when the window bounds change. We could probably improve this a bit by listening for changes to the FRAME_EXTENTS property and updating the border size as soon as the property is changed. I’ll make that change shortly.

Even once I’ve made the change above, the frame extents will not be available in the window’s constructor on Linux. If keeping track of the border size is important in your project, I’d recommend querying it as late as possible.

1 Like

Thanks, good to know. I need it only to properly compute the size limits i want for the window.

Frame extents should now be available as soon as the window manager sets them:

1 Like

It seems that about 20 ms of delay is enough to get the proper size on Ubuntu and on my RPI.
Notice that i didn’t test less since i don’t care. Thanks again.

My frame size is always all 0’s, I heard that may be because it’s non native. How do you get the title bar height of a non native window?