Bug: getWindowStateAsString() and setUsingNativeTitleBar()

I use getWindowStateAsString() to save the window position, and when the app starts up again I use restoreWindowStateFromString().

This works great when I use the JUCE titlebars.

However, if my code uses setUsingNativeTitleBar() before the window is shown, the size is correct but the position drifts down and to the right.

Looking at the XML I’m writing with ApplicationProperties.getUserSettings()->setValue(…), the window drifts exactly 1 pixel to the right, and 25 pixels down every time the application is restarted. Here are the results of 3 open-close iterations where I did not move the window at all on the screen:

I’m using JUCE 2.0.38-g0353100 on Ubuntu 12.10.

Nothing like that happens for me with the introjucer or other apps that use those methods, so I don’t think you can blame those methods… Could be that on linux the window positions are coming back inconsistently?

Had the same here.

When calling setContentOwned() within your main DocumentWindow, use "false' for the second parameter.

So, this should work:

    setContentOwned (mainComponent = new MainComponent(), false);
    restoreWindowStateFromString (propertyFile->getValue (getName()));


I have the same problem on Ubuntu 20.04.2 LTS. Each time the window is opened i have a same offset down.

The value from restoreWindowStateFromString is correct, but a wrong moved call (of 37 pixels down) is triggered just right after a first (good) one. If i don’t use native title bar only the first moved call is done (and such result is fine).

Same behaviour with master/develop branch. Any idea to resolve that?

I reported this 8 years ago. Still happening with my code today. I never understood why and gave up on understanding this bug or having it fixed a long time ago.

1 Like

Thanks for the reply. It’s my turn to waste time on that. I hope i’ll be more lucky than you!

Minimum example to reproduce the bug (Ubuntu) :

Drift.zip (4.9 KB)
MainComponent.h (695 Bytes)
Main.cpp (3.2 KB)

Thank you for reporting.

1 Like

Thanks for the fix (seems to work fine now). :grinning: