summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.config/waybar/config.jsonc23
-rw-r--r--.config/waybar/modules/mpris.awk57
-rwxr-xr-x.config/waybar/modules/mpris.sh4
3 files changed, 74 insertions, 10 deletions
diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc
index 6c5b294..bd38898 100644
--- a/.config/waybar/config.jsonc
+++ b/.config/waybar/config.jsonc
@@ -2,7 +2,6 @@
   "modules-left": ["sway/mode", "sway/workspaces", "custom/mpris"],
 
   "sway/workspaces": {
-    "disable-scroll": true,
     "format": "{icon}",
     "format-icons": {
       "m": "󰎇",
@@ -13,14 +12,15 @@
   },
 
   "custom/mpris": {
-    "exec-on-event": false,
     "max-width": 60,
-    "escape": true,
     "on-click": "playerctl play-pause",
     "on-click-right": "playerctl next",
     // "exec": "env YAEGI_SYSCALL=1 YAEGI_UNRESTRICTED=1 ${HOME}/.config/waybar/modules/mpris.go",
+    // "interval": "once",
+    "retart-interval": 1,
     "exec": "${HOME}/.config/waybar/modules/mpris.sh",
-    "return-type": "json"
+    "return-type": "json",
+    "signal": 4,
   },
 
   // ------------------------------------------------------------------------ //
@@ -54,7 +54,7 @@
     "format": "{:<i>%a</i> %d %b <b>%H:%M</b>}",
     "tooltip-format": "TZ: {:%Z %z}\n\n{calendar}",
     // "locale": "ja_JP.utf-8"
-    "locale": "en_US.utf-8"
+    // "locale": "en_US.utf-8"
   },
 
   "clock#utc": {
@@ -77,7 +77,7 @@
   },
 
   // ------------------------------------------------------------------------ //
-  "modules-right": ["tray", "custom/covid", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gamma", "pulseaudio", "network#tailscale", "network", "battery"],
+  "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gamma", "pulseaudio", "network#mullvad", "network#tailscale", "network", "battery"],
 
   "tray": {
     "spacing": 10
@@ -86,6 +86,7 @@
   "custom/covid": {
     "format": "{icon} {}",
     "format-icons": {
+      "": "x",
       "gray": "󱅼",
       "green": "󱎷",
       "yellow": "󱎷",
@@ -148,10 +149,10 @@
   "custom/gamma": {
     "format": "{icon}",
     "format-icons": {
+      "dawn": "󰱌",
       "day": "󰱌",
+      "dusk": "󰱊",
       "night": "󰱊",
-      "dusk": "?",
-      "dawn": "?"
     },
     "exec": "env GAMMA_COMMAND='wlsunset -l $HOME_LAT -L $HOME_LON -p' YAEGI_SYSCALL=1 YAEGI_UNRESTRICTED=1 ${HOME}/.config/waybar/modules/gamma.go",
     "return-type": "json"
@@ -176,6 +177,12 @@
     "on-click": "swx -t -F '0.4' pulsemixer"
   },
 
+  "network#mullvad": {
+    "interface": "mlvd-*",
+    "format": "󰒃",
+    "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}",
+    "tooltip-format-disconnected": "disconnected",
+  },
   "network#tailscale": {
     "interface": "tailscale0",
     "format": "󰌆",
diff --git a/.config/waybar/modules/mpris.awk b/.config/waybar/modules/mpris.awk
new file mode 100644
index 0000000..af3a271
--- /dev/null
+++ b/.config/waybar/modules/mpris.awk
@@ -0,0 +1,57 @@
+BEGIN {
+  # system("jq -Mnc {}");
+}
+
+{
+  gsub(/"/,"")
+  gsub(/'/,"\047")
+  # print "DEBUG: " $0
+
+  artist=$1
+  album=$2
+  title=$3
+  position=$4
+  player=$5
+  status=$6
+}
+
+($0 == "") || (status ~ /stopped/) {
+  system("jq -Mnc {}")
+  exit
+}
+(status ~ /playing/) {
+  icon="󰲸"
+}
+(status ~ /paused/) {
+  icon="󰏤"
+}
+(artist != "") && (album != "") {
+  text=sprintf("%s - %s - %s (%s)", artist, album, title, position)
+  tooltip=sprintf("%s\nby %s\nfrom %s\n(%s)", title, artist, album, player)
+}
+(artist == "") {
+  text=sprintf("%s - %s (%s)", album, title, position)
+  tooltip=sprintf("%s\nfrom %s\n(%s)", title, album, player)
+}
+(album == "") {
+  text=sprintf("%s - %s (%s)", artist, title, position)
+  tooltip=sprintf("%s\nby %s\n(%s)", title, artist, player)
+}
+(artist == "") && (album == "") {
+  text=sprintf("%s (%s)", title, position)
+  tooltip=sprintf("%s\n(%s)", title, player)
+}
+# edge cases to beautify the output
+(player == "tdesktop") && (title ~ /Unknown Track/) {
+  text="telegram voice message"
+}
+
+{
+  system(sprintf("jq -rMnc --arg class \"%s\" --arg text \"%s %s\" --arg tt \"%s\" '{ class: $class, text: $text|@html, tooltip: $tt|@html }'", \
+         status,
+         icon,
+         text,
+         tooltip))
+}
+
+END {}
diff --git a/.config/waybar/modules/mpris.sh b/.config/waybar/modules/mpris.sh
index 5f33f5e..4654a09 100755
--- a/.config/waybar/modules/mpris.sh
+++ b/.config/waybar/modules/mpris.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-set -eo pipefail
+set -e
 [ -n "$DEBUG" ] && set -x
 
-playerctl -sF metadata -f '"{{artist}}","{{album}}","{{title}}","{{duration(position)}}","{{playerName}}","{{lc(status)}}"' | awk -F',' -f "${HOME}/.config/waybar/modules/mpris.awk"
+playerctl -sF metadata -f '"{{artist}}","{{album}}","{{title}}","{{duration(position)}}","{{playerName}}","{{lc(status)}}"' 2>/dev/null | awk -F',' -f "${HOME}/.config/waybar/modules/mpris.awk"