From 8070a982887be775ee657798452248ce42506d21 Mon Sep 17 00:00:00 2001 From: Ben Maxwell Date: Sun, 3 Apr 2022 10:51:54 +0100 Subject: [PATCH] DisplaySettings+WindowServer: Allow updating theme without background With this change you can now set the theme and background color at the same time in the Display Settings. Before if both were changed before hitting 'apply' the theme background color would overwrite the custom background. --- .../DisplaySettings/BackgroundSettingsWidget.cpp | 15 ++++++++++++--- .../DisplaySettings/BackgroundSettingsWidget.h | 4 +++- .../DisplaySettings/ThemesSettingsWidget.cpp | 6 ++++-- .../DisplaySettings/ThemesSettingsWidget.h | 4 +++- Userland/Applications/DisplaySettings/main.cpp | 6 ++++-- Userland/Services/Taskbar/main.cpp | 2 +- .../WindowServer/ConnectionFromClient.cpp | 4 ++-- .../Services/WindowServer/ConnectionFromClient.h | 2 +- Userland/Services/WindowServer/WindowManager.cpp | 5 +++-- Userland/Services/WindowServer/WindowManager.h | 2 +- Userland/Services/WindowServer/WindowServer.ipc | 2 +- 11 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp index d4c9fdc060..36e635abce 100644 --- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp @@ -31,7 +31,8 @@ namespace DisplaySettings { -BackgroundSettingsWidget::BackgroundSettingsWidget() +BackgroundSettingsWidget::BackgroundSettingsWidget(bool& background_settings_changed) + : m_background_settings_changed { background_settings_changed } { m_modes.append("tile"); m_modes.append("center"); @@ -86,20 +87,27 @@ void BackgroundSettingsWidget::create_frame() return; m_wallpaper_view->selection().clear(); m_monitor_widget->set_wallpaper(path.value()); + m_background_settings_changed = true; }; m_mode_combo = *find_descendant_of_type_named("mode_combo"); m_mode_combo->set_only_allow_values_from_model(true); m_mode_combo->set_model(*GUI::ItemListModel::create(m_modes)); - m_mode_combo->on_change = [this](auto&, const GUI::ModelIndex& index) { + bool first_mode_change = true; + m_mode_combo->on_change = [this, first_mode_change](auto&, const GUI::ModelIndex& index) mutable { m_monitor_widget->set_wallpaper_mode(m_modes.at(index.row())); + m_background_settings_changed = !first_mode_change; + first_mode_change = false; }; m_color_input = *find_descendant_of_type_named("color_input"); m_color_input->set_color_has_alpha_channel(false); m_color_input->set_color_picker_title("Select color for desktop"); - m_color_input->on_change = [this] { + bool first_color_change = true; + m_color_input->on_change = [this, first_color_change]() mutable { m_monitor_widget->set_background_color(m_color_input->color()); + m_background_settings_changed = !first_color_change; + first_color_change = false; }; } @@ -133,6 +141,7 @@ void BackgroundSettingsWidget::load_current_settings() m_color_input->set_color(palette_desktop_color); m_monitor_widget->set_background_color(palette_desktop_color); + m_background_settings_changed = false; } void BackgroundSettingsWidget::apply_settings() diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h index 0fa8a191cf..2a187b0f58 100644 --- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h +++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h @@ -27,13 +27,15 @@ public: virtual void apply_settings() override; private: - BackgroundSettingsWidget(); + BackgroundSettingsWidget(bool& background_settings_changed); void create_frame(); void load_current_settings(); Vector m_modes; + bool& m_background_settings_changed; + RefPtr m_monitor_widget; RefPtr m_wallpaper_view; RefPtr m_mode_combo; diff --git a/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp b/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp index 955c079612..bdfd64ccac 100644 --- a/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/ThemesSettingsWidget.cpp @@ -19,7 +19,8 @@ static inline String current_system_theme() return GUI::ConnectionToWindowServer::the().get_system_theme(); } -ThemesSettingsWidget::ThemesSettingsWidget() +ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed) + : m_background_settings_changed { background_settings_changed } { load_from_gml(themes_settings_gml); m_themes = Gfx::list_installed_system_themes(); @@ -50,7 +51,8 @@ ThemesSettingsWidget::ThemesSettingsWidget() void ThemesSettingsWidget::apply_settings() { if (m_selected_theme && m_selected_theme->name != current_system_theme()) - VERIFY(GUI::ConnectionToWindowServer::the().set_system_theme(m_selected_theme->path, m_selected_theme->name)); + VERIFY(GUI::ConnectionToWindowServer::the().set_system_theme(m_selected_theme->path, m_selected_theme->name, m_background_settings_changed)); + m_background_settings_changed = false; } } diff --git a/Userland/Applications/DisplaySettings/ThemesSettingsWidget.h b/Userland/Applications/DisplaySettings/ThemesSettingsWidget.h index 520a754642..7975487148 100644 --- a/Userland/Applications/DisplaySettings/ThemesSettingsWidget.h +++ b/Userland/Applications/DisplaySettings/ThemesSettingsWidget.h @@ -31,7 +31,9 @@ private: Gfx::SystemThemeMetaData const* m_selected_theme { nullptr }; - ThemesSettingsWidget(); + bool& m_background_settings_changed; + + ThemesSettingsWidget(bool& background_settings_changed); }; } diff --git a/Userland/Applications/DisplaySettings/main.cpp b/Userland/Applications/DisplaySettings/main.cpp index b8b2fef93a..154d9da393 100644 --- a/Userland/Applications/DisplaySettings/main.cpp +++ b/Userland/Applications/DisplaySettings/main.cpp @@ -27,9 +27,11 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app_icon = GUI::Icon::default_icon("app-display-settings"); + bool background_settings_changed = false; + auto window = TRY(GUI::SettingsWindow::create("Display Settings")); - (void)TRY(window->add_tab("Background")); - (void)TRY(window->add_tab("Themes")); + (void)TRY(window->add_tab("Background", background_settings_changed)); + (void)TRY(window->add_tab("Themes", background_settings_changed)); (void)TRY(window->add_tab("Fonts")); (void)TRY(window->add_tab("Monitor")); (void)TRY(window->add_tab("Workspaces")); diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index 5d3f66376a..4150145aa0 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -217,7 +217,7 @@ ErrorOr> build_system_menu() auto action = GUI::Action::create_checkable(theme.name, [theme_identifier](auto&) { auto& theme = g_themes[theme_identifier]; dbgln("Theme switched to {} at path {}", theme.name, theme.path); - auto success = GUI::ConnectionToWindowServer::the().set_system_theme(theme.path, theme.name); + auto success = GUI::ConnectionToWindowServer::the().set_system_theme(theme.path, theme.name, false); VERIFY(success); }); if (theme.name == current_theme_name) diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index aebd1f3e72..76f05ff10f 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.cpp +++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp @@ -790,9 +790,9 @@ Messages::WindowServer::StartDragResponse ConnectionFromClient::start_drag(Strin return true; } -Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(String const& theme_path, String const& theme_name) +Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(String const& theme_path, String const& theme_name, bool keep_desktop_background) { - bool success = WindowManager::the().update_theme(theme_path, theme_name); + bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background); return success; } diff --git a/Userland/Services/WindowServer/ConnectionFromClient.h b/Userland/Services/WindowServer/ConnectionFromClient.h index 6b12169355..1a87563b9c 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.h +++ b/Userland/Services/WindowServer/ConnectionFromClient.h @@ -140,7 +140,7 @@ private: virtual void dismiss_menu(i32) override; virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override; virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap const&, Gfx::ShareableBitmap const&) override; - virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(String const&, String 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 void apply_cursor_theme(String const&) override; virtual Messages::WindowServer::GetCursorThemeResponse get_cursor_theme() override; diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index bf57e84207..bdbbe2c1a5 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -2089,7 +2089,7 @@ void WindowManager::invalidate_after_theme_or_font_change() Compositor::the().invalidate_after_theme_or_font_change(); } -bool WindowManager::update_theme(String theme_path, String theme_name) +bool WindowManager::update_theme(String theme_path, String theme_name, bool keep_desktop_background) { auto new_theme = Gfx::load_system_theme(theme_path); if (!new_theme.is_valid()) @@ -2097,7 +2097,8 @@ bool WindowManager::update_theme(String theme_path, String theme_name) Gfx::set_system_theme(new_theme); m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme); m_config->write_entry("Theme", "Name", theme_name); - m_config->remove_entry("Background", "Color"); + if (!keep_desktop_background) + m_config->remove_entry("Background", "Color"); if (auto result = m_config->sync(); result.is_error()) { dbgln("Failed to save config file: {}", result.error()); return false; diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index 047d6f3866..115b718350 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -213,7 +213,7 @@ public: return nullptr; } - bool update_theme(String theme_path, String theme_name); + bool update_theme(String theme_path, String theme_name, bool keep_desktop_background); void invalidate_after_theme_or_font_change(); bool set_hovered_window(Window*); diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 53849dd3ba..91f69a4467 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -113,7 +113,7 @@ endpoint WindowServer start_drag([UTF8] String text, HashMap mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started) - set_system_theme(String theme_path, [UTF8] String theme_name) => (bool success) + set_system_theme(String theme_path, [UTF8] String theme_name, bool keep_desktop_background) => (bool success) get_system_theme() => ([UTF8] String theme_name) refresh_system_theme() =|