Notification when DisplayOrientation changed?

Hi everyone,

my mobile app needs to get notified when Desktop::DisplayOrientation changes and was wondering if there is some sort of listener for this? Didn’t find anything in the docs.

At the moment I’m checking in DocumentWindow’s resized() if still width > height or vice versa and reporting that back to the JUCEApplication to call Desktop::getCurrentOrientation manually. This is quite messy as I need to rebuild my DocumentWindow when screen orientation changes.

Is there a more elegant way to get notified?

Thanks
Stefan

Why is just checking juce::desktop:getCurrentOrientation() on your resized() method not sufficient?

IMHO, there’s no need for a custom event just because the orientation changed - this gets propagated to your resized() methods anyway… isn’t this the purpose of the resized() message propagation in the first place?

rebuild DocumentWindow

I’ve found that using FlexBox helps immensely with this situation …

Well, without going to deep into my setup. it’s not only a matter of realigning my subcomponents within my DocumentWindow's content component, I replace the whole content. Depending on the orientation, I show two complete different things. At the moment, when checking an orientation change in resized(), the DocumentWindow is telling the owner class (JUCEApplication) to destroy itself and build a new DocumentWindow. I have to use MessageManager::callAsync to do that because it’s possible that something in the MessageManager queue want to access the DocumentWindow which otherwise would have been already destroyed.

It would also be possible to only change the contentComponent, but the corresponding ValueTree node is a different one and I would have to refactor my class. And that’s also problematic because my app has a desktop version with multi window usage as well, so I would have to change a lot things.

That’s why a listener like DarkModeSettingListener would be a nicer solution for the mobile app.

For this part of the question it is adviseable to capture a SafePointer:

juce::Component::SafePointer<DocumentWindow> safe (documentWindow);
juce::MessageManager::callAsync([this, safe]
{
    if (!safe) return;

    // ...
});
1 Like

Oh yeah, good call.

Thanks, Daniel.