-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1520 from robertgzr/mpris-module
- Loading branch information
Showing
8 changed files
with
586 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
waybar-mpris(5) | ||
|
||
# NAME | ||
|
||
waybar - MPRIS module | ||
|
||
# DESCRIPTION | ||
|
||
The *mpris* module displays currently playing media via libplayerctl. | ||
|
||
# CONFIGURATION | ||
|
||
*player*: ++ | ||
typeof: string ++ | ||
default: playerctld ++ | ||
Name of the MPRIS player to attach to. Using the default value always | ||
follows the currenly active player. | ||
|
||
*ignored-players*: ++ | ||
typeof: []string ++ | ||
Ignore updates of the listed players, when using playerctld. | ||
|
||
*interval*: ++ | ||
typeof: integer ++ | ||
Refresh MPRIS information on a timer. | ||
|
||
*format*: ++ | ||
typeof: string ++ | ||
default: {player} ({status}) {dynamic} ++ | ||
The text format. | ||
|
||
*format-[status]*: ++ | ||
typeof: string ++ | ||
The status-specific text format. | ||
|
||
*on-click*: ++ | ||
typeof: string ++ | ||
default: play-pause ++ | ||
Overwrite default action toggles. | ||
|
||
*on-middle-click*: ++ | ||
typeof: string ++ | ||
default: previous track ++ | ||
Overwrite default action toggles. | ||
|
||
*on-right-click*: ++ | ||
typeof: string ++ | ||
default: next track ++ | ||
Overwrite default action toggles. | ||
|
||
*player-icons*: ++ | ||
typeof: map[string]string | ||
Allows setting _{player-icon}_ based on player-name property. | ||
|
||
*status-icons*: ++ | ||
typeof: map[string]string | ||
Allows setting _{status-icon}_ based on player status (playing, paused, | ||
stopped). | ||
|
||
|
||
# FORMAT REPLACEMENTS | ||
|
||
*{player}*: The name of the current media player | ||
|
||
*{status}*: The current status (playing, paused, stopped) | ||
|
||
*{artist}*: The artist of the current track | ||
|
||
*{album}*: The album title of the current track | ||
|
||
*{title}*: The title of the current track | ||
|
||
*{length}*: Length of the track, formatted as HH:MM:SS | ||
|
||
*{dynamic}*: Use _{artist}_, _{album}_, _{title}_ and _{length}_, automatically omit++ | ||
empty values | ||
|
||
*{player-icon}*: Chooses an icon from _player-icons_ based on _{player}_ | ||
|
||
*{status-icon}*: Chooses an icon from _status-icons_ based on _{status}_ | ||
|
||
# EXAMPLES | ||
|
||
``` | ||
"mpris": { | ||
"format": "DEFAULT: {player_icon} {dynamic}", | ||
"format-paused": "DEFAULT: {status_icon} <i>{dynamic}</i>", | ||
"player-icons": { | ||
"default": "▶", | ||
"mpv": "🎵" | ||
}, | ||
"status-icons": { | ||
"paused": "⏸" | ||
}, | ||
// "ignored-players": ["firefox"] | ||
} | ||
``` | ||
|
||
# STYLE | ||
|
||
- *#mpris* | ||
- *#mpris.${status}* | ||
- *#mpris.${player}* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.