Skip to content

Make CssReloadHelper watch CSS new style on appearance change#4804

Open
BBaoVanC wants to merge 1 commit intoAlexays:masterfrom
BBaoVanC:fix-appearance-change-css-watching
Open

Make CssReloadHelper watch CSS new style on appearance change#4804
BBaoVanC wants to merge 1 commit intoAlexays:masterfrom
BBaoVanC:fix-appearance-change-css-watching

Conversation

@BBaoVanC
Copy link
Contributor

@BBaoVanC BBaoVanC commented Feb 2, 2026

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.

To me this API was the most obvious way to fix it, but I'm open to other ideas.

TODO: tests?

@BBaoVanC BBaoVanC force-pushed the fix-appearance-change-css-watching branch from 858adf8 to 277bf02 Compare February 2, 2026 20:29
@Alexays Alexays requested a review from Copilot February 4, 2026 09:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where CSS file reload monitoring doesn't update when the application appearance changes between light and dark themes. When users have reload_style_on_change enabled and switch between style-dark.css and style-light.css, the file watcher continues monitoring the old CSS file instead of switching to the new one.

Changes:

  • Modified CssReloadHelper callback signature to pass the CSS file path as a parameter
  • Added changeCssFile method to update the monitored CSS file
  • Updated appearance change handler to call changeCssFile when switching themes

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
include/util/css_reload_helper.hpp Updated callback signature to include CSS file parameter; added changeCssFile method declaration
src/util/css_reload_helper.cpp Implemented changeCssFile to clear old monitors and set up new ones; updated callback invocation to pass CSS file
src/client.cpp Modified callback lambda to accept CSS file parameter; added call to changeCssFile in appearance change handler
test/utils/css_reload_helper.cpp Updated test callback signature to match new API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +92 to +94
m_fileMonitors.clear();
m_cssFile = newCssFile;
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a potential race condition in changeCssFile. If a file change event from the old monitors fires after m_fileMonitors.clear() but during or after m_cssFile = newCssFile, the handleFileChange callback will be invoked with the new CSS file path for a change in the old file. To fix this, the new CSS file path should be assigned after setting up the new monitors, or the old signal connections should be explicitly disconnected before clearing the monitors.

Suggested change
m_fileMonitors.clear();
m_cssFile = newCssFile;
// Cancel existing monitors to avoid receiving further events from the old CSS file.
for (auto& monitor : m_fileMonitors) {
if (monitor) {
monitor->cancel();
}
}
m_fileMonitors.clear();
m_cssFile = std::move(newCssFile);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, clearing m_fileMonitors drops all of the old monitors since they no longer have any references.

class CssReloadHelperTest : public waybar::CssReloadHelper {
public:
CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this]() { callback(); }) {}
CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this](const std::string&) { callback(); }) {}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new changeCssFile method lacks test coverage. Since the test file already contains comprehensive tests for other methods in CssReloadHelper, tests should be added for changeCssFile to verify that it correctly updates the monitored CSS file and clears/re-establishes file monitors.

Copilot uses AI. Check for mistakes.
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.
@BBaoVanC BBaoVanC force-pushed the fix-appearance-change-css-watching branch from b480df5 to 86284c1 Compare February 4, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant