2020-10-04 05:01:51 +00:00
|
|
|
#include "modules/mpd/mpd.hpp"
|
2019-04-16 14:34:37 +00:00
|
|
|
|
2020-10-18 08:45:31 +00:00
|
|
|
#include <fmt/chrono.h>
|
2021-01-31 02:04:59 +00:00
|
|
|
#include <glibmm/ustring.h>
|
2022-04-06 06:37:19 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
2022-10-09 17:13:54 +00:00
|
|
|
#include <util/sanitize_str.hpp>
|
|
|
|
using namespace waybar::util;
|
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
#include "modules/mpd/state.hpp"
|
|
|
|
#if defined(MPD_NOINLINE)
|
|
|
|
namespace waybar::modules {
|
|
|
|
#include "modules/mpd/state.inl.hpp"
|
|
|
|
} // namespace waybar::modules
|
|
|
|
#endif
|
|
|
|
|
2019-04-18 09:31:47 +00:00
|
|
|
waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
|
2022-11-24 11:28:52 +00:00
|
|
|
: ALabel(config, "mpd", id, "{album} - {artist} - {title}", 5, false, true),
|
2019-04-18 09:48:38 +00:00
|
|
|
module_name_(id.empty() ? "mpd" : "mpd#" + id),
|
2019-04-17 09:01:35 +00:00
|
|
|
server_(nullptr),
|
2019-04-21 08:54:40 +00:00
|
|
|
port_(config_["port"].isUInt() ? config["port"].asUInt() : 0),
|
2020-10-19 18:54:36 +00:00
|
|
|
password_(config_["password"].empty() ? "" : config_["password"].asString()),
|
2019-04-21 08:54:40 +00:00
|
|
|
timeout_(config_["timeout"].isUInt() ? config_["timeout"].asUInt() * 1'000 : 30'000),
|
2019-04-16 14:34:37 +00:00
|
|
|
connection_(nullptr, &mpd_connection_free),
|
|
|
|
status_(nullptr, &mpd_status_free),
|
|
|
|
song_(nullptr, &mpd_song_free) {
|
2019-04-21 08:54:40 +00:00
|
|
|
if (!config_["port"].isNull() && !config_["port"].isUInt()) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::warn("{}: `port` configuration should be an unsigned int", module_name_);
|
2019-04-21 08:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!config_["timeout"].isNull() && !config_["timeout"].isUInt()) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::warn("{}: `timeout` configuration should be an unsigned int", module_name_);
|
2019-04-21 08:54:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 14:34:37 +00:00
|
|
|
if (!config["server"].isNull()) {
|
2019-04-21 08:54:40 +00:00
|
|
|
if (!config_["server"].isString()) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::warn("{}:`server` configuration should be a string", module_name_);
|
2019-04-21 08:54:40 +00:00
|
|
|
}
|
2019-04-17 09:01:35 +00:00
|
|
|
server_ = config["server"].asCString();
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 14:16:39 +00:00
|
|
|
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
2019-04-18 09:31:47 +00:00
|
|
|
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &MPD::handlePlayPause));
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto waybar::modules::MPD::update() -> void {
|
2020-10-04 05:01:51 +00:00
|
|
|
context_.update();
|
|
|
|
|
|
|
|
// Call parent update
|
2022-11-24 11:28:52 +00:00
|
|
|
ALabel::update();
|
2020-10-04 05:01:51 +00:00
|
|
|
}
|
2019-04-16 14:34:37 +00:00
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
void waybar::modules::MPD::queryMPD() {
|
2019-04-16 14:34:37 +00:00
|
|
|
if (connection_ != nullptr) {
|
2020-10-04 05:01:51 +00:00
|
|
|
spdlog::debug("{}: fetching state information", module_name_);
|
2019-04-16 14:34:37 +00:00
|
|
|
try {
|
|
|
|
fetchState();
|
2020-10-04 05:01:51 +00:00
|
|
|
spdlog::debug("{}: fetch complete", module_name_);
|
|
|
|
} catch (std::exception const& e) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::error("{}: {}", module_name_, e.what());
|
2019-04-18 09:17:08 +00:00
|
|
|
state_ = MPD_STATE_UNKNOWN;
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
2020-10-18 08:45:31 +00:00
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
dp.emit();
|
|
|
|
}
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
std::string waybar::modules::MPD::getTag(mpd_tag_type type, unsigned idx) const {
|
2019-04-21 08:54:40 +00:00
|
|
|
std::string result =
|
|
|
|
config_["unknown-tag"].isString() ? config_["unknown-tag"].asString() : "N/A";
|
2019-04-20 16:12:30 +00:00
|
|
|
const char* tag = mpd_song_get_tag(song_.get(), type, idx);
|
|
|
|
|
|
|
|
// mpd_song_get_tag can return NULL, so make sure it's valid before setting
|
2019-04-21 08:54:40 +00:00
|
|
|
if (tag) result = tag;
|
2019-04-20 16:12:30 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-07-22 10:09:09 +00:00
|
|
|
std::string waybar::modules::MPD::getFilename() const {
|
|
|
|
std::string path = mpd_song_get_uri(song_.get());
|
|
|
|
size_t position = path.find_last_of("/");
|
|
|
|
if (position == std::string::npos) {
|
|
|
|
return path;
|
|
|
|
} else {
|
|
|
|
return path.substr(position + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 14:34:37 +00:00
|
|
|
void waybar::modules::MPD::setLabel() {
|
|
|
|
if (connection_ == nullptr) {
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.get_style_context()->add_class("disconnected");
|
|
|
|
label_.get_style_context()->remove_class("stopped");
|
|
|
|
label_.get_style_context()->remove_class("playing");
|
|
|
|
label_.get_style_context()->remove_class("paused");
|
2019-04-16 14:34:37 +00:00
|
|
|
|
2019-04-18 09:31:47 +00:00
|
|
|
auto format = config_["format-disconnected"].isString()
|
|
|
|
? config_["format-disconnected"].asString()
|
|
|
|
: "disconnected";
|
2022-12-02 15:08:56 +00:00
|
|
|
if(format.empty()) {
|
|
|
|
label_.set_markup(format);
|
|
|
|
label_.show();
|
|
|
|
} else {
|
|
|
|
label_.hide();
|
|
|
|
}
|
|
|
|
|
2019-04-17 08:46:08 +00:00
|
|
|
|
|
|
|
if (tooltipEnabled()) {
|
|
|
|
std::string tooltip_format;
|
2019-04-18 09:31:47 +00:00
|
|
|
tooltip_format = config_["tooltip-format-disconnected"].isString()
|
|
|
|
? config_["tooltip-format-disconnected"].asString()
|
|
|
|
: "MPD (disconnected)";
|
2019-04-17 08:46:08 +00:00
|
|
|
// Nothing to format
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.set_tooltip_text(tooltip_format);
|
2019-04-17 08:46:08 +00:00
|
|
|
}
|
2019-04-16 14:34:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-12-02 15:08:56 +00:00
|
|
|
label_.get_style_context()->remove_class("disconnected");
|
2019-04-16 14:34:37 +00:00
|
|
|
|
|
|
|
auto format = format_;
|
2022-04-06 06:37:19 +00:00
|
|
|
Glib::ustring artist, album_artist, album, title;
|
2022-07-22 10:09:09 +00:00
|
|
|
std::string date, filename;
|
2022-04-06 06:37:19 +00:00
|
|
|
int song_pos = 0, queue_length = 0, volume = 0;
|
2019-04-18 09:17:08 +00:00
|
|
|
std::chrono::seconds elapsedTime, totalTime;
|
2019-04-16 14:34:37 +00:00
|
|
|
|
2019-04-17 11:55:08 +00:00
|
|
|
std::string stateIcon = "";
|
2019-04-18 09:17:08 +00:00
|
|
|
if (stopped()) {
|
2019-04-18 09:31:47 +00:00
|
|
|
format =
|
|
|
|
config_["format-stopped"].isString() ? config_["format-stopped"].asString() : "stopped";
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.get_style_context()->add_class("stopped");
|
|
|
|
label_.get_style_context()->remove_class("playing");
|
|
|
|
label_.get_style_context()->remove_class("paused");
|
2019-04-16 14:34:37 +00:00
|
|
|
} else {
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.get_style_context()->remove_class("stopped");
|
2019-04-18 12:30:50 +00:00
|
|
|
if (playing()) {
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.get_style_context()->add_class("playing");
|
|
|
|
label_.get_style_context()->remove_class("paused");
|
2019-10-15 16:24:04 +00:00
|
|
|
} else if (paused()) {
|
2020-10-04 05:01:51 +00:00
|
|
|
format = config_["format-paused"].isString() ? config_["format-paused"].asString()
|
|
|
|
: config_["format"].asString();
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.get_style_context()->add_class("paused");
|
|
|
|
label_.get_style_context()->remove_class("playing");
|
2019-04-18 12:30:50 +00:00
|
|
|
}
|
2019-04-16 14:34:37 +00:00
|
|
|
|
2019-04-17 11:55:08 +00:00
|
|
|
stateIcon = getStateIcon();
|
|
|
|
|
2022-10-09 17:13:54 +00:00
|
|
|
artist = sanitize_string(getTag(MPD_TAG_ARTIST));
|
|
|
|
album_artist = sanitize_string(getTag(MPD_TAG_ALBUM_ARTIST));
|
|
|
|
album = sanitize_string(getTag(MPD_TAG_ALBUM));
|
|
|
|
title = sanitize_string(getTag(MPD_TAG_TITLE));
|
|
|
|
date = sanitize_string(getTag(MPD_TAG_DATE));
|
|
|
|
filename = sanitize_string(getFilename());
|
2022-02-19 01:41:33 +00:00
|
|
|
song_pos = mpd_status_get_song_pos(status_.get()) + 1;
|
2021-04-20 06:25:48 +00:00
|
|
|
volume = mpd_status_get_volume(status_.get());
|
2021-11-11 20:42:05 +00:00
|
|
|
if (volume < 0) {
|
|
|
|
volume = 0;
|
|
|
|
}
|
2020-09-13 15:32:00 +00:00
|
|
|
queue_length = mpd_status_get_queue_length(status_.get());
|
2019-04-18 09:31:47 +00:00
|
|
|
elapsedTime = std::chrono::seconds(mpd_status_get_elapsed_time(status_.get()));
|
|
|
|
totalTime = std::chrono::seconds(mpd_status_get_total_time(status_.get()));
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
bool consumeActivated = mpd_status_get_consume(status_.get());
|
2019-04-17 13:09:06 +00:00
|
|
|
std::string consumeIcon = getOptionIcon("consume", consumeActivated);
|
2022-04-06 06:37:19 +00:00
|
|
|
bool randomActivated = mpd_status_get_random(status_.get());
|
2019-04-17 13:09:06 +00:00
|
|
|
std::string randomIcon = getOptionIcon("random", randomActivated);
|
2022-04-06 06:37:19 +00:00
|
|
|
bool repeatActivated = mpd_status_get_repeat(status_.get());
|
2019-04-17 13:09:06 +00:00
|
|
|
std::string repeatIcon = getOptionIcon("repeat", repeatActivated);
|
2022-04-06 06:37:19 +00:00
|
|
|
bool singleActivated = mpd_status_get_single(status_.get());
|
2019-04-17 13:09:06 +00:00
|
|
|
std::string singleIcon = getOptionIcon("single", singleActivated);
|
2021-02-26 21:29:58 +00:00
|
|
|
if (config_["artist-len"].isInt()) artist = artist.substr(0, config_["artist-len"].asInt());
|
2022-04-06 06:37:19 +00:00
|
|
|
if (config_["album-artist-len"].isInt())
|
|
|
|
album_artist = album_artist.substr(0, config_["album-artist-len"].asInt());
|
2021-02-26 21:29:58 +00:00
|
|
|
if (config_["album-len"].isInt()) album = album.substr(0, config_["album-len"].asInt());
|
2022-04-06 06:37:19 +00:00
|
|
|
if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt());
|
2021-01-31 02:04:59 +00:00
|
|
|
|
2020-10-23 19:13:20 +00:00
|
|
|
try {
|
2022-12-02 15:08:56 +00:00
|
|
|
auto text = fmt::format(
|
2022-11-05 19:20:28 +00:00
|
|
|
format, fmt::arg("artist", artist.raw()), fmt::arg("albumArtist", album_artist.raw()),
|
|
|
|
fmt::arg("album", album.raw()), fmt::arg("title", title.raw()), fmt::arg("date", date),
|
|
|
|
fmt::arg("volume", volume), fmt::arg("elapsedTime", elapsedTime),
|
|
|
|
fmt::arg("totalTime", totalTime), fmt::arg("songPosition", song_pos),
|
|
|
|
fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon),
|
|
|
|
fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon),
|
|
|
|
fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon),
|
2022-12-02 15:08:56 +00:00
|
|
|
fmt::arg("filename", filename));
|
|
|
|
if(text.empty()) {
|
|
|
|
label_.hide();
|
|
|
|
} else {
|
|
|
|
label_.show();
|
|
|
|
label_.set_markup(text);
|
|
|
|
}
|
2020-10-23 19:13:20 +00:00
|
|
|
} catch (fmt::format_error const& e) {
|
|
|
|
spdlog::warn("mpd: format error: {}", e.what());
|
|
|
|
}
|
2019-04-16 14:34:37 +00:00
|
|
|
|
|
|
|
if (tooltipEnabled()) {
|
|
|
|
std::string tooltip_format;
|
2019-04-18 09:31:47 +00:00
|
|
|
tooltip_format = config_["tooltip-format"].isString() ? config_["tooltip-format"].asString()
|
|
|
|
: "MPD (connected)";
|
2020-10-23 19:13:20 +00:00
|
|
|
try {
|
2022-04-06 06:37:19 +00:00
|
|
|
auto tooltip_text =
|
|
|
|
fmt::format(tooltip_format, fmt::arg("artist", artist.raw()),
|
|
|
|
fmt::arg("albumArtist", album_artist.raw()), fmt::arg("album", album.raw()),
|
|
|
|
fmt::arg("title", title.raw()), fmt::arg("date", date),
|
|
|
|
fmt::arg("volume", volume), fmt::arg("elapsedTime", elapsedTime),
|
|
|
|
fmt::arg("totalTime", totalTime), fmt::arg("songPosition", song_pos),
|
|
|
|
fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon),
|
|
|
|
fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon),
|
|
|
|
fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon));
|
2022-11-24 11:28:52 +00:00
|
|
|
label_.set_tooltip_text(tooltip_text);
|
2020-10-23 19:13:20 +00:00
|
|
|
} catch (fmt::format_error const& e) {
|
|
|
|
spdlog::warn("mpd: format error (tooltip): {}", e.what());
|
|
|
|
}
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
std::string waybar::modules::MPD::getStateIcon() const {
|
2019-04-17 11:55:08 +00:00
|
|
|
if (!config_["state-icons"].isObject()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection_ == nullptr) {
|
2019-05-19 00:10:42 +00:00
|
|
|
spdlog::warn("{}: Trying to fetch state icon while disconnected", module_name_);
|
2019-04-17 11:55:08 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:17:08 +00:00
|
|
|
if (stopped()) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::warn("{}: Trying to fetch state icon while stopped", module_name_);
|
2019-04-17 11:55:08 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:17:08 +00:00
|
|
|
if (playing()) {
|
2019-04-17 11:55:08 +00:00
|
|
|
return config_["state-icons"]["playing"].asString();
|
|
|
|
} else {
|
|
|
|
return config_["state-icons"]["paused"].asString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
std::string waybar::modules::MPD::getOptionIcon(std::string optionName, bool activated) const {
|
2019-04-17 13:09:06 +00:00
|
|
|
if (!config_[optionName + "-icons"].isObject()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection_ == nullptr) {
|
2019-05-19 00:10:42 +00:00
|
|
|
spdlog::warn("{}: Trying to fetch option icon while disconnected", module_name_);
|
2019-04-17 13:09:06 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activated) {
|
|
|
|
return config_[optionName + "-icons"]["on"].asString();
|
|
|
|
} else {
|
|
|
|
return config_[optionName + "-icons"]["off"].asString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 14:34:37 +00:00
|
|
|
void waybar::modules::MPD::tryConnect() {
|
|
|
|
if (connection_ != nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-21 08:54:40 +00:00
|
|
|
connection_ =
|
2020-10-04 05:01:51 +00:00
|
|
|
detail::unique_connection(mpd_connection_new(server_, port_, timeout_), &mpd_connection_free);
|
2019-04-16 14:34:37 +00:00
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
if (connection_ == nullptr) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::error("{}: Failed to connect to MPD", module_name_);
|
2019-04-17 14:16:39 +00:00
|
|
|
connection_.reset();
|
2019-04-16 14:34:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-04-18 09:17:08 +00:00
|
|
|
checkErrors(connection_.get());
|
2020-05-16 07:28:30 +00:00
|
|
|
spdlog::debug("{}: Connected to MPD", module_name_);
|
2020-10-19 18:54:36 +00:00
|
|
|
|
|
|
|
if (!password_.empty()) {
|
|
|
|
bool res = mpd_run_password(connection_.get(), password_.c_str());
|
|
|
|
if (!res) {
|
|
|
|
spdlog::error("{}: Wrong MPD password", module_name_);
|
|
|
|
connection_.reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checkErrors(connection_.get());
|
|
|
|
}
|
2019-04-21 08:54:40 +00:00
|
|
|
} catch (std::runtime_error& e) {
|
2019-05-22 10:06:24 +00:00
|
|
|
spdlog::error("{}: Failed to connect to MPD: {}", module_name_, e.what());
|
2019-04-16 14:34:37 +00:00
|
|
|
connection_.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:17:08 +00:00
|
|
|
void waybar::modules::MPD::checkErrors(mpd_connection* conn) {
|
2019-04-16 14:34:37 +00:00
|
|
|
switch (mpd_connection_get_error(conn)) {
|
|
|
|
case MPD_ERROR_SUCCESS:
|
2019-04-21 08:54:40 +00:00
|
|
|
mpd_connection_clear_error(conn);
|
2019-04-16 14:34:37 +00:00
|
|
|
return;
|
2019-04-21 08:54:40 +00:00
|
|
|
case MPD_ERROR_TIMEOUT:
|
2019-04-16 14:34:37 +00:00
|
|
|
case MPD_ERROR_CLOSED:
|
|
|
|
mpd_connection_clear_error(conn);
|
|
|
|
connection_.reset();
|
2019-04-18 09:39:04 +00:00
|
|
|
state_ = MPD_STATE_UNKNOWN;
|
2019-04-21 08:54:40 +00:00
|
|
|
throw std::runtime_error("Connection to MPD closed");
|
2019-04-16 14:34:37 +00:00
|
|
|
default:
|
2020-05-24 16:47:50 +00:00
|
|
|
if (conn) {
|
|
|
|
auto error_message = mpd_connection_get_error_message(conn);
|
2020-10-23 19:13:20 +00:00
|
|
|
std::string error(error_message);
|
2020-05-24 16:47:50 +00:00
|
|
|
mpd_connection_clear_error(conn);
|
2020-10-23 19:13:20 +00:00
|
|
|
throw std::runtime_error(error);
|
2020-05-24 16:47:50 +00:00
|
|
|
}
|
|
|
|
throw std::runtime_error("Invalid connection");
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void waybar::modules::MPD::fetchState() {
|
2020-10-04 05:01:51 +00:00
|
|
|
if (connection_ == nullptr) {
|
|
|
|
spdlog::error("{}: Not connected to MPD", module_name_);
|
2020-10-18 08:45:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
auto conn = connection_.get();
|
2020-10-04 05:01:51 +00:00
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
status_ = detail::unique_status(mpd_run_status(conn), &mpd_status_free);
|
|
|
|
checkErrors(conn);
|
|
|
|
|
|
|
|
state_ = mpd_status_get_state(status_.get());
|
2019-04-21 08:54:40 +00:00
|
|
|
checkErrors(conn);
|
|
|
|
|
2020-10-04 05:01:51 +00:00
|
|
|
song_ = detail::unique_song(mpd_run_current_song(conn), &mpd_song_free);
|
2019-04-18 09:17:08 +00:00
|
|
|
checkErrors(conn);
|
2019-04-16 14:34:37 +00:00
|
|
|
}
|
2019-04-17 14:16:39 +00:00
|
|
|
|
|
|
|
bool waybar::modules::MPD::handlePlayPause(GdkEventButton* const& e) {
|
2019-04-18 09:17:08 +00:00
|
|
|
if (e->type == GDK_2BUTTON_PRESS || e->type == GDK_3BUTTON_PRESS || connection_ == nullptr) {
|
2019-04-17 14:16:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->button == 1) {
|
2020-10-04 05:01:51 +00:00
|
|
|
if (state_ == MPD_STATE_PLAY)
|
|
|
|
context_.pause();
|
|
|
|
else
|
|
|
|
context_.play();
|
2019-04-17 14:16:39 +00:00
|
|
|
} else if (e->button == 3) {
|
2020-10-04 05:01:51 +00:00
|
|
|
context_.stop();
|
2019-04-17 14:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|