VirtualBox

Changeset 102750 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 3, 2024 4:10:44 PM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160927
Message:

FE/Qt: Extend UICommon with stuff to detect dark/light mode at GUI startup for platforms other than macOS or Windows; This time it's based purely on palette Window color luminance.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r102525 r102750  
    327327#elif defined(VBOX_WS_WIN)
    328328    m_fDarkMode = isWindowsInDarkMode();
    329 #endif
     329#else /* Linux, BSD, Solaris */
     330    m_fDarkMode = isPaletteInDarkMode();
     331#endif /* Linux, BSD, Solaris */
    330332    /* Load color theme: */
    331333    loadColorTheme();
     
    10111013}
    10121014
    1013 #ifdef VBOX_WS_WIN
     1015#if defined(VBOX_WS_MAC)
     1016// Provided by UICocoaApplication ..
     1017
     1018#elif defined(VBOX_WS_WIN)
     1019
    10141020bool UICommon::isWindowsInDarkMode() const
    10151021{
     
    10291035    return enmColorTheme == UIColorThemeType_Dark;
    10301036}
    1031 #endif /* VBOX_WS_WIN */
     1037
     1038#else /* Linux, BSD, Solaris */
     1039
     1040bool UICommon::isPaletteInDarkMode() const
     1041{
     1042    const QPalette pal = qApp->palette();
     1043    const QColor background = pal.color(QPalette::Active, QPalette::Window);
     1044    const double dLuminance = (0.299 * background.red() + 0.587 * background.green() + 0.114 * background.blue()) / 255;
     1045    return dLuminance < 0.5;
     1046}
     1047#endif /* Linux, BSD, Solaris */
    10321048
    10331049void UICommon::loadColorTheme()
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r102525 r102750  
    233233        QString hostOperatingSystem() const;
    234234
    235 #ifdef VBOX_WS_WIN
     235#if defined(VBOX_WS_MAC)
     236        // Provided by UICocoaApplication ..
     237#elif defined(VBOX_WS_WIN)
    236238        /** Returns whether Windows host is in Dark mode. */
    237239        bool isWindowsInDarkMode() const;
    238 #endif
     240#else /* Linux, BSD, Solaris */
     241        /** Returns whether palette is in Dark mode. */
     242        bool isPaletteInDarkMode() const;
     243#endif /* Linux, BSD, Solaris */
    239244
    240245        /** Returns whether host OS is in Dark mode. */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette