summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar liamwhite2022-08-12 10:05:06 -0400
committerGravatar GitHub2022-08-12 10:05:06 -0400
commite8a59a6931250131fd5cbd1d531cf4912a04f7a7 (patch)
tree07fd2ab47501efad4f6a97447338a6c62ebaabe5 /src
parentMerge pull request #8731 from FearlessTobi/better-ldn (diff)
parentreview pass on CheckDarkMode function (diff)
downloadyuzu-e8a59a6931250131fd5cbd1d531cf4912a04f7a7.tar.gz
yuzu-e8a59a6931250131fd5cbd1d531cf4912a04f7a7.tar.xz
yuzu-e8a59a6931250131fd5cbd1d531cf4912a04f7a7.zip
Merge pull request #8647 from Docteh/default_dark
Linux: handle dark system themes nicely
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/game_list.cpp2
-rw-r--r--src/yuzu/game_list_p.h2
-rw-r--r--src/yuzu/main.cpp82
-rw-r--r--src/yuzu/main.h5
4 files changed, 77 insertions, 14 deletions
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp
index 041e6ac11..c4b1f65bd 100644
--- a/src/yuzu/game_list.cpp
+++ b/src/yuzu/game_list.cpp
@@ -286,7 +286,7 @@ void GameList::OnUpdateThemedIcons() {
286 } 286 }
287 case GameListItemType::AddDir: 287 case GameListItemType::AddDir:
288 child->setData( 288 child->setData(
289 QIcon::fromTheme(QStringLiteral("plus")) 289 QIcon::fromTheme(QStringLiteral("list-add"))
290 .pixmap(icon_size) 290 .pixmap(icon_size)
291 .scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 291 .scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
292 Qt::DecorationRole); 292 Qt::DecorationRole);
diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h
index e7667cf60..0e19be22d 100644
--- a/src/yuzu/game_list_p.h
+++ b/src/yuzu/game_list_p.h
@@ -294,7 +294,7 @@ public:
294 294
295 const int icon_size = UISettings::values.folder_icon_size.GetValue(); 295 const int icon_size = UISettings::values.folder_icon_size.GetValue();
296 296
297 setData(QIcon::fromTheme(QStringLiteral("plus")) 297 setData(QIcon::fromTheme(QStringLiteral("list-add"))
298 .pixmap(icon_size) 298 .pixmap(icon_size)
299 .scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), 299 .scaled(icon_size, icon_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation),
300 Qt::DecorationRole); 300 Qt::DecorationRole);
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index f82bec3b7..44d7feddc 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -257,6 +257,18 @@ static QString PrettyProductName() {
257 return QSysInfo::prettyProductName(); 257 return QSysInfo::prettyProductName();
258} 258}
259 259
260bool GMainWindow::CheckDarkMode() {
261#ifdef __linux__
262 const QPalette test_palette(qApp->palette());
263 const QColor text_color = test_palette.color(QPalette::Active, QPalette::Text);
264 const QColor window_color = test_palette.color(QPalette::Active, QPalette::Window);
265 return (text_color.value() > window_color.value());
266#else
267 // TODO: Windows
268 return false;
269#endif // __linux__
270}
271
260GMainWindow::GMainWindow(bool has_broken_vulkan) 272GMainWindow::GMainWindow(bool has_broken_vulkan)
261 : ui{std::make_unique<Ui::MainWindow>()}, system{std::make_unique<Core::System>()}, 273 : ui{std::make_unique<Ui::MainWindow>()}, system{std::make_unique<Core::System>()},
262 input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, 274 input_subsystem{std::make_shared<InputCommon::InputSubsystem>()},
@@ -274,6 +286,13 @@ GMainWindow::GMainWindow(bool has_broken_vulkan)
274 ui->setupUi(this); 286 ui->setupUi(this);
275 statusBar()->hide(); 287 statusBar()->hide();
276 288
289 // Check dark mode before a theme is loaded
290 os_dark_mode = CheckDarkMode();
291 startup_icon_theme = QIcon::themeName();
292 // fallback can only be set once, colorful theme icons are okay on both light/dark
293 QIcon::setFallbackThemeName(QStringLiteral("colorful"));
294 QIcon::setFallbackSearchPaths(QStringList(QStringLiteral(":/icons")));
295
277 default_theme_paths = QIcon::themeSearchPaths(); 296 default_theme_paths = QIcon::themeSearchPaths();
278 UpdateUITheme(); 297 UpdateUITheme();
279 298
@@ -3935,8 +3954,21 @@ void GMainWindow::filterBarSetChecked(bool state) {
3935 emit(OnToggleFilterBar()); 3954 emit(OnToggleFilterBar());
3936} 3955}
3937 3956
3957static void AdjustLinkColor() {
3958 QPalette new_pal(qApp->palette());
3959 if (UISettings::IsDarkTheme()) {
3960 new_pal.setColor(QPalette::Link, QColor(0, 190, 255, 255));
3961 } else {
3962 new_pal.setColor(QPalette::Link, QColor(0, 140, 200, 255));
3963 }
3964 if (qApp->palette().color(QPalette::Link) != new_pal.color(QPalette::Link)) {
3965 qApp->setPalette(new_pal);
3966 }
3967}
3968
3938void GMainWindow::UpdateUITheme() { 3969void GMainWindow::UpdateUITheme() {
3939 const QString default_theme = QStringLiteral("default"); 3970 const QString default_theme =
3971 QString::fromUtf8(UISettings::themes[static_cast<size_t>(Config::default_theme)].second);
3940 QString current_theme = UISettings::values.theme; 3972 QString current_theme = UISettings::values.theme;
3941 QStringList theme_paths(default_theme_paths); 3973 QStringList theme_paths(default_theme_paths);
3942 3974
@@ -3944,6 +3976,23 @@ void GMainWindow::UpdateUITheme() {
3944 current_theme = default_theme; 3976 current_theme = default_theme;
3945 } 3977 }
3946 3978
3979#ifdef _WIN32
3980 QIcon::setThemeName(current_theme);
3981 AdjustLinkColor();
3982#else
3983 if (current_theme == QStringLiteral("default") || current_theme == QStringLiteral("colorful")) {
3984 QIcon::setThemeName(current_theme == QStringLiteral("colorful") ? current_theme
3985 : startup_icon_theme);
3986 QIcon::setThemeSearchPaths(theme_paths);
3987 if (CheckDarkMode()) {
3988 current_theme = QStringLiteral("default_dark");
3989 }
3990 } else {
3991 QIcon::setThemeName(current_theme);
3992 QIcon::setThemeSearchPaths(QStringList(QStringLiteral(":/icons")));
3993 AdjustLinkColor();
3994 }
3995#endif
3947 if (current_theme != default_theme) { 3996 if (current_theme != default_theme) {
3948 QString theme_uri{QStringLiteral(":%1/style.qss").arg(current_theme)}; 3997 QString theme_uri{QStringLiteral(":%1/style.qss").arg(current_theme)};
3949 QFile f(theme_uri); 3998 QFile f(theme_uri);
@@ -3966,17 +4015,6 @@ void GMainWindow::UpdateUITheme() {
3966 qApp->setStyleSheet({}); 4015 qApp->setStyleSheet({});
3967 setStyleSheet({}); 4016 setStyleSheet({});
3968 } 4017 }
3969
3970 QPalette new_pal(qApp->palette());
3971 if (UISettings::IsDarkTheme()) {
3972 new_pal.setColor(QPalette::Link, QColor(0, 190, 255, 255));
3973 } else {
3974 new_pal.setColor(QPalette::Link, QColor(0, 140, 200, 255));
3975 }
3976 qApp->setPalette(new_pal);
3977
3978 QIcon::setThemeName(current_theme);
3979 QIcon::setThemeSearchPaths(theme_paths);
3980} 4018}
3981 4019
3982void GMainWindow::LoadTranslation() { 4020void GMainWindow::LoadTranslation() {
@@ -4022,6 +4060,26 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
4022 discord_rpc->Update(); 4060 discord_rpc->Update();
4023} 4061}
4024 4062
4063void GMainWindow::changeEvent(QEvent* event) {
4064#ifdef __linux__
4065 // PaletteChange event appears to only reach so far into the GUI, explicitly asking to
4066 // UpdateUITheme is a decent work around
4067 if (event->type() == QEvent::PaletteChange) {
4068 const QPalette test_palette(qApp->palette());
4069 const QString current_theme = UISettings::values.theme;
4070 // Keeping eye on QPalette::Window to avoid looping. QPalette::Text might be useful too
4071 static QColor last_window_color;
4072 const QColor window_color = test_palette.color(QPalette::Active, QPalette::Window);
4073 if (last_window_color != window_color && (current_theme == QStringLiteral("default") ||
4074 current_theme == QStringLiteral("colorful"))) {
4075 UpdateUITheme();
4076 }
4077 last_window_color = window_color;
4078 }
4079#endif // __linux__
4080 QWidget::changeEvent(event);
4081}
4082
4025#ifdef main 4083#ifdef main
4026#undef main 4084#undef main
4027#endif 4085#endif
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index e13b38b24..1ae2b93d9 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -251,6 +251,7 @@ private:
251 bool ConfirmForceLockedExit(); 251 bool ConfirmForceLockedExit();
252 void RequestGameExit(); 252 void RequestGameExit();
253 void RequestGameResume(); 253 void RequestGameResume();
254 void changeEvent(QEvent* event) override;
254 void closeEvent(QCloseEvent* event) override; 255 void closeEvent(QCloseEvent* event) override;
255 256
256#ifdef __linux__ 257#ifdef __linux__
@@ -347,6 +348,7 @@ private:
347 void OpenURL(const QUrl& url); 348 void OpenURL(const QUrl& url);
348 void LoadTranslation(); 349 void LoadTranslation();
349 void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); 350 void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
351 bool CheckDarkMode();
350 352
351 QString GetTasStateDescription() const; 353 QString GetTasStateDescription() const;
352 354
@@ -392,6 +394,9 @@ private:
392 QTimer mouse_hide_timer; 394 QTimer mouse_hide_timer;
393 QTimer mouse_center_timer; 395 QTimer mouse_center_timer;
394 396
397 QString startup_icon_theme;
398 bool os_dark_mode = false;
399
395 // FS 400 // FS
396 std::shared_ptr<FileSys::VfsFilesystem> vfs; 401 std::shared_ptr<FileSys::VfsFilesystem> vfs;
397 std::unique_ptr<FileSys::ManualContentProvider> provider; 402 std::unique_ptr<FileSys::ManualContentProvider> provider;