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