From 8e76265b0c6f50b1e389de991ffbb19ff161a067 Mon Sep 17 00:00:00 2001 From: Hugh Davenport Date: Wed, 3 Jan 2024 17:20:42 +1300 Subject: [PATCH] Taskbar: Add hotkeys for theme selector menu --- Base/res/themes/Basalt.ini | 2 ++ Base/res/themes/Chillychilly.ini | 2 ++ Base/res/themes/Coffee.ini | 2 ++ Base/res/themes/Contrast.ini | 2 ++ Base/res/themes/Cupertino.ini | 2 ++ Base/res/themes/Dark.ini | 2 ++ Base/res/themes/Default.ini | 2 ++ Base/res/themes/Desert.ini | 2 ++ Base/res/themes/Durrque.ini | 2 ++ Base/res/themes/Faux Pas.ini | 2 ++ Base/res/themes/Gruvbox Dark.ini | 2 ++ Base/res/themes/Light.ini | 2 ++ Base/res/themes/Nord.ini | 2 ++ Base/res/themes/Olive.ini | 2 ++ Base/res/themes/Plum.ini | 2 ++ Base/res/themes/Pumpkin.ini | 2 ++ Base/res/themes/Redmond 2000.ini | 2 ++ Base/res/themes/Redmond.ini | 2 ++ Base/res/themes/Scarlett.ini | 2 ++ Base/res/themes/Silver.ini | 2 ++ Base/res/themes/Sunshine.ini | 2 ++ Userland/Libraries/LibGfx/SystemTheme.cpp | 4 +++- Userland/Libraries/LibGfx/SystemTheme.h | 1 + Userland/Services/Taskbar/main.cpp | 8 +++++--- 24 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Base/res/themes/Basalt.ini b/Base/res/themes/Basalt.ini index 18c9a84d431..29354b3d00c 100644 --- a/Base/res/themes/Basalt.ini +++ b/Base/res/themes/Basalt.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Basalt [Colors] Accent=#ff7f00 DesktopBackground=#171717 diff --git a/Base/res/themes/Chillychilly.ini b/Base/res/themes/Chillychilly.ini index 39ee1707f85..214d1bdd14c 100644 --- a/Base/res/themes/Chillychilly.ini +++ b/Base/res/themes/Chillychilly.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Chill&ychilly [Colors] DesktopBackground=#3f8077ff Accent=#509296ff diff --git a/Base/res/themes/Coffee.ini b/Base/res/themes/Coffee.ini index fc9b648004b..ca05e076d03 100644 --- a/Base/res/themes/Coffee.ini +++ b/Base/res/themes/Coffee.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Coffee [Colors] Accent=#574dbb DesktopBackground=#567f9d diff --git a/Base/res/themes/Contrast.ini b/Base/res/themes/Contrast.ini index eb3e55fe050..1ff804e3b4a 100644 --- a/Base/res/themes/Contrast.ini +++ b/Base/res/themes/Contrast.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Con&trast [Metrics] TitleButtonWidth=15 BorderRadius=0 diff --git a/Base/res/themes/Cupertino.ini b/Base/res/themes/Cupertino.ini index 99cabbc58c5..dfac7c93dbb 100644 --- a/Base/res/themes/Cupertino.ini +++ b/Base/res/themes/Cupertino.ini @@ -1,3 +1,5 @@ +[Menu] +Name=C&upertino [Colors] DesktopBackground=#55bff0 Accent=#55bff0 diff --git a/Base/res/themes/Dark.ini b/Base/res/themes/Dark.ini index 8f150ba4475..3d9e4fe53d8 100644 --- a/Base/res/themes/Dark.ini +++ b/Base/res/themes/Dark.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Dar&k [Colors] Accent=#4d4d5f DesktopBackground=#202020 diff --git a/Base/res/themes/Default.ini b/Base/res/themes/Default.ini index 5f322be0bde..5706efa5fbf 100644 --- a/Base/res/themes/Default.ini +++ b/Base/res/themes/Default.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Default [Colors] DesktopBackground=#505050 Accent=#ab6e4a diff --git a/Base/res/themes/Desert.ini b/Base/res/themes/Desert.ini index 83c111535e2..db8e8c1bc3f 100644 --- a/Base/res/themes/Desert.ini +++ b/Base/res/themes/Desert.ini @@ -1,3 +1,5 @@ +[Menu] +Name=D&esert [Colors] Accent=#84bdaa DesktopBackground=#a28d68 diff --git a/Base/res/themes/Durrque.ini b/Base/res/themes/Durrque.ini index 1a49597f06b..c09562b8699 100644 --- a/Base/res/themes/Durrque.ini +++ b/Base/res/themes/Durrque.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Durr&que [Metrics] TitleButtonWidth=15 BorderRadius=0 diff --git a/Base/res/themes/Faux Pas.ini b/Base/res/themes/Faux Pas.ini index 3df2a2b2c87..15e4ebf7a95 100644 --- a/Base/res/themes/Faux Pas.ini +++ b/Base/res/themes/Faux Pas.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Faux Pas [Colors] Accent=#000000 DesktopBackground=#505170 diff --git a/Base/res/themes/Gruvbox Dark.ini b/Base/res/themes/Gruvbox Dark.ini index ffca443f3aa..fca1d641e7f 100644 --- a/Base/res/themes/Gruvbox Dark.ini +++ b/Base/res/themes/Gruvbox Dark.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Gruvbox Dark [Colors] Accent=#79740e DesktopBackground=#282828 diff --git a/Base/res/themes/Light.ini b/Base/res/themes/Light.ini index 51ff17cd06c..45b9c6539d4 100644 --- a/Base/res/themes/Light.ini +++ b/Base/res/themes/Light.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Light [Colors] Accent=#ffffff DesktopBackground=#0f0f0f diff --git a/Base/res/themes/Nord.ini b/Base/res/themes/Nord.ini index fb4ada69bd8..ae0bb37a287 100644 --- a/Base/res/themes/Nord.ini +++ b/Base/res/themes/Nord.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Nord [Colors] Accent=#4c566a DesktopBackground=#3b4252 diff --git a/Base/res/themes/Olive.ini b/Base/res/themes/Olive.ini index f871a0e8d40..e3951786025 100644 --- a/Base/res/themes/Olive.ini +++ b/Base/res/themes/Olive.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Olive [Metrics] TitleButtonWidth=15 BorderRadius=0 diff --git a/Base/res/themes/Plum.ini b/Base/res/themes/Plum.ini index 03c2471b943..2b9535d7269 100644 --- a/Base/res/themes/Plum.ini +++ b/Base/res/themes/Plum.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Plum [Colors] Accent=#a084b8 DesktopBackground=#402840 diff --git a/Base/res/themes/Pumpkin.ini b/Base/res/themes/Pumpkin.ini index 63666e1d7d0..0d5df026192 100644 --- a/Base/res/themes/Pumpkin.ini +++ b/Base/res/themes/Pumpkin.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Pumpk&in [Metrics] TitleButtonWidth=15 BorderRadius=0 diff --git a/Base/res/themes/Redmond 2000.ini b/Base/res/themes/Redmond 2000.ini index 997745d9b68..8f6e3b70603 100644 --- a/Base/res/themes/Redmond 2000.ini +++ b/Base/res/themes/Redmond 2000.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Redmond &2000 [Colors] Accent=#4a6eab DesktopBackground=#3a6ea5 diff --git a/Base/res/themes/Redmond.ini b/Base/res/themes/Redmond.ini index 38b0cf6a8df..c1cc82b9486 100644 --- a/Base/res/themes/Redmond.ini +++ b/Base/res/themes/Redmond.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Redmond [Colors] Accent=#0000ab DesktopBackground=#008080 diff --git a/Base/res/themes/Scarlett.ini b/Base/res/themes/Scarlett.ini index ca9ae517911..9f3e6591af9 100644 --- a/Base/res/themes/Scarlett.ini +++ b/Base/res/themes/Scarlett.ini @@ -1,3 +1,5 @@ +[Menu] +Name=&Scarlett [Metrics] TitleButtonWidth=15 BorderRadius=0 diff --git a/Base/res/themes/Silver.ini b/Base/res/themes/Silver.ini index 534dc1428b4..80a44d4f836 100644 --- a/Base/res/themes/Silver.ini +++ b/Base/res/themes/Silver.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Sil&ver [Metrics] TitleButtonWidth=15 BorderRadius=0 diff --git a/Base/res/themes/Sunshine.ini b/Base/res/themes/Sunshine.ini index 5ab729bbb4b..1e1e58c2b6c 100644 --- a/Base/res/themes/Sunshine.ini +++ b/Base/res/themes/Sunshine.ini @@ -1,3 +1,5 @@ +[Menu] +Name=Suns&hine [Colors] Accent=#b24d7a DesktopBackground=#574c8f diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index 1a9b41f813f..fd70bb9ad85 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -204,7 +204,9 @@ ErrorOr> list_installed_system_themes() while (dt.has_next()) { auto theme_name = dt.next_path(); auto theme_path = ByteString::formatted("/res/themes/{}", theme_name); - TRY(system_themes.try_append({ LexicalPath::title(theme_name), theme_path })); + auto config_file = TRY(Core::ConfigFile::open(theme_path)); + auto menu_name = config_file->read_entry("Menu", "Name", theme_name); + TRY(system_themes.try_append({ LexicalPath::title(theme_name), menu_name, theme_path })); } quick_sort(system_themes, [](auto& a, auto& b) { return a.name < b.name; }); return system_themes; diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h index 28ac08ec655..f1d67f7924d 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.h +++ b/Userland/Libraries/LibGfx/SystemTheme.h @@ -296,6 +296,7 @@ ErrorOr load_system_theme(ByteString const& path, Optiona struct SystemThemeMetaData { ByteString name; + ByteString menu_name; ByteString path; }; diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index de2861770a9..dfc30ec2b08 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -239,9 +239,9 @@ ErrorOr> build_system_menu(GUI::Window& window) { int theme_identifier = 0; for (auto& theme : g_themes) { - auto action = GUI::Action::create_checkable(theme.name, [theme_identifier, &window](auto&) { + auto action = GUI::Action::create_checkable(theme.menu_name, [theme_identifier, current_theme_name, &window](auto&) { auto& theme = g_themes[theme_identifier]; - dbgln("Theme switched to {} at path {}", theme.name, theme.path); + dbgln("Theme switched from {} to {} at path {}", current_theme_name, theme.name, theme.path); if (window.main_widget()->palette().color_scheme_path() != ""sv) VERIFY(GUI::ConnectionToWindowServer::the().set_system_theme(theme.path, theme.name, false, GUI::ConnectionToWindowServer::the().get_preferred_color_scheme())); else @@ -260,9 +260,11 @@ ErrorOr> build_system_menu(GUI::Window& window) return; auto current_theme_name = GUI::ConnectionToWindowServer::the().get_system_theme(); auto theme_overridden = GUI::ConnectionToWindowServer::the().is_system_theme_overridden(); + VERIFY(g_themes.size() == g_themes_menu->items().size()); for (size_t index = 0; index < g_themes.size(); ++index) { auto* action = g_themes_menu->action_at(index); - action->set_checked(!theme_overridden && action->text() == current_theme_name); + auto& theme = g_themes[index]; + action->set_checked(!theme_overridden && theme.name == current_theme_name); } };