2021-11-01 18:17:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iostream>
|
2023-01-07 00:42:57 +00:00
|
|
|
#include <optional>
|
2021-11-01 18:17:29 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "gtkmm/box.h"
|
|
|
|
#include "gtkmm/label.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <playerctl/playerctl.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "ALabel.hpp"
|
|
|
|
#include "util/sleeper_thread.hpp"
|
|
|
|
|
|
|
|
namespace waybar::modules::mpris {
|
|
|
|
|
2023-02-20 19:37:49 +00:00
|
|
|
class Mpris : public ALabel {
|
2021-11-01 18:17:29 +00:00
|
|
|
public:
|
|
|
|
Mpris(const std::string&, const Json::Value&);
|
2023-03-02 13:57:07 +00:00
|
|
|
virtual ~Mpris();
|
|
|
|
auto update() -> void override;
|
|
|
|
bool handleToggle(GdkEventButton* const&) override;
|
2021-11-01 18:17:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static auto onPlayerNameAppeared(PlayerctlPlayerManager*, PlayerctlPlayerName*, gpointer) -> void;
|
|
|
|
static auto onPlayerNameVanished(PlayerctlPlayerManager*, PlayerctlPlayerName*, gpointer) -> void;
|
|
|
|
static auto onPlayerPlay(PlayerctlPlayer*, gpointer) -> void;
|
|
|
|
static auto onPlayerPause(PlayerctlPlayer*, gpointer) -> void;
|
|
|
|
static auto onPlayerStop(PlayerctlPlayer*, gpointer) -> void;
|
|
|
|
static auto onPlayerMetadata(PlayerctlPlayer*, GVariant*, gpointer) -> void;
|
|
|
|
|
|
|
|
struct PlayerInfo {
|
|
|
|
std::string name;
|
|
|
|
PlayerctlPlaybackStatus status;
|
|
|
|
std::string status_string;
|
|
|
|
|
|
|
|
std::optional<std::string> artist;
|
|
|
|
std::optional<std::string> album;
|
|
|
|
std::optional<std::string> title;
|
2023-02-20 20:38:26 +00:00
|
|
|
std::optional<std::string> length; // as HH:MM:SS
|
|
|
|
std::optional<std::string> position; // same format
|
2021-11-01 18:17:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto getPlayerInfo() -> std::optional<PlayerInfo>;
|
2023-02-20 19:37:49 +00:00
|
|
|
auto getIconFromJson(const Json::Value&, const std::string&) -> std::string;
|
2023-02-16 12:41:24 +00:00
|
|
|
auto getArtistStr(const PlayerInfo&, bool) -> std::string;
|
|
|
|
auto getAlbumStr(const PlayerInfo&, bool) -> std::string;
|
|
|
|
auto getTitleStr(const PlayerInfo&, bool) -> std::string;
|
|
|
|
auto getLengthStr(const PlayerInfo&, bool) -> std::string;
|
2023-02-16 20:41:38 +00:00
|
|
|
auto getPositionStr(const PlayerInfo&, bool) -> std::string;
|
2023-02-16 12:41:24 +00:00
|
|
|
auto getDynamicStr(const PlayerInfo&, bool, bool) -> std::string;
|
2021-11-01 18:17:29 +00:00
|
|
|
|
|
|
|
// config
|
|
|
|
std::string format_playing_;
|
|
|
|
std::string format_paused_;
|
|
|
|
std::string format_stopped_;
|
2023-02-16 12:41:24 +00:00
|
|
|
|
|
|
|
std::string tooltip_;
|
|
|
|
std::string tooltip_playing_;
|
|
|
|
std::string tooltip_paused_;
|
|
|
|
std::string tooltip_stopped_;
|
|
|
|
|
|
|
|
int artist_len_;
|
|
|
|
int album_len_;
|
|
|
|
int title_len_;
|
|
|
|
int dynamic_len_;
|
|
|
|
std::vector<std::string> dynamic_prio_;
|
2023-07-04 21:05:26 +00:00
|
|
|
std::vector<std::string> dynamic_order_;
|
|
|
|
std::string dynamic_separator_;
|
2023-02-16 20:41:38 +00:00
|
|
|
bool truncate_hours_;
|
2023-02-16 12:41:24 +00:00
|
|
|
bool tooltip_len_limits_;
|
2023-02-16 20:41:38 +00:00
|
|
|
std::string ellipsis_;
|
2023-02-16 12:41:24 +00:00
|
|
|
|
2021-11-01 18:17:29 +00:00
|
|
|
std::string player_;
|
|
|
|
std::vector<std::string> ignored_players_;
|
|
|
|
|
|
|
|
PlayerctlPlayerManager* manager;
|
|
|
|
PlayerctlPlayer* player;
|
|
|
|
std::string lastStatus;
|
|
|
|
std::string lastPlayer;
|
|
|
|
|
|
|
|
util::SleeperThread thread_;
|
2023-07-03 20:46:50 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> last_update_;
|
2021-11-01 18:17:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules::mpris
|