diff --git a/home/qtile/src/core/bar.py b/home/qtile/src/core/bar.py index f0fe004..b34b1e3 100644 --- a/home/qtile/src/core/bar.py +++ b/home/qtile/src/core/bar.py @@ -10,10 +10,10 @@ CPUGraph, GroupBox, Memory, + Mpris2, Prompt, QuickExit, Separator, - SpotifyNowPlaying, Systray, TaskList, ) @@ -26,7 +26,7 @@ class Bar(bar.Bar): TaskList, Separator, Prompt, - SpotifyNowPlaying, + Mpris2, Battery, Memory, CPUGraph, @@ -46,7 +46,7 @@ def __init__(self, id_): margin=[0, 0, 8, 0] ) - def is_desktop(self) -> bool: + def is_desktop(self): machine_info = subprocess.check_output( ["hostnamectl", "status"], universal_newlines=True) m = re.search(r"Chassis: (\w+)\s.*\n", machine_info) diff --git a/home/qtile/src/widgets/__init__.py b/home/qtile/src/widgets/__init__.py index 1a17000..e0acb9a 100644 --- a/home/qtile/src/widgets/__init__.py +++ b/home/qtile/src/widgets/__init__.py @@ -4,6 +4,7 @@ Clock, CPUGraph, GroupBox, + Mpris2, Memory, Prompt, QuickExit, @@ -12,19 +13,17 @@ Systray ) -from .spotify import SpotifyNowPlaying - __all__ = ( "widget_defaults", "Battery", "Clock", "CPUGraph", "GroupBox", + "Mpris2", "Memory", "Prompt", "QuickExit", "Separator", - "SpotifyNowPlaying", "TaskList", "Systray", ) diff --git a/home/qtile/src/widgets/overides.py b/home/qtile/src/widgets/overides.py index bedf90b..e65bee6 100644 --- a/home/qtile/src/widgets/overides.py +++ b/home/qtile/src/widgets/overides.py @@ -38,6 +38,12 @@ def mk_overrides(cls, **conf): active=Color.TEXT_LIGHT, ) +Mpris2 = mk_overrides( + widget.Mpris2, + objname="org.mpris.MediaPlayer2.spotify", + format='{xesam:title} - {xesam:artist}', +) + Memory = mk_overrides( widget.Memory, format="{MemUsed: .3f}Mb", diff --git a/home/qtile/src/widgets/spotify.py b/home/qtile/src/widgets/spotify.py deleted file mode 100644 index e17cc3b..0000000 --- a/home/qtile/src/widgets/spotify.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Wakatime widget inspired by drawbu.""" -from typing import List -import subprocess - -from libqtile import qtile -from libqtile.widget import base - - -COVER_PATH = "/tmp/spotify-now-playing.png" - - -def get_stdout(cmd: List[str]) -> str: - try: - sub = subprocess.run( - cmd, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - timeout=2 - ) - except (TimeoutError, FileNotFoundError): - return "" - if sub.stderr is not None: - return "" - return sub.stdout.decode("utf-8").strip() - - -class SpotifyNowPlaying(base.InLoopPollText): - def __init__(self, **config): - super().__init__("", update_interval=5, qtile=qtile, **config) - self.name = "Spotify now playing" - - def poll(self) -> str: - is_playing = get_stdout(["playerctl", "--player=spotify", "status"]) - if is_playing != "Playing": - return "" - artist = get_stdout(["playerctl", "--player=spotify", "metadata", "artist"]) - title = get_stdout(["playerctl", "--player=spotify", "metadata", "title"]) - if artist == "" or title == "": - return "" - return f" {artist} - {title}"