modules: Set style-context on button

Fixes issue where the class parameters in style.css would have no
effect.

The CSS now references the GtkButton instead of the GtkLabel. Removing
all style-classes from the custom module GtkButton however removes
any properties set via style.css. Thus, the default classes 'flat' and
'text-button' are added on every update of these modules.
This commit is contained in:
Simon Plakolb
2021-05-29 19:40:50 +02:00
parent 0012bcbd74
commit 8fa5d9b838
12 changed files with 49 additions and 47 deletions

View File

@ -240,9 +240,9 @@ auto waybar::modules::Pulseaudio::update() -> void {
if (monitor_.find("a2dp_sink") != std::string::npos || // PulseAudio
monitor_.find("a2dp-sink") != std::string::npos) { // PipeWire
format_name = format_name + "-bluetooth";
label_->get_style_context()->add_class("bluetooth");
button_.get_style_context()->add_class("bluetooth");
} else {
label_->get_style_context()->remove_class("bluetooth");
button_.get_style_context()->remove_class("bluetooth");
}
if (muted_) {
// Check muted bluetooth format exist, otherwise fallback to default muted format
@ -250,23 +250,23 @@ auto waybar::modules::Pulseaudio::update() -> void {
format_name = "format";
}
format_name = format_name + "-muted";
label_->get_style_context()->add_class("muted");
label_->get_style_context()->add_class("sink-muted");
button_.get_style_context()->add_class("muted");
button_.get_style_context()->add_class("sink-muted");
} else {
label_->get_style_context()->remove_class("muted");
label_->get_style_context()->remove_class("sink-muted");
button_.get_style_context()->remove_class("muted");
button_.get_style_context()->remove_class("sink-muted");
}
format = config_[format_name].isString() ? config_[format_name].asString() : format;
}
// TODO: find a better way to split source/sink
std::string format_source = "{volume}%";
if (source_muted_) {
label_->get_style_context()->add_class("source-muted");
button_.get_style_context()->add_class("source-muted");
if (config_["format-source-muted"].isString()) {
format_source = config_["format-source-muted"].asString();
}
} else {
label_->get_style_context()->remove_class("source-muted");
button_.get_style_context()->remove_class("source-muted");
if (config_["format-source-muted"].isString()) {
format_source = config_["format-source"].asString();
}