Skip to content

Commit

Permalink
Merge pull request #3464 from findus/pulseaudio-default-sink
Browse files Browse the repository at this point in the history
pulseaudio: volume indicator update on default output switch
  • Loading branch information
Alexays authored Oct 25, 2024
2 parents dacecb9 + 57156bc commit 9d89dda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit 9d89dda

Please sign in to comment.