Waybar/include/modules/mpd.hpp

51 lines
1.3 KiB
C++
Raw Normal View History

2019-04-16 14:34:37 +00:00
#pragma once
#include <thread>
#include <fmt/format.h>
#include <mpd/client.h>
#include "ALabel.hpp"
namespace waybar::modules {
class MPD : public ALabel {
public:
MPD(const std::string&, const Json::Value&);
auto update() -> void;
private:
std::thread worker();
void setLabel();
std::string getStateIcon();
std::string getOptionIcon(std::string optionName, bool activated);
2019-04-16 14:34:37 +00:00
void tryConnect();
void checkErrors();
2019-04-16 14:34:37 +00:00
void fetchState();
void waitForEvent();
bool handlePlayPause(GdkEventButton* const&);
2019-04-16 14:34:37 +00:00
std::thread worker_;
using unique_connection = std::unique_ptr<mpd_connection, decltype(&mpd_connection_free)>;
using unique_status = std::unique_ptr<mpd_status, decltype(&mpd_status_free)>;
using unique_song = std::unique_ptr<mpd_song, decltype(&mpd_song_free)>;
2019-04-16 14:34:37 +00:00
// Not using unique_ptr since we don't manage the pointer
// (It's either nullptr, or from the config)
const char* server_;
const unsigned port_;
2019-04-16 14:34:37 +00:00
unique_connection connection_;
// Use two connections because the main one will be blocking most of the time.
// Used to send play/pause events and poll elapsed time.
unique_connection alternate_connection_;
2019-04-16 14:34:37 +00:00
unique_status status_;
mpd_state state_;
2019-04-16 14:34:37 +00:00
unique_song song_;
bool stopped_;
};
} // namespace waybar::modules