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.
This commit is contained in:
parent
e6ad55ab53
commit
8070a98288
Notes:
sideshowbarker
2024-07-17 14:33:59 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/8070a98288 Pull-request: https://github.com/SerenityOS/serenity/pull/13456 Issue: https://github.com/SerenityOS/serenity/issues/13448
11 changed files with 35 additions and 17 deletions
|
@ -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<GUI::ComboBox>("mode_combo");
|
||||
m_mode_combo->set_only_allow_values_from_model(true);
|
||||
m_mode_combo->set_model(*GUI::ItemListModel<String>::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<GUI::ColorInput>("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()
|
||||
|
|
|
@ -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<String> m_modes;
|
||||
|
||||
bool& m_background_settings_changed;
|
||||
|
||||
RefPtr<DisplaySettings::MonitorWidget> m_monitor_widget;
|
||||
RefPtr<GUI::IconView> m_wallpaper_view;
|
||||
RefPtr<GUI::ComboBox> m_mode_combo;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ private:
|
|||
|
||||
Gfx::SystemThemeMetaData const* m_selected_theme { nullptr };
|
||||
|
||||
ThemesSettingsWidget();
|
||||
bool& m_background_settings_changed;
|
||||
|
||||
ThemesSettingsWidget(bool& background_settings_changed);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -27,9 +27,11 @@ ErrorOr<int> 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<DisplaySettings::BackgroundSettingsWidget>("Background"));
|
||||
(void)TRY(window->add_tab<DisplaySettings::ThemesSettingsWidget>("Themes"));
|
||||
(void)TRY(window->add_tab<DisplaySettings::BackgroundSettingsWidget>("Background", background_settings_changed));
|
||||
(void)TRY(window->add_tab<DisplaySettings::ThemesSettingsWidget>("Themes", background_settings_changed));
|
||||
(void)TRY(window->add_tab<DisplaySettings::FontSettingsWidget>("Fonts"));
|
||||
(void)TRY(window->add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor"));
|
||||
(void)TRY(window->add_tab<DisplaySettings::DesktopSettingsWidget>("Workspaces"));
|
||||
|
|
|
@ -217,7 +217,7 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> 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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, ByteBuffer> 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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*);
|
||||
|
|
|
@ -113,7 +113,7 @@ endpoint WindowServer
|
|||
|
||||
start_drag([UTF8] String text, HashMap<String,ByteBuffer> 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() =|
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue