summaryrefslogtreecommitdiff
path: root/Userland/Services/WindowServer
diff options
context:
space:
mode:
authorimplicitfield <114500360+implicitfield@users.noreply.github.com>2023-02-12 15:48:23 +0200
committerAndreas Kling <kling@serenityos.org>2023-03-10 22:03:49 +0100
commite9e4baee777c82db2191af0a016411f46aa4b71c (patch)
tree36f9abb50b3759c4aab98260b4aa515dfcf076e8 /Userland/Services/WindowServer
parentfba0cee622701638b6853c33464f7c36b64b90e6 (diff)
downloadserenity-e9e4baee777c82db2191af0a016411f46aa4b71c.zip
Everywhere: Support overriding the system color scheme
Diffstat (limited to 'Userland/Services/WindowServer')
-rw-r--r--Userland/Services/WindowServer/ConnectionFromClient.cpp9
-rw-r--r--Userland/Services/WindowServer/ConnectionFromClient.h3
-rw-r--r--Userland/Services/WindowServer/WindowManager.cpp15
-rw-r--r--Userland/Services/WindowServer/WindowManager.h4
-rw-r--r--Userland/Services/WindowServer/WindowServer.ipc4
-rw-r--r--Userland/Services/WindowServer/main.cpp6
6 files changed, 32 insertions, 9 deletions
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp
index dab03a3c81..34bf167b78 100644
--- a/Userland/Services/WindowServer/ConnectionFromClient.cpp
+++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp
@@ -865,9 +865,9 @@ void ConnectionFromClient::set_accepts_drag(bool accepts)
wm.set_accepts_drag(accepts);
}
-Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(DeprecatedString const& theme_path, DeprecatedString const& theme_name, bool keep_desktop_background)
+Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(DeprecatedString const& theme_path, DeprecatedString const& theme_name, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path)
{
- bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background);
+ bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background, color_scheme_path);
return success;
}
@@ -897,6 +897,11 @@ Messages::WindowServer::IsSystemThemeOverriddenResponse ConnectionFromClient::is
return WindowManager::the().is_theme_overridden();
}
+Messages::WindowServer::GetPreferredColorSchemeResponse ConnectionFromClient::get_preferred_color_scheme()
+{
+ return WindowManager::the().get_preferred_color_scheme();
+}
+
void ConnectionFromClient::apply_cursor_theme(DeprecatedString const& name)
{
WindowManager::the().apply_cursor_theme(name);
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.h b/Userland/Services/WindowServer/ConnectionFromClient.h
index 627b647a5f..c511716478 100644
--- a/Userland/Services/WindowServer/ConnectionFromClient.h
+++ b/Userland/Services/WindowServer/ConnectionFromClient.h
@@ -145,12 +145,13 @@ private:
virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override;
virtual Messages::WindowServer::StartDragResponse start_drag(DeprecatedString const&, HashMap<DeprecatedString, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
virtual void set_accepts_drag(bool) override;
- virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(DeprecatedString const&, DeprecatedString const&, bool keep_desktop_background) override;
+ virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(DeprecatedString const&, DeprecatedString const&, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path) override;
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
virtual Messages::WindowServer::SetSystemThemeOverrideResponse set_system_theme_override(Core::AnonymousBuffer const&) override;
virtual Messages::WindowServer::GetSystemThemeOverrideResponse get_system_theme_override() override;
virtual void clear_system_theme_override() override;
virtual Messages::WindowServer::IsSystemThemeOverriddenResponse is_system_theme_overridden() override;
+ virtual Messages::WindowServer::GetPreferredColorSchemeResponse get_preferred_color_scheme() override;
virtual void apply_cursor_theme(DeprecatedString const&) override;
virtual void set_cursor_highlight_radius(int radius) override;
virtual Messages::WindowServer::GetCursorHighlightRadiusResponse get_cursor_highlight_radius() override;
diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp
index dee3f2680d..ae44b26b74 100644
--- a/Userland/Services/WindowServer/WindowManager.cpp
+++ b/Userland/Services/WindowServer/WindowManager.cpp
@@ -2077,9 +2077,9 @@ void WindowManager::invalidate_after_theme_or_font_change()
Compositor::the().invalidate_after_theme_or_font_change();
}
-bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background)
+bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path)
{
- auto error_or_new_theme = Gfx::load_system_theme(theme_path);
+ auto error_or_new_theme = Gfx::load_system_theme(theme_path, color_scheme_path);
if (error_or_new_theme.is_error()) {
dbgln("WindowManager: Updating theme failed, error {}", error_or_new_theme.error());
return false;
@@ -2089,6 +2089,15 @@ bool WindowManager::update_theme(DeprecatedString theme_path, DeprecatedString t
Gfx::set_system_theme(new_theme);
m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme);
g_config->write_entry("Theme", "Name", theme_name);
+ if (color_scheme_path.has_value() && color_scheme_path.value() != "Custom"sv) {
+ g_config->write_bool_entry("Theme", "LoadCustomColorScheme", true);
+ g_config->write_entry("Theme", "CustomColorSchemePath", color_scheme_path.value());
+ m_preferred_color_scheme = color_scheme_path.value();
+ } else if (!color_scheme_path.has_value()) {
+ g_config->write_bool_entry("Theme", "LoadCustomColorScheme", false);
+ g_config->remove_entry("Theme", "CustomColorSchemePath");
+ m_preferred_color_scheme = OptionalNone();
+ }
if (!keep_desktop_background)
g_config->remove_entry("Background", "Color");
if (!sync_config_to_disk())
@@ -2119,7 +2128,7 @@ void WindowManager::clear_theme_override()
{
m_theme_overridden = false;
auto previous_theme_name = g_config->read_entry("Theme", "Name");
- auto previous_theme = MUST(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", previous_theme_name)));
+ auto previous_theme = MUST(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", previous_theme_name), m_preferred_color_scheme));
Gfx::set_system_theme(previous_theme);
m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(previous_theme);
invalidate_after_theme_or_font_change();
diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h
index 1dd9fc686e..fd375e4423 100644
--- a/Userland/Services/WindowServer/WindowManager.h
+++ b/Userland/Services/WindowServer/WindowManager.h
@@ -201,13 +201,14 @@ public:
return nullptr;
}
- bool update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background);
+ bool update_theme(DeprecatedString theme_path, DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path);
void invalidate_after_theme_or_font_change();
bool set_theme_override(Core::AnonymousBuffer const& theme_override);
Optional<Core::AnonymousBuffer> get_theme_override() const;
void clear_theme_override();
bool is_theme_overridden() { return m_theme_overridden; }
+ Optional<DeprecatedString> get_preferred_color_scheme() { return m_preferred_color_scheme; }
bool set_hovered_window(Window*);
void deliver_mouse_event(Window&, MouseEvent const&);
@@ -439,6 +440,7 @@ private:
bool m_mouse_buttons_switched { false };
bool m_natural_scroll { false };
bool m_theme_overridden { false };
+ Optional<DeprecatedString> m_preferred_color_scheme { OptionalNone() };
WeakPtr<Window> m_hovered_window;
WeakPtr<Window> m_highlight_window;
diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc
index f40e4e1394..e8e8b7b4bc 100644
--- a/Userland/Services/WindowServer/WindowServer.ipc
+++ b/Userland/Services/WindowServer/WindowServer.ipc
@@ -130,7 +130,7 @@ endpoint WindowServer
start_drag([UTF8] DeprecatedString text, HashMap<DeprecatedString,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
set_accepts_drag(bool accepts) =|
- set_system_theme(DeprecatedString theme_path, [UTF8] DeprecatedString theme_name, bool keep_desktop_background) => (bool success)
+ set_system_theme(DeprecatedString theme_path, [UTF8] DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> color_scheme_path) => (bool success)
get_system_theme() => ([UTF8] DeprecatedString theme_name)
refresh_system_theme() =|
@@ -139,6 +139,8 @@ endpoint WindowServer
clear_system_theme_override() =|
is_system_theme_overridden() => (bool overridden)
+ get_preferred_color_scheme() => (Optional<DeprecatedString> path)
+
apply_cursor_theme(DeprecatedString name) =|
get_cursor_theme() => (DeprecatedString name)
diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp
index 5fc766a26c..da17e92616 100644
--- a/Userland/Services/WindowServer/main.cpp
+++ b/Userland/Services/WindowServer/main.cpp
@@ -47,7 +47,11 @@ ErrorOr<int> serenity_main(Main::Arguments)
WindowServer::g_config = TRY(Core::ConfigFile::open("/etc/WindowServer.ini", Core::ConfigFile::AllowWriting::Yes));
auto theme_name = WindowServer::g_config->read_entry("Theme", "Name", "Default");
- auto theme = TRY(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", theme_name)));
+ Optional<DeprecatedString> custom_color_scheme_path = OptionalNone();
+ if (WindowServer::g_config->read_bool_entry("Theme", "LoadCustomColorScheme", false))
+ custom_color_scheme_path = WindowServer::g_config->read_entry("Theme", "CustomColorSchemePath");
+
+ auto theme = TRY(Gfx::load_system_theme(DeprecatedString::formatted("/res/themes/{}.ini", theme_name), custom_color_scheme_path));
Gfx::set_system_theme(theme);
auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);