mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-01 15:43:36 +03:00
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.
This commit is contained in:
parent
278fd28502
commit
976b6156d4
Notes:
sideshowbarker
2024-07-17 10:06:53 +09:00
Author: https://github.com/networkException Commit: https://github.com/SerenityOS/serenity/commit/976b6156d4 Pull-request: https://github.com/SerenityOS/serenity/pull/14305 Reviewed-by: https://github.com/linusg ✅
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user