Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulseaudio: volume indicator update on default output switch #3464

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/util/audio_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class AudioBackend {
std::string desc_;
std::string monitor_;
std::string current_sink_name_;
std::string default_sink_name;
bool default_sink_running_;
bool current_sink_running_;
// SOURCE
uint32_t source_idx_{0};
Expand Down
20 changes: 18 additions & 2 deletions src/util/audio_backend.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "util/audio_backend.hpp"

#include <fmt/core.h>
#include <pulse/def.h>
#include <pulse/error.h>
#include <pulse/introspect.h>
#include <pulse/subscribe.h>
#include <pulse/volume.h>
#include <spdlog/spdlog.h>

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -139,6 +142,10 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
void *data) {
if (i == nullptr) return;

auto running = i->state == PA_SINK_RUNNING;
auto idle = i->state == PA_SINK_IDLE;
spdlog::trace("Sink name {} Running:[{}] Idle:[{}]", i->name, running, idle);

auto *backend = static_cast<AudioBackend *>(data);

if (!backend->ignored_sinks_.empty()) {
Expand All @@ -155,11 +162,19 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
}
}

backend->default_sink_running_ = backend->default_sink_name == i->name &&
(i->state == PA_SINK_RUNNING || i->state == PA_SINK_IDLE);

if (i->name != backend->default_sink_name && !backend->default_sink_running_) {
return;
}

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 || i->state == PA_SINK_IDLE);
}

if (!backend->current_sink_running_ && i->state == PA_SINK_RUNNING) {
if (!backend->current_sink_running_ &&
(i->state == PA_SINK_RUNNING || i->state == PA_SINK_IDLE)) {
backend->current_sink_name_ = i->name;
backend->current_sink_running_ = true;
}
Expand Down Expand Up @@ -207,6 +222,7 @@ void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *
void AudioBackend::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) {
auto *backend = static_cast<AudioBackend *>(data);
backend->current_sink_name_ = i->default_sink_name;
backend->default_sink_name = i->default_sink_name;
backend->default_source_name_ = i->default_source_name;

pa_context_get_sink_info_list(context, sinkInfoCb, data);
Expand Down