FR: Support detecting dark mode in other operating systems

Presently this is only a feature for macOS via juce::Desktop::isOSXDarkModeActive().

The other operating systems provide some form of detection:

I feel like extending this FR to include detecting when a change from light<->dark mode happens.

Also, I just found a Win32 way of detecting such a change, based on this StackOverflow post

String comparisons aren’t ideal of course.

2 Likes

I investigated the Win32 side of things for this and here are related changes to intercept the state/parameter change at the OS level:

    // In juce_win32_Windowing.cpp

            // ...in peerWindowProc()
            case WM_SETTINGCHANGE:  // note the fall-through in the previous case!
                doSettingChange (String (LPCTSTR (lParam)).trim());
                break;

    void doSettingChange (String settingId)
    {
        bool wasColourThemeChanged = settingId.equalsIgnoreCase ("ImmersiveColorSet");
        if (wasColourThemeChanged)
            jassertfalse;

And, although this is ugly, this is the simplest method I could find to detect dark mode Windows on an as-needed basis:

    // Generalising the `isOSXDarkModeActive` method in juce_Desktop.h
    /** Returns true if the OS is running with dark mode active.
        Many OSs don't support this.
    */
    static bool isDarkModeActive();
// Somewhere in juce_win32_Windowing.cpp
bool Desktop::isDarkModeActive()
{
    return WindowsRegistry::getValue ("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\\SystemUsesLightTheme")
            != "1";
}

I’m not sure about what kind of mechanism would be useful, if any, to notify the user-developer that the theme changed. The user-develop could probably just check if dark mode is active in the LookAndFeel.

Huh, would you look at that! Desktop: Deprecate isOSXDarkModeActive() and add isDarkModeActive() … · juce-framework/JUCE@3d282c1 · GitHub

I guess this means the votes outta get reclaimed now :smile:

2 Likes

Good point, I’ll close this thread so that the votes can be reclaimed. If you need to discuss any of the new changes, please start a new topic.

3 Likes