Merge pull request #3523 from S0nter/master

cava: Add format_silent option and css triggers
This commit is contained in:
Alexis Rouillard 2024-09-19 17:30:34 +02:00 committed by GitHub
commit b5395f4e6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View File

@ -39,6 +39,7 @@ class Cava final : public ALabel {
std::chrono::seconds suspend_silence_delay_{0};
bool silence_{false};
bool hide_on_silence_{false};
std::string format_silent_{""};
int sleep_counter_{0};
// Cava method
void pause_resume();

View File

@ -64,6 +64,10 @@ libcava lives in:
:[ bool
:[ false
:[ Hides the widget if no input (after sleep_timer elapsed)
|[ *format_silent*
:[ string
:[
:[ Widget's text after sleep_timer elapsed (hide_on_silence has to be false)
|[ *method*
:[ string
:[ pulse
@ -196,3 +200,8 @@ In case when cava releases new version and you're wanna get it, it should be rai
}
},
```
# STYLE
- *#cava*
- *#cava.silent* Applied after no sound has been detected for sleep_timer seconds
- *#cava.updated* Applied when a new frame is shown

View File

@ -59,6 +59,7 @@ waybar::modules::Cava::Cava(const std::string& id, const Json::Value& config)
if (config_["input_delay"].isInt())
fetch_input_delay_ = std::chrono::seconds(config_["input_delay"].asInt());
if (config_["hide_on_silence"].isBool()) hide_on_silence_ = config_["hide_on_silence"].asBool();
if (config_["format_silent"].isString()) format_silent_ = config_["format_silent"].asString();
// Make cava parameters configuration
plan_ = new cava::cava_plan{};
@ -172,10 +173,17 @@ auto waybar::modules::Cava::update() -> void {
label_.set_markup(text_);
label_.show();
ALabel::update();
label_.get_style_context()->add_class("updated");
}
label_.get_style_context()->remove_class("silent");
} else {
upThreadDelay(frame_time_milsec_, suspend_silence_delay_);
if (hide_on_silence_) label_.hide();
else if (config_["format_silent"].isString()) label_.set_markup(format_silent_);
label_.get_style_context()->add_class("silent");
label_.get_style_context()->remove_class("updated");
}
}