Skip to content

Commit

Permalink
FEAT(client): Automatically sync theme with OS color scheme
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. -fix

Implements mumble-voip#6515
  • Loading branch information
jakub2682-tuke committed Oct 29, 2024
1 parent be5a104 commit 9999da2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ MainWindow::MainWindow(QWidget *p)
else
SvgIcon::addSvgPixmapsToIcon(qiIcon, QLatin1String("skin:mumble.svg"));
#else
{
SvgIcon::addSvgPixmapsToIcon(qiIcon, QLatin1String("skin:mumble.svg"));
}
{ SvgIcon::addSvgPixmapsToIcon(qiIcon, QLatin1String("skin:mumble.svg")); }

// Set application icon except on MacOSX, where the window-icon
// shown in the title-bar usually serves as a draggable version of the
Expand Down Expand Up @@ -211,8 +209,7 @@ MainWindow::MainWindow(QWidget *p)

QAccessible::installFactory(AccessibleSlider::semanticSliderFactory);

// Theme application
applyTheme(); // Apply the light or dark theme during initialization
applyTheme();
}

void MainWindow::applyTheme() {
Expand All @@ -225,6 +222,7 @@ void MainWindow::applyTheme() {
if (configuredStyle->name == "Auto") {
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
auto colorScheme = QGuiApplication::styleHints()->colorScheme();

if (colorScheme == Qt::ColorScheme::Dark) {
setStyleSheet(loadStyleSheet(darkThemePath)); // Apply dark theme
} else {
Expand Down Expand Up @@ -284,7 +282,6 @@ QString MainWindow::loadStyleSheet(const QString &path) {
return QString(); // Return empty if the file cannot be loaded
}


void MainWindow::createActions() {
gsPushTalk = new GlobalShortcut(this, GlobalShortcutType::PushToTalk, tr("Push-to-Talk", "Global Shortcut"));
gsPushTalk->setObjectName(QLatin1String("PushToTalk"));
Expand Down Expand Up @@ -841,7 +838,6 @@ void MainWindow::changeEvent(QEvent *e) {
QTimer::singleShot(0, this, SLOT(hide()));
}
#endif

if (e->type() == QEvent::ThemeChange) {
applyTheme();
}
Expand Down
1 change: 0 additions & 1 deletion src/mumble/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindow {
ContextMenuTarget getContextMenuTargets();

void autocompleteUsername();

void applyTheme();
bool detectSystemTheme();
QString loadStyleSheet(const QString &path);
Expand Down

0 comments on commit 9999da2

Please sign in to comment.