sway: waybar: fix media to better handle multiple players
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
./nix-index.nix
|
./nix-index.nix
|
||||||
./obsidian.nix
|
./obsidian.nix
|
||||||
./offlineimap.nix
|
./offlineimap.nix
|
||||||
|
./playerctl.nix
|
||||||
./rhythmbox.nix
|
./rhythmbox.nix
|
||||||
./ripgrep.nix
|
./ripgrep.nix
|
||||||
./sfeed.nix
|
./sfeed.nix
|
||||||
|
15
hosts/common/programs/playerctl.nix
Normal file
15
hosts/common/programs/playerctl.nix
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
{
|
||||||
|
# TODO: give `sane.programs` native support for defining services
|
||||||
|
systemd.user.services.playerctld = lib.mkIf config.sane.programs.playerctl.enabled {
|
||||||
|
description = "playerctl daemon to keep track of which MPRIS players were recently active";
|
||||||
|
documentation = [ "https://github.com/altdesktop/playerctl/issues/161" ];
|
||||||
|
wantedBy = [ "default.target" ];
|
||||||
|
serviceConfig.ExecStart = "${config.sane.programs.playerctl.package}/bin/playerctld";
|
||||||
|
# serviceConfig.Type = "dbus";
|
||||||
|
# serviceConfig.BusName = "org.mpris.MediaPlayer2.Player";
|
||||||
|
serviceConfig.Type = "simple"; # playerctl also supports a --daemon option, idk if that's better
|
||||||
|
serviceConfig.Restart = "on-failure";
|
||||||
|
serviceConfig.RestartSec = "10s";
|
||||||
|
};
|
||||||
|
}
|
@@ -171,6 +171,7 @@ in
|
|||||||
"swayidle"
|
"swayidle"
|
||||||
"wl-clipboard"
|
"wl-clipboard"
|
||||||
"blueberry" # GUI bluetooth manager
|
"blueberry" # GUI bluetooth manager
|
||||||
|
"playerctl" # for waybar & particularly to have playerctld running
|
||||||
# "mako" # notification daemon
|
# "mako" # notification daemon
|
||||||
"swaynotificationcenter" # notification daemon
|
"swaynotificationcenter" # notification daemon
|
||||||
# # "pavucontrol"
|
# # "pavucontrol"
|
||||||
|
17
hosts/modules/gui/sway/waybar-media
Executable file
17
hosts/modules/gui/sway/waybar-media
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i bash -p jq -p playerctl
|
||||||
|
status=$(playerctl status 2> /dev/null | tr 'A-Z' 'a-z')
|
||||||
|
if [ -z "$status" ]; then
|
||||||
|
status="inactive"
|
||||||
|
fi
|
||||||
|
|
||||||
|
artist=$(playerctl metadata artist 2> /dev/null)
|
||||||
|
title=$(playerctl metadata title 2> /dev/null)
|
||||||
|
|
||||||
|
text=
|
||||||
|
if [ -n "$title" ]; then
|
||||||
|
text="$artist - $title"
|
||||||
|
fi
|
||||||
|
# waybar requires output to be on a single line.
|
||||||
|
# `alt` key determines the icon
|
||||||
|
jq --null-input --compact-output --arg status "$status" --arg text "$text" '{ "text": $text, "alt": $status }'
|
@@ -1,6 +1,14 @@
|
|||||||
# docs: <https://github.com/Alexays/Waybar/wiki/Configuration>
|
# docs: <https://github.com/Alexays/Waybar/wiki/Configuration>
|
||||||
# format specifiers: <https://fmt.dev/latest/syntax.html#syntax>
|
# - custom modules: <https://github.com/Alexays/Waybar/wiki/Module:-Custom>
|
||||||
|
# - format specifiers: <https://fmt.dev/latest/syntax.html#syntax>
|
||||||
{ lib, pkgs }:
|
{ lib, pkgs }:
|
||||||
|
let
|
||||||
|
waybar-media = pkgs.static-nix-shell.mkBash {
|
||||||
|
pname = "waybar-media";
|
||||||
|
src = ./.;
|
||||||
|
pkgs = [ "jq" "playerctl" ];
|
||||||
|
};
|
||||||
|
in
|
||||||
{
|
{
|
||||||
height = lib.mkDefault 40;
|
height = lib.mkDefault 40;
|
||||||
modules-left = lib.mkDefault [ "sway/workspaces" ];
|
modules-left = lib.mkDefault [ "sway/workspaces" ];
|
||||||
@@ -19,28 +27,36 @@
|
|||||||
max-length = 50;
|
max-length = 50;
|
||||||
};
|
};
|
||||||
|
|
||||||
# include song artist/title.
|
|
||||||
# source: <https://www.reddit.com/r/swaywm/comments/ni0vso/waybar_spotify_tracktitle/>
|
|
||||||
"custom/media" = {
|
"custom/media" = {
|
||||||
exec = pkgs.writeShellScript "waybar-mediaplayer" ''
|
# this module shows the actively playing song
|
||||||
player_status=$(${pkgs.playerctl}/bin/playerctl status 2> /dev/null)
|
# - source: <https://www.reddit.com/r/swaywm/comments/ni0vso/waybar_spotify_tracktitle/>
|
||||||
if [ "$player_status" = "Playing" ]; then
|
# - alternative: <https://github.com/Alexays/Waybar/wiki/Module:-MPRIS>
|
||||||
echo " $(${pkgs.playerctl}/bin/playerctl metadata artist) - $(${pkgs.playerctl}/bin/playerctl metadata title)"
|
# - alternative: <https://github.com/Alexays/Waybar/wiki/Module:-Custom#mpris-controller>
|
||||||
elif [ "$player_status" = "Paused" ]; then
|
#
|
||||||
echo " $(${pkgs.playerctl}/bin/playerctl metadata artist) - $(${pkgs.playerctl}/bin/playerctl metadata title)"
|
# N.B.: for this to behave well with multiple MPRIS clients,
|
||||||
fi
|
# `playerctld` must be enabled. see: <https://github.com/altdesktop/playerctl/issues/161>
|
||||||
'';
|
exec = "${waybar-media}/bin/waybar-media";
|
||||||
|
return-type = "json";
|
||||||
interval = 2;
|
interval = 2;
|
||||||
format = "{}";
|
format = "{icon}{}";
|
||||||
# return-type = "json";
|
max-length = 50;
|
||||||
on-click = "${pkgs.playerctl}/bin/playerctl play-pause";
|
format-icons = {
|
||||||
on-scroll-up = "${pkgs.playerctl}/bin/playerctl next";
|
playing = " ";
|
||||||
on-scroll-down = "${pkgs.playerctl}/bin/playerctl previous";
|
paused = " ";
|
||||||
|
inactive = "";
|
||||||
|
};
|
||||||
|
tooltip = false;
|
||||||
|
on-click = "playerctl play-pause";
|
||||||
|
on-scroll-up = "playerctl next";
|
||||||
|
on-scroll-down = "playerctl previous";
|
||||||
};
|
};
|
||||||
"custom/swaync" = {
|
"custom/swaync" = {
|
||||||
# source: <https://github.com/ErikReider/SwayNotificationCenter#waybar-example>
|
# source: <https://github.com/ErikReider/SwayNotificationCenter#waybar-example>
|
||||||
tooltip = false;
|
exec-if = "which swaync-client";
|
||||||
format = "{icon}"; # or "{icon} {}" to inclde notif count
|
exec = "swaync-client -swb";
|
||||||
|
return-type = "json";
|
||||||
|
escape = true;
|
||||||
|
format = "{icon}"; # or "{icon} {}" to include notif count
|
||||||
format-icons = {
|
format-icons = {
|
||||||
notification = "<span foreground='red'><sup></sup></span>";
|
notification = "<span foreground='red'><sup></sup></span>";
|
||||||
none = "";
|
none = "";
|
||||||
@@ -51,12 +67,9 @@
|
|||||||
dnd-inhibited-notification = "<span foreground='red'><sup></sup></span>";
|
dnd-inhibited-notification = "<span foreground='red'><sup></sup></span>";
|
||||||
dnd-inhibited-none = "";
|
dnd-inhibited-none = "";
|
||||||
};
|
};
|
||||||
return-type = "json";
|
tooltip = false;
|
||||||
exec-if = "which swaync-client";
|
|
||||||
exec = "swaync-client -swb";
|
|
||||||
on-click = "swaync-client -t -sw";
|
on-click = "swaync-client -t -sw";
|
||||||
on-click-right = "swaync-client -d -sw";
|
on-click-right = "swaync-client -d -sw";
|
||||||
escape = true;
|
|
||||||
};
|
};
|
||||||
network = {
|
network = {
|
||||||
# docs: <https://github.com/Alexays/Waybar/blob/master/man/waybar-network.5.scd>
|
# docs: <https://github.com/Alexays/Waybar/blob/master/man/waybar-network.5.scd>
|
||||||
|
Reference in New Issue
Block a user