DisplaySettings: Update selected theme on change

Previously the "Theme" tab in DisplaySettings would only reflect the
current theme on startup and get out of sync when a theme would get
selected using the taskbar menu.
This commit is contained in:
networkException
2022-06-16 20:11:56 +02:00
committed by Linus Groh
parent 82f537b847
commit 278fd28502
Notes: sideshowbarker 2024-07-17 10:06:57 +09:00

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
* Copyright (c) 2022, Jakob-Niklas See <git@nwex.de>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -9,6 +10,7 @@
#include <AK/QuickSort.h>
#include <Applications/DisplaySettings/ThemesSettingsGML.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/Application.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/ItemListModel.h>
#include <LibGUI/Process.h>
@@ -54,6 +56,20 @@ ThemesSettingsWidget::ThemesSettingsWidget(bool& background_settings_changed)
m_cursor_themes_button->on_click = [&](auto) {
GUI::Process::spawn_or_show_error(window(), "/bin/MouseSettings", Array { "-t", "cursor-theme" });
};
GUI::Application::the()->on_theme_change = [&]() {
auto current_theme_name = current_system_theme();
size_t index = 0;
for (auto& theme_meta : m_themes) {
if (current_theme_name == theme_meta.name) {
m_themes_combo->set_selected_index(index, GUI::AllowCallback::No);
m_selected_theme = &m_themes.at(index);
m_theme_preview->set_theme(m_selected_theme->path);
}
++index;
}
};
}
void ThemesSettingsWidget::apply_settings()