Skip to content

Commit

Permalink
FEAT(client): Automatically sync theme with OS color scheme- v5
Browse files Browse the repository at this point in the history
This update introduces an automatic theme switch that changes based on the OS color scheme at startup and during runtime. This feature is implemented for Qt 6.2 and includes compatibility for Qt 6.5 once Mumble upgrades.

Implements mumble-voip#6515
  • Loading branch information
jakub2682-tuke committed Nov 1, 2024
1 parent ab72ac2 commit fcc5edd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/mumble/Themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <QPalette>
#include <QSettings>
#include <QStyleHints>
#include <QTextStream>

QString Themes::currentThemePath;

boost::optional< ThemeInfo::StyleInfo > Themes::getConfiguredStyle(const Settings &settings) {
if (settings.themeName.isEmpty() && settings.themeStyleName.isEmpty()) {
Expand Down Expand Up @@ -63,37 +63,23 @@ void Themes::applyFallback() {
}

bool Themes::applyConfigured() {
static QString currentThemePath;



boost::optional< ThemeInfo::StyleInfo > style = Themes::getConfiguredStyle(Global::get().s);
if (!style) {
return false;
}

QString themePath;
QString themePath = style->getPlatformQss().absoluteFilePath();
if (style->themeName == "Auto" || style->name == "Auto") {
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
auto colorScheme = QGuiApplication::styleHints()->colorScheme();
if (colorScheme == Qt::ColorScheme::Dark) {
themePath = ":/themes/Default/Dark.qss";
} else {
themePath = ":/themes/Default/Lite.qss";
}
#else

bool isDarkTheme = detectSystemTheme();
if (isDarkTheme) {
themePath = ":/themes/Default/Dark.qss";
} else {
themePath = ":/themes/Default/Lite.qss";
}
#endif
} else {
if (style->name == "Dark") {
themePath = ":/themes/Default/Dark.qss";
} else {
themePath = ":/themes/Default/Lite.qss";
}

}

// Early exit if the theme path is the same as the current one
Expand Down Expand Up @@ -149,9 +135,8 @@ bool Themes::apply() {

bool Themes::detectSystemTheme() {
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
return false; // This should not be called for Qt 6.5 and above
return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark;
#else
// Custom method to detect dark theme for Qt 6.2 and below
# ifdef Q_OS_WIN
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
QSettings::NativeFormat);
Expand Down
3 changes: 3 additions & 0 deletions src/mumble/Themes.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class Themes {
/// If a the file is is available, the function returns true.
/// If no file is available, it returns false.
static bool readStylesheet(const QString &stylesheetFn, QString &stylesheetContent);

/// Member variable to store the current theme path
static QString currentThemePath;
};

#endif // MUMBLE_MUMBLE_THEMES_H_

0 comments on commit fcc5edd

Please sign in to comment.