summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornetworkException <git@nwex.de>2022-06-16 20:25:01 +0200
committerLinus Groh <mail@linusgroh.de>2022-06-17 19:46:30 +0100
commit976b6156d466671016d5c3b70dcc0f54adbae983 (patch)
tree1a63c7738e06904a7348d245366e9d967f90438e
parent278fd28502c6ced57df029559658951cbd2cbaec (diff)
downloadserenity-976b6156d466671016d5c3b70dcc0f54adbae983.zip
WindowServer: Allow temporarily overriding the system theme
This patch adds a new api to override the current system theme with an in memory override theme.
-rw-r--r--Userland/Services/WindowServer/ConnectionFromClient.cpp21
-rw-r--r--Userland/Services/WindowServer/ConnectionFromClient.h4
-rw-r--r--Userland/Services/WindowServer/WindowManager.cpp30
-rw-r--r--Userland/Services/WindowServer/WindowManager.h6
-rw-r--r--Userland/Services/WindowServer/WindowServer.ipc5
5 files changed, 66 insertions, 0 deletions
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp
index 716dd1c862..0adbe0d78f 100644
--- a/Userland/Services/WindowServer/ConnectionFromClient.cpp
+++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp
@@ -804,6 +804,27 @@ Messages::WindowServer::GetSystemThemeResponse ConnectionFromClient::get_system_
return name;
}
+Messages::WindowServer::SetSystemThemeOverrideResponse ConnectionFromClient::set_system_theme_override(Core::AnonymousBuffer const& theme_override)
+{
+ bool success = WindowManager::the().set_theme_override(theme_override);
+ return success;
+}
+
+Messages::WindowServer::GetSystemThemeOverrideResponse ConnectionFromClient::get_system_theme_override()
+{
+ return WindowManager::the().get_theme_override();
+}
+
+void ConnectionFromClient::clear_system_theme_override()
+{
+ WindowManager::the().clear_theme_override();
+}
+
+Messages::WindowServer::IsSystemThemeOverriddenResponse ConnectionFromClient::is_system_theme_overridden()
+{
+ return WindowManager::the().is_theme_overridden();
+}
+
void ConnectionFromClient::apply_cursor_theme(String const& name)
{
WindowManager::the().apply_cursor_theme(name);
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.h b/Userland/Services/WindowServer/ConnectionFromClient.h
index 3db7349bfe..d0184b2805 100644
--- a/Userland/Services/WindowServer/ConnectionFromClient.h
+++ b/Userland/Services/WindowServer/ConnectionFromClient.h
@@ -142,6 +142,10 @@ private:
virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(String const&, String const&, bool keep_desktop_background) 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 void apply_cursor_theme(String 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 e60ac68621..dbd2f26585 100644
--- a/Userland/Services/WindowServer/WindowManager.cpp
+++ b/Userland/Services/WindowServer/WindowManager.cpp
@@ -2111,6 +2111,7 @@ bool WindowManager::update_theme(String theme_path, String theme_name, bool keep
auto new_theme = Gfx::load_system_theme(theme_path);
if (!new_theme.is_valid())
return false;
+ m_theme_overridden = false;
Gfx::set_system_theme(new_theme);
m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme);
m_config->write_entry("Theme", "Name", theme_name);
@@ -2122,6 +2123,35 @@ bool WindowManager::update_theme(String theme_path, String theme_name, bool keep
return true;
}
+bool WindowManager::set_theme_override(Core::AnonymousBuffer const& theme_override)
+{
+ if (!theme_override.is_valid())
+ return false;
+ m_theme_overridden = true;
+ Gfx::set_system_theme(theme_override);
+ m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme_override);
+ invalidate_after_theme_or_font_change();
+ return true;
+}
+
+Optional<Core::AnonymousBuffer> WindowManager::get_theme_override() const
+{
+ if (!m_theme_overridden)
+ return {};
+ return Gfx::current_system_theme_buffer();
+}
+
+void WindowManager::clear_theme_override()
+{
+ m_theme_overridden = false;
+ auto previous_theme_name = m_config->read_entry("Theme", "Name");
+ auto previous_theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", previous_theme_name));
+ VERIFY(previous_theme.is_valid());
+ Gfx::set_system_theme(previous_theme);
+ m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(previous_theme);
+ invalidate_after_theme_or_font_change();
+}
+
void WindowManager::did_popup_a_menu(Badge<Menu>)
{
// Clear any ongoing input gesture
diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h
index f2272ebfb5..bfd1e8d01e 100644
--- a/Userland/Services/WindowServer/WindowManager.h
+++ b/Userland/Services/WindowServer/WindowManager.h
@@ -220,6 +220,11 @@ public:
bool update_theme(String theme_path, String theme_name, bool keep_desktop_background);
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; }
+
bool set_hovered_window(Window*);
void deliver_mouse_event(Window&, MouseEvent const&, bool process_double_click);
@@ -431,6 +436,7 @@ private:
int m_max_distance_for_double_click { 4 };
bool m_previous_event_was_super_keydown { false };
bool m_buttons_switched { false };
+ bool m_theme_overridden { false };
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 54ed6d1a74..38ed398a92 100644
--- a/Userland/Services/WindowServer/WindowServer.ipc
+++ b/Userland/Services/WindowServer/WindowServer.ipc
@@ -129,6 +129,11 @@ endpoint WindowServer
get_system_theme() => ([UTF8] String theme_name)
refresh_system_theme() =|
+ set_system_theme_override(Core::AnonymousBuffer buffer) => (bool success)
+ get_system_theme_override() => (Optional<Core::AnonymousBuffer> buffer)
+ clear_system_theme_override() =|
+ is_system_theme_overridden() => (bool overridden)
+
apply_cursor_theme(String name) =|
get_cursor_theme() => (String name)