mirror of
https://github.com/Alexays/Waybar.git
synced 2025-10-29 19:46:32 +00:00
Merge pull request #4560 from NicolasBuchin/fix-css-memory-leak
fix: resolve memory leak by removing old CSS provider before reloading CSS styles
This commit is contained in:
commit
9221508e51
@ -183,16 +183,24 @@ const std::string waybar::Client::getStyle(const std::string &style,
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto waybar::Client::setupCss(const std::string &css_file) -> void {
|
auto waybar::Client::setupCss(const std::string &css_file) -> void {
|
||||||
css_provider_ = Gtk::CssProvider::create();
|
auto screen = Gdk::Screen::get_default();
|
||||||
style_context_ = Gtk::StyleContext::create();
|
if (!screen) {
|
||||||
|
throw std::runtime_error("No default screen");
|
||||||
|
}
|
||||||
|
|
||||||
// Load our css file, wherever that may be hiding
|
if (css_provider_) {
|
||||||
|
Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_);
|
||||||
|
css_provider_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
css_provider_ = Gtk::CssProvider::create();
|
||||||
if (!css_provider_->load_from_path(css_file)) {
|
if (!css_provider_->load_from_path(css_file)) {
|
||||||
|
css_provider_.reset();
|
||||||
throw std::runtime_error("Can't open style file");
|
throw std::runtime_error("Can't open style file");
|
||||||
}
|
}
|
||||||
// there's always only one screen
|
|
||||||
style_context_->add_provider_for_screen(Gdk::Screen::get_default(), css_provider_,
|
Gtk::StyleContext::add_provider_for_screen(screen, css_provider_,
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Client::bindInterfaces() {
|
void waybar::Client::bindInterfaces() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user