Merge remote-tracking branch 'origin/master' into pr-3818
# Conflicts: # src/modules/pulseaudio.cpp
This commit is contained in:
+25
-20
@@ -1,15 +1,20 @@
|
||||
#include "modules/pulseaudio.hpp"
|
||||
|
||||
waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value &config)
|
||||
waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "pulseaudio", id, "{volume}%") {
|
||||
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleScroll));
|
||||
|
||||
backend = util::AudioBackend::getInstance([this] { this->dp.emit(); });
|
||||
backend->setIgnoredSinks(config_["ignored-sinks"]);
|
||||
backend->setSinkMapping(config_["sink-mapping"]);
|
||||
|
||||
if (config_["target"].isString() && config_["target"].asString() == "source") {
|
||||
target = util::PulseaudioTarget::Source;
|
||||
}
|
||||
}
|
||||
|
||||
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
|
||||
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll* e) {
|
||||
// change the pulse volume only when no user provided
|
||||
// events are configured
|
||||
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||
@@ -33,7 +38,7 @@ bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
|
||||
? util::ChangeType::Increase
|
||||
: util::ChangeType::Decrease;
|
||||
|
||||
backend->changeVolume(change_type, step, max_volume);
|
||||
backend->changeVolume(change_type, step, max_volume, target);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,7 +56,7 @@ const std::vector<std::string> waybar::modules::Pulseaudio::getPulseIcon() const
|
||||
res.push_back(backend->getDefaultSourceName());
|
||||
std::string nameLC = backend->getSinkPortName() + backend->getFormFactor();
|
||||
std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower);
|
||||
for (auto const &port : ports) {
|
||||
for (auto const& port : ports) {
|
||||
if (nameLC.find(port) != std::string::npos) {
|
||||
if (sink_muted) {
|
||||
res.emplace_back(port + "-muted");
|
||||
@@ -68,7 +73,6 @@ const std::vector<std::string> waybar::modules::Pulseaudio::getPulseIcon() const
|
||||
|
||||
auto waybar::modules::Pulseaudio::update() -> void {
|
||||
auto format = format_;
|
||||
std::string tooltip_format;
|
||||
auto sink_volume = backend->getSinkVolume();
|
||||
if (!alt_) {
|
||||
std::string format_name = "format";
|
||||
@@ -115,30 +119,31 @@ auto waybar::modules::Pulseaudio::update() -> void {
|
||||
auto sink_desc = backend->getSinkDesc();
|
||||
auto source_desc = backend->getSourceDesc();
|
||||
|
||||
format_source = fmt::format(fmt::runtime(format_source), fmt::arg("volume", source_volume), fmt::arg("source_desc", source_desc));
|
||||
auto text = fmt::format(
|
||||
fmt::runtime(format), fmt::arg("desc", sink_desc), fmt::arg("volume", sink_volume),
|
||||
fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume),
|
||||
fmt::arg("source_desc", source_desc), fmt::arg("icon", getIcon(sink_volume, getPulseIcon())));
|
||||
format_source = fmt::format(fmt::runtime(format_source), fmt::arg("volume", source_volume),
|
||||
fmt::arg("source_desc", source_desc));
|
||||
|
||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
||||
store.push_back(fmt::arg("desc", sink_desc));
|
||||
store.push_back(fmt::arg("volume", sink_volume));
|
||||
store.push_back(fmt::arg("format_source", format_source));
|
||||
store.push_back(fmt::arg("source_volume", source_volume));
|
||||
store.push_back(fmt::arg("source_desc", source_desc));
|
||||
store.push_back(fmt::arg("icon", getIcon(sink_volume, getPulseIcon())));
|
||||
|
||||
auto text = fmt::vformat(format, store);
|
||||
if (text.empty()) {
|
||||
label_.hide();
|
||||
} else {
|
||||
label_.set_markup(text);
|
||||
setLabelMarkup(text);
|
||||
label_.show();
|
||||
}
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
|
||||
tooltip_format = config_["tooltip-format"].asString();
|
||||
}
|
||||
auto tooltip_format = resolveTooltipFormat("");
|
||||
if (!tooltip_format.empty()) {
|
||||
label_.set_tooltip_markup(fmt::format(
|
||||
fmt::runtime(tooltip_format), fmt::arg("desc", sink_desc),
|
||||
fmt::arg("volume", sink_volume), fmt::arg("format_source", format_source),
|
||||
fmt::arg("source_volume", source_volume), fmt::arg("source_desc", source_desc),
|
||||
fmt::arg("icon", getIcon(sink_volume, getPulseIcon()))));
|
||||
setTooltipMarkup(fmt::vformat(tooltip_format, store));
|
||||
} else {
|
||||
label_.set_tooltip_text(sink_desc);
|
||||
setTooltipMarkup(sink_desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user