chore: Add clang-format configuration and format MPD module
parent
235997fa73
commit
cd92b475ad
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
BasedOnStyle: Google
|
||||
ColumnLimit: '100'
|
||||
|
||||
AlignConsecutiveDeclarations: true
|
||||
BinPackArguments: false
|
||||
ColumnLimit: 100
|
||||
...
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#include <fmt/format.h>
|
||||
#include <mpd/client.h>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#include "ALabel.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
@ -12,6 +12,7 @@ class MPD : public ALabel {
|
|||
public:
|
||||
MPD(const std::string&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
std::thread periodic_updater();
|
||||
void setLabel();
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "modules/mpd.hpp"
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
waybar::modules::MPD::MPD(const std::string& id, const Json::Value &config)
|
||||
waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{album} - {artist} - {title}", 5),
|
||||
server_(nullptr),
|
||||
port_(config["port"].asUInt()),
|
||||
|
@ -24,8 +23,7 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value &config)
|
|||
event_listener().detach();
|
||||
|
||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||
event_box_.signal_button_press_event().connect(
|
||||
sigc::mem_fun(*this, &MPD::handlePlayPause));
|
||||
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &MPD::handlePlayPause));
|
||||
}
|
||||
|
||||
auto waybar::modules::MPD::update() -> void {
|
||||
|
@ -77,14 +75,16 @@ void waybar::modules::MPD::setLabel() {
|
|||
// In the case connection closed while MPD is stopped
|
||||
label_.get_style_context()->remove_class("stopped");
|
||||
|
||||
auto format = config_["format-disconnected"].isString() ?
|
||||
config_["format-disconnected"].asString() : "disconnected";
|
||||
auto format = config_["format-disconnected"].isString()
|
||||
? config_["format-disconnected"].asString()
|
||||
: "disconnected";
|
||||
label_.set_markup(format);
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
std::string tooltip_format;
|
||||
tooltip_format = config_["tooltip-format-disconnected"].isString() ?
|
||||
config_["tooltip-format-disconnected"].asString() : "MPD (disconnected)";
|
||||
tooltip_format = config_["tooltip-format-disconnected"].isString()
|
||||
? config_["tooltip-format-disconnected"].asString()
|
||||
: "MPD (disconnected)";
|
||||
// Nothing to format
|
||||
label_.set_tooltip_text(tooltip_format);
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ void waybar::modules::MPD::setLabel() {
|
|||
|
||||
std::string stateIcon = "";
|
||||
if (stopped()) {
|
||||
format = config_["format-stopped"].isString() ?
|
||||
config_["format-stopped"].asString() : "stopped";
|
||||
format =
|
||||
config_["format-stopped"].isString() ? config_["format-stopped"].asString() : "stopped";
|
||||
label_.get_style_context()->add_class("stopped");
|
||||
} else {
|
||||
label_.get_style_context()->remove_class("stopped");
|
||||
|
@ -143,8 +143,8 @@ void waybar::modules::MPD::setLabel() {
|
|||
|
||||
if (tooltipEnabled()) {
|
||||
std::string tooltip_format;
|
||||
tooltip_format = config_["tooltip-format"].isString() ?
|
||||
config_["tooltip-format"].asString() : "MPD (connected)";
|
||||
tooltip_format = config_["tooltip-format"].isString() ? config_["tooltip-format"].asString()
|
||||
: "MPD (connected)";
|
||||
auto tooltip_text = fmt::format(tooltip_format,
|
||||
fmt::arg("artist", artist),
|
||||
fmt::arg("albumArtist", album_artist),
|
||||
|
@ -204,13 +204,10 @@ void waybar::modules::MPD::tryConnect() {
|
|||
return;
|
||||
}
|
||||
|
||||
connection_ = unique_connection(
|
||||
mpd_connection_new(server_, port_, 5'000),
|
||||
&mpd_connection_free);
|
||||
connection_ = unique_connection(mpd_connection_new(server_, port_, 5'000), &mpd_connection_free);
|
||||
|
||||
alternate_connection_ = unique_connection(
|
||||
mpd_connection_new(server_, port_, 5'000),
|
||||
&mpd_connection_free);
|
||||
alternate_connection_ =
|
||||
unique_connection(mpd_connection_new(server_, port_, 5'000), &mpd_connection_free);
|
||||
|
||||
if (connection_ == nullptr || alternate_connection_ == nullptr) {
|
||||
std::cerr << "Failed to connect to MPD" << std::endl;
|
||||
|
@ -258,8 +255,10 @@ void waybar::modules::MPD::fetchState() {
|
|||
|
||||
void waybar::modules::MPD::waitForEvent() {
|
||||
auto conn = alternate_connection_.get();
|
||||
// Wait for a player (play/pause), option (random, shuffle, etc.), or playlist change
|
||||
mpd_run_idle_mask(conn, static_cast<mpd_idle>(MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_PLAYLIST));
|
||||
// Wait for a player (play/pause), option (random, shuffle, etc.), or playlist
|
||||
// change
|
||||
mpd_run_idle_mask(conn,
|
||||
static_cast<mpd_idle>(MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_PLAYLIST));
|
||||
checkErrors(conn);
|
||||
}
|
||||
|
||||
|
@ -287,6 +286,4 @@ bool waybar::modules::MPD::stopped() {
|
|||
return connection_ == nullptr || state_ == MPD_STATE_UNKNOWN || state_ == MPD_STATE_STOP;
|
||||
}
|
||||
|
||||
bool waybar::modules::MPD::playing() {
|
||||
return connection_ != nullptr && state_ == MPD_STATE_PLAY;
|
||||
}
|
||||
bool waybar::modules::MPD::playing() { return connection_ != nullptr && state_ == MPD_STATE_PLAY; }
|
||||
|
|
Loading…
Reference in New Issue