mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Add mpris module
Uses libplayerctl to use the MPRIS dbus protocol to query, listen and control media players. Signed-off-by: Robert Günzler <r@gnzler.io>
This commit is contained in:
@ -41,6 +41,9 @@
|
||||
#ifdef HAVE_DBUSMENU
|
||||
#include "modules/sni/tray.hpp"
|
||||
#endif
|
||||
#ifdef HAVE_MPRIS
|
||||
#include "modules/mpris/mpris.hpp"
|
||||
#endif
|
||||
#ifdef HAVE_LIBNL
|
||||
#include "modules/network.hpp"
|
||||
#endif
|
||||
|
67
include/modules/mpris/mpris.hpp
Normal file
67
include/modules/mpris/mpris.hpp
Normal file
@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#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 {
|
||||
|
||||
class Mpris : public AModule {
|
||||
public:
|
||||
Mpris(const std::string&, const Json::Value&);
|
||||
~Mpris();
|
||||
auto update() -> void;
|
||||
bool handleToggle(GdkEventButton* const&);
|
||||
|
||||
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;
|
||||
std::optional<std::string> length; // as HH:MM:SS
|
||||
};
|
||||
|
||||
auto getPlayerInfo() -> std::optional<PlayerInfo>;
|
||||
auto getIcon(const Json::Value&, const std::string&) -> std::string;
|
||||
|
||||
Gtk::Box box_;
|
||||
Gtk::Label label_;
|
||||
|
||||
// config
|
||||
std::string format_;
|
||||
std::string format_playing_;
|
||||
std::string format_paused_;
|
||||
std::string format_stopped_;
|
||||
std::chrono::seconds interval_;
|
||||
std::string player_;
|
||||
std::vector<std::string> ignored_players_;
|
||||
|
||||
PlayerctlPlayerManager* manager;
|
||||
PlayerctlPlayer* player;
|
||||
std::string lastStatus;
|
||||
std::string lastPlayer;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::mpris
|
Reference in New Issue
Block a user