aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rwxr-xr-x.local/bin/playerctl_systray19
-rw-r--r--.local/share/python-playerctl_systray/Makefile4
-rw-r--r--.local/share/python-playerctl_systray/playerctl_systray.py61
4 files changed, 86 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 5eb6c48..88b117d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,5 +43,5 @@
.local/src/dmenu-dunst/util.o
# future ignores
-.local/share/python-SysTrayMediaControls/SysTrayMediaControls
-.local/share/python-SysTrayMediaControls/SysTrayMediaControls.c
+.local/share/python-playerctl_systray/playerctl_systray
+.local/share/python-playerctl_systray/playerctl_systray.c
diff --git a/.local/bin/playerctl_systray b/.local/bin/playerctl_systray
new file mode 100755
index 0000000..5f4fcca
--- /dev/null
+++ b/.local/bin/playerctl_systray
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+BIN_PATH=~/.local/share/python-playerctl_systray/playerctl_systray
+SCRIPT_PATH=~/.local/share/python-playerctl_systray/playerctl_systray.py
+
+if ! command -v playerctl >/dev/null 2>&1; then
+ echo "playerctl is not installed but is required."
+ notify-send "dependency missing:" "playerctl is required to run playerctl_systray." --urgency critical
+ exit 1
+fi
+
+if [ -f "$BIN_PATH" ]; then
+ $BIN_PATH
+elif [ -f "$SCRIPT_PATH" ]; then
+ python3 $SCRIPT_PATH
+else
+ echo "playerctl_systray(.py) not found"
+ notify-send "error!" "playerctl_systray(.py) not found" --urgency critical
+fi
diff --git a/.local/share/python-playerctl_systray/Makefile b/.local/share/python-playerctl_systray/Makefile
new file mode 100644
index 0000000..e135452
--- /dev/null
+++ b/.local/share/python-playerctl_systray/Makefile
@@ -0,0 +1,4 @@
+compile:
+ cython3 --embed -o playerctl_systray.c -X language_level=3 playerctl_systray.py
+ PYTHON_VERSION=`ls /usr/include | grep -o 'python[3-9]\+\.[0-9]\+'` ; \
+ gcc -march=native -O2 -pipe -fno-plt -I /usr/include/$$PYTHON_VERSION -o playerctl_systray playerctl_systray.c -l$$PYTHON_VERSION -lpthread -lm -lutil -ldl `pkg-config --cflags --libs gtk+-3.0 appindicator3-0.1 dbus-1 dbus-glib-1`
diff --git a/.local/share/python-playerctl_systray/playerctl_systray.py b/.local/share/python-playerctl_systray/playerctl_systray.py
new file mode 100644
index 0000000..f5cf5e6
--- /dev/null
+++ b/.local/share/python-playerctl_systray/playerctl_systray.py
@@ -0,0 +1,61 @@
+import gi
+import subprocess
+import os
+
+gi.require_version('Gtk', '3.0')
+gi.require_version('AppIndicator3', '0.1')
+from gi.repository import Gtk, AppIndicator3
+
+class playerctl_systray:
+ def __init__(self):
+ self.indicator = AppIndicator3.Indicator.new(
+ "media-control-app",
+ "audio-x-generic",
+ AppIndicator3.IndicatorCategory.APPLICATION_STATUS
+ )
+ self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
+ self.indicator.set_menu(self.create_menu())
+
+ def create_menu(self):
+ menu = Gtk.Menu()
+
+ play_item = Gtk.MenuItem(label="Play/Pause")
+ play_item.connect("activate", self.play_pause)
+ menu.append(play_item)
+
+ next_item = Gtk.MenuItem(label="Next")
+ next_item.connect("activate", self.next_track)
+ menu.append(next_item)
+
+ prev_item = Gtk.MenuItem(label="Previous")
+ prev_item.connect("activate", self.prev_track)
+ menu.append(prev_item)
+
+ quit_item = Gtk.MenuItem(label="Quit")
+ quit_item.connect("activate", self.quit)
+ menu.append(quit_item)
+
+ menu.show_all()
+ return menu
+
+ def play_pause(self, source):
+ self.run_command("playerctl play-pause")
+
+ def next_track(self, source):
+ self.run_command("playerctl next")
+
+ def prev_track(self, source):
+ self.run_command("playerctl previous")
+
+ def run_command(self, command):
+ subprocess.run(command, shell=True)
+
+ def quit(self, source):
+ Gtk.main_quit()
+
+def main():
+ app = playerctl_systray()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()