Make CssReloadHelper watch CSS new style on appearance change

If you have reload_style_on_change enabled, and use dynamic appearance
styling (style-dark.css and style-light.css), then changing the
appearance doesn't update the files that are being watched for reload.

Add a method to CssReloadHelper to change the CSS file being watched,
and also provide the CSS file as a parameter to the callback so setupCss
can be called on the right file when the file watcher triggers.
This commit is contained in:
BBaoVanC
2026-02-21 21:42:34 -06:00
parent 54e7451cf0
commit 55fa8cf185
4 changed files with 16 additions and 6 deletions
+9 -2
View File
@@ -23,7 +23,8 @@ namespace {
const std::regex IMPORT_REGEX(R"(@import\s+(?:url\()?(?:"|')([^"')]+)(?:"|')\)?;)");
}
waybar::CssReloadHelper::CssReloadHelper(std::string cssFile, std::function<void()> callback)
waybar::CssReloadHelper::CssReloadHelper(std::string cssFile,
std::function<void(const std::string&)> callback)
: m_cssFile(std::move(cssFile)), m_callback(std::move(callback)) {}
std::string waybar::CssReloadHelper::getFileContents(const std::string& filename) {
@@ -88,6 +89,12 @@ void waybar::CssReloadHelper::monitorChanges() {
}
}
void waybar::CssReloadHelper::changeCssFile(const std::string& newCssFile) {
m_fileMonitors.clear();
m_cssFile = newCssFile;
monitorChanges();
}
void waybar::CssReloadHelper::handleFileChange(Glib::RefPtr<Gio::File> const& file,
Glib::RefPtr<Gio::File> const& other_type,
Gio::FileMonitorEvent event_type) {
@@ -95,7 +102,7 @@ void waybar::CssReloadHelper::handleFileChange(Glib::RefPtr<Gio::File> const& fi
// fire for one
if (event_type == Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
spdlog::debug("Reloading style, file changed: {}", file->get_path());
m_callback();
m_callback(m_cssFile);
}
}