util: clang-tidy
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace waybar::util {
|
||||
|
||||
@ -15,13 +16,11 @@ AudioBackend::AudioBackend(std::function<void()> on_updated_cb, private_construc
|
||||
: mainloop_(nullptr),
|
||||
mainloop_api_(nullptr),
|
||||
context_(nullptr),
|
||||
sink_idx_(0),
|
||||
volume_(0),
|
||||
muted_(false),
|
||||
source_idx_(0),
|
||||
source_volume_(0),
|
||||
source_muted_(false),
|
||||
on_updated_cb_(on_updated_cb) {
|
||||
on_updated_cb_(std::move(on_updated_cb)) {
|
||||
mainloop_ = pa_threaded_mainloop_new();
|
||||
if (mainloop_ == nullptr) {
|
||||
throw std::runtime_error("pa_mainloop_new() failed.");
|
||||
@ -66,7 +65,7 @@ void AudioBackend::connectContext() {
|
||||
}
|
||||
|
||||
void AudioBackend::contextStateCb(pa_context *c, void *data) {
|
||||
auto backend = static_cast<AudioBackend *>(data);
|
||||
auto *backend = static_cast<AudioBackend *>(data);
|
||||
switch (pa_context_get_state(c)) {
|
||||
case PA_CONTEXT_TERMINATED:
|
||||
backend->mainloop_api_->quit(backend->mainloop_api_, 0);
|
||||
@ -127,7 +126,7 @@ void AudioBackend::subscribeCb(pa_context *context, pa_subscription_event_type_t
|
||||
* Called in response to a volume change request
|
||||
*/
|
||||
void AudioBackend::volumeModifyCb(pa_context *c, int success, void *data) {
|
||||
auto backend = static_cast<AudioBackend *>(data);
|
||||
auto *backend = static_cast<AudioBackend *>(data);
|
||||
if (success != 0) {
|
||||
pa_context_get_sink_info_by_index(backend->context_, backend->sink_idx_, sinkInfoCb, data);
|
||||
}
|
||||
@ -140,7 +139,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
|
||||
void *data) {
|
||||
if (i == nullptr) return;
|
||||
|
||||
auto backend = static_cast<AudioBackend *>(data);
|
||||
auto *backend = static_cast<AudioBackend *>(data);
|
||||
|
||||
if (!backend->ignored_sinks_.empty()) {
|
||||
for (const auto &ignored_sink : backend->ignored_sinks_) {
|
||||
@ -151,11 +150,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
|
||||
}
|
||||
|
||||
if (backend->current_sink_name_ == i->name) {
|
||||
if (i->state != PA_SINK_RUNNING) {
|
||||
backend->current_sink_running_ = false;
|
||||
} else {
|
||||
backend->current_sink_running_ = true;
|
||||
}
|
||||
backend->current_sink_running_ = i->state == PA_SINK_RUNNING;
|
||||
}
|
||||
|
||||
if (!backend->current_sink_running_ && i->state == PA_SINK_RUNNING) {
|
||||
@ -173,7 +168,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
|
||||
backend->desc_ = i->description;
|
||||
backend->monitor_ = i->monitor_source_name;
|
||||
backend->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown";
|
||||
if (auto ff = pa_proplist_gets(i->proplist, PA_PROP_DEVICE_FORM_FACTOR)) {
|
||||
if (const auto *ff = pa_proplist_gets(i->proplist, PA_PROP_DEVICE_FORM_FACTOR)) {
|
||||
backend->form_factor_ = ff;
|
||||
} else {
|
||||
backend->form_factor_ = "";
|
||||
@ -187,7 +182,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
|
||||
*/
|
||||
void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *i, int /*eol*/,
|
||||
void *data) {
|
||||
auto backend = static_cast<AudioBackend *>(data);
|
||||
auto *backend = static_cast<AudioBackend *>(data);
|
||||
if (i != nullptr && backend->default_source_name_ == i->name) {
|
||||
auto source_volume = static_cast<float>(pa_cvolume_avg(&(i->volume))) / float{PA_VOLUME_NORM};
|
||||
backend->source_volume_ = std::round(source_volume * 100.0F);
|
||||
@ -204,7 +199,7 @@ void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *
|
||||
* used to find the default PulseAudio sink.
|
||||
*/
|
||||
void AudioBackend::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) {
|
||||
auto backend = static_cast<AudioBackend *>(data);
|
||||
auto *backend = static_cast<AudioBackend *>(data);
|
||||
backend->current_sink_name_ = i->default_sink_name;
|
||||
backend->default_source_name_ = i->default_source_name;
|
||||
|
||||
@ -253,22 +248,26 @@ void AudioBackend::changeVolume(ChangeType change_type, double step, uint16_t ma
|
||||
|
||||
void AudioBackend::toggleSinkMute() {
|
||||
muted_ = !muted_;
|
||||
pa_context_set_sink_mute_by_index(context_, sink_idx_, muted_, nullptr, nullptr);
|
||||
pa_context_set_sink_mute_by_index(context_, sink_idx_, static_cast<int>(muted_), nullptr,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void AudioBackend::toggleSinkMute(bool mute) {
|
||||
muted_ = mute;
|
||||
pa_context_set_sink_mute_by_index(context_, sink_idx_, muted_, nullptr, nullptr);
|
||||
pa_context_set_sink_mute_by_index(context_, sink_idx_, static_cast<int>(muted_), nullptr,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void AudioBackend::toggleSourceMute() {
|
||||
source_muted_ = !muted_;
|
||||
pa_context_set_source_mute_by_index(context_, source_idx_, source_muted_, nullptr, nullptr);
|
||||
pa_context_set_source_mute_by_index(context_, source_idx_, static_cast<int>(source_muted_),
|
||||
nullptr, nullptr);
|
||||
}
|
||||
|
||||
void AudioBackend::toggleSourceMute(bool mute) {
|
||||
source_muted_ = mute;
|
||||
pa_context_set_source_mute_by_index(context_, source_idx_, source_muted_, nullptr, nullptr);
|
||||
pa_context_set_source_mute_by_index(context_, source_idx_, static_cast<int>(source_muted_),
|
||||
nullptr, nullptr);
|
||||
}
|
||||
|
||||
bool AudioBackend::isBluetooth() {
|
||||
@ -287,4 +286,4 @@ void AudioBackend::setIgnoredSinks(const Json::Value &config) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace waybar::util
|
||||
} // namespace waybar::util
|
||||
|
Reference in New Issue
Block a user