pulseaudio: Add 'sink-mapping' config option
This commit adds a new optional config to the pulseaudio modules. It
maps sink names to other sink names so that if the current sink is a
key, the sink named by the value is considered to be the current sink
instead of it.
E.g.
"sink-mapping": {
"easyeffects_sink": "speakers_sink"
}
This commit is contained in:
@@ -48,6 +48,7 @@ class AudioBackend {
|
|||||||
std::string default_source_name_;
|
std::string default_source_name_;
|
||||||
|
|
||||||
std::vector<std::string> ignored_sinks_;
|
std::vector<std::string> ignored_sinks_;
|
||||||
|
std::map<std::string, std::string> sink_mapping_;
|
||||||
|
|
||||||
std::function<void()> on_updated_cb_ = NOOP;
|
std::function<void()> on_updated_cb_ = NOOP;
|
||||||
|
|
||||||
@@ -69,6 +70,7 @@ class AudioBackend {
|
|||||||
void changeVolume(ChangeType change_type, double step = 1, uint16_t max_volume = 100);
|
void changeVolume(ChangeType change_type, double step = 1, uint16_t max_volume = 100);
|
||||||
|
|
||||||
void setIgnoredSinks(const Json::Value& config);
|
void setIgnoredSinks(const Json::Value& config);
|
||||||
|
void setSinkMapping(const Json::Value& config);
|
||||||
|
|
||||||
std::string getSinkPortName() const { return port_name_; }
|
std::string getSinkPortName() const { return port_name_; }
|
||||||
std::string getFormFactor() const { return form_factor_; }
|
std::string getFormFactor() const { return form_factor_; }
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ Additionally, you can control the volume by scrolling *up* or *down* while the c
|
|||||||
typeof: array ++
|
typeof: array ++
|
||||||
Sinks in this list will not be shown as active sink by Waybar. Entries should be the sink's description field.
|
Sinks in this list will not be shown as active sink by Waybar. Entries should be the sink's description field.
|
||||||
|
|
||||||
|
*sink-mapping*: ++
|
||||||
|
typeof: object ++
|
||||||
|
Sinks named by the values of this mapping will be considered to be the current sink instead of the sinks named by the respective keys.
|
||||||
|
|
||||||
*menu*: ++
|
*menu*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
Action that popups the menu.
|
Action that popups the menu.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
|
|||||||
|
|
||||||
backend = util::AudioBackend::getInstance([this] { this->dp.emit(); });
|
backend = util::AudioBackend::getInstance([this] { this->dp.emit(); });
|
||||||
backend->setIgnoredSinks(config_["ignored-sinks"]);
|
backend->setIgnoredSinks(config_["ignored-sinks"]);
|
||||||
|
backend->setSinkMapping(config_["sink-mapping"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
|
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ PulseaudioSlider::PulseaudioSlider(const std::string& id, const Json::Value& con
|
|||||||
: ASlider(config, "pulseaudio-slider", id) {
|
: ASlider(config, "pulseaudio-slider", id) {
|
||||||
backend = util::AudioBackend::getInstance([this] { this->dp.emit(); });
|
backend = util::AudioBackend::getInstance([this] { this->dp.emit(); });
|
||||||
backend->setIgnoredSinks(config_["ignored-sinks"]);
|
backend->setIgnoredSinks(config_["ignored-sinks"]);
|
||||||
|
backend->setSinkMapping(config_["sink-mapping"]);
|
||||||
|
|
||||||
if (config_["target"].isString()) {
|
if (config_["target"].isString()) {
|
||||||
std::string target = config_["target"].asString();
|
std::string target = config_["target"].asString();
|
||||||
|
|||||||
@@ -155,6 +155,13 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (const auto mapping = backend->sink_mapping_.find(backend->current_sink_name_);
|
||||||
|
mapping != backend->sink_mapping_.end()) {
|
||||||
|
if (i->name == mapping->second) {
|
||||||
|
backend->current_sink_name_ = i->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (backend->current_sink_name_ == i->name) {
|
if (backend->current_sink_name_ == i->name) {
|
||||||
backend->current_sink_running_ = i->state == PA_SINK_RUNNING;
|
backend->current_sink_running_ = i->state == PA_SINK_RUNNING;
|
||||||
}
|
}
|
||||||
@@ -292,4 +299,14 @@ void AudioBackend::setIgnoredSinks(const Json::Value &config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioBackend::setSinkMapping(const Json::Value &config) {
|
||||||
|
if (config.isObject()) {
|
||||||
|
for (auto it = config.begin(); it != config.end(); ++it) {
|
||||||
|
if (it.key().isString() && it->isString()) {
|
||||||
|
sink_mapping_.emplace(it.key().asString(), it->asString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace waybar::util
|
} // namespace waybar::util
|
||||||
|
|||||||
Reference in New Issue
Block a user