forge
Explore
Log in

Don't you dare go Hollow

Save uncommitted config changes

Browse files at this commit

41c669cf144834e7fd528d51c52df2bde4cc2e92Ahmet Kaan GümüşParent: d06029d
  • chore
    • save uncommitted config changes
Show full message
🔧 chore: save uncommitted config changes

The working tree held edits to waybar, niri, hypr, eww, btop, mimeapps and media scripts that existed only locally, and playerctl-active.sh is renamed to playerctl_active.sh.
.config/btop/btop.confmodified+1 -1
@@ -192,7 +192,7 @@ show_swap = true
192192 swap_disk = true
193193
194194 #* If mem box should be split to also show disks info.
195-show_disks = true
195+show_disks = false
196196
197197 #* Filter out non physical disks. Set this to False to include network disks, RAM disks and similar.
198198 only_physical = true
.config/eww/eww.yuckmodified+1 -1
@@ -96,7 +96,7 @@
9696
9797 ;; Music widget - click to play/pause, right-click to show cover
9898 (defwidget music-widget []
99- (eventbox :onclick "bash ~/.config/scripts/shared/playerctl-active.sh play-pause"
99+ (eventbox :onclick "bash ~/.config/scripts/shared/playerctl_active.sh play-pause"
100100 :onrightclick "bash ~/.config/scripts/shared/show_cover.sh"
101101 :class "music-box"
102102 (label :text music)))
.config/hypr/hyprland.confmodified+7 -7
@@ -32,8 +32,8 @@ $clipboard = cliphist list | rofi -dmenu -show-icons -i | cliphist decode | wl-
3232 $screenshot = grim -t png - | tee "$HOME/Pictures/Screenshots/$(date '+%y%m%d_%H-%M-%S').png" | wl-copy -t image/png
3333 $screenshot_with_area_selector = grim -t png -g "$(slurp)" - | wl-copy -t image/png
3434 $power_menu = bash ~/.config/scripts/system/power_menu.sh
35-$browser = flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll
36-$browser_unsafe = mullvad-exclude flatpak run org.chromium.Chromium --incognito --enable-features=MiddleClickAutoscroll,AllowLegacyMV2Extensions --disable-features=ExtensionManifestV2Unsupported,ExtensionManifestV2Disabled,ExtensionsManifestV3Only
35+$browser = flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll,HardwareMediaKeyHandling
36+$browser_unsafe = mullvad-exclude flatpak run org.chromium.Chromium --incognito --enable-features=MiddleClickAutoscroll,HardwareMediaKeyHandling,AllowLegacyMV2Extensions --disable-features=ExtensionManifestV2Unsupported,ExtensionManifestV2Disabled,ExtensionsManifestV3Only
3737 $signal = flatpak run org.signal.Signal
3838 $deezer = mullvad-exclude flatpak run io.github.ungoogled_software.ungoogled_chromium --no-first-run --app="https://deezer.com/" --class=chrome-deezer.com__-Default --name=chrome-deezer.com__-Default --user-data-dir=/home/tahinli/.var/app/io.github.ungoogled_software.ungoogled_chromium/data/web-app-hub/profiles/VjW8vTQ3
3939 $mainMod = SUPER
@@ -63,7 +63,7 @@ bindl = $mainMod SHIFT, M, exec, ~/.config/scripts/hyprland/toggle_monitors.sh o
6363 bind = $mainMod SHIFT, K, exec, bash ~/.config/scripts/system/usb_menu.sh
6464
6565 $discord = flatpak run dev.vencord.Vesktop
66-$youtube = mullvad-exclude flatpak run io.freetubeapp.FreeTube
66+$youtube = mullvad-exclude flatpak run --command=bash io.freetubeapp.FreeTube -c 'true & wait; run.sh; exit $?'
6767 $code = zed
6868 $mail = flatpak run io.github.ungoogled_software.ungoogled_chromium --no-first-run --app="https://mail.proton.me/" --class=chrome-mail.proton.me__-Default --name=chrome-mail.proton.me__-Default --user-data-dir=/home/tahinli/.var/app/io.github.ungoogled_software.ungoogled_chromium/data/web-app-hub/profiles/eIpzVtL8
6969 $whatsapp = mullvad-exclude flatpak run io.github.ungoogled_software.ungoogled_chromium --no-first-run --app="https://web.whatsapp.com/" --class=chrome-web.whatsapp.com__-Default --name=chrome-web.whatsapp.com__-Default --user-data-dir=/home/tahinli/.var/app/io.github.ungoogled_software.ungoogled_chromium/data/web-app-hub/profiles/aW2IMaZ8
@@ -168,10 +168,10 @@ bindel = ,XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
168168 bindel = ,XF86MonBrightnessUp, exec, brightnessctl s 10%+
169169 bindel = ,XF86MonBrightnessDown, exec, brightnessctl s 10%-
170170
171-bindl = , XF86AudioNext, exec, ~/.config/scripts/shared/playerctl-active.sh next
172-bindl = , XF86AudioPause, exec, ~/.config/scripts/shared/playerctl-active.sh play-pause
173-bindl = , XF86AudioPlay, exec, ~/.config/scripts/shared/playerctl-active.sh play-pause
174-bindl = , XF86AudioPrev, exec, ~/.config/scripts/shared/playerctl-active.sh previous
171+bindl = , XF86AudioNext, exec, ~/.config/scripts/shared/playerctl_active.sh next
172+bindl = , XF86AudioPause, exec, ~/.config/scripts/shared/playerctl_active.sh play-pause
173+bindl = , XF86AudioPlay, exec, ~/.config/scripts/shared/playerctl_active.sh play-pause
174+bindl = , XF86AudioPrev, exec, ~/.config/scripts/shared/playerctl_active.sh previous
175175
176176 windowrule = match:class .*, suppress_event maximize
177177 windowrule = match:class ^$, match:title ^$, match:xwayland 1, match:float 1, match:fullscreen 0, match:pin 0, no_focus on
.config/mimeapps.listmodified+1 -0
@@ -61,6 +61,7 @@ x-scheme-handler/surrealist=surrealist.desktop
6161 x-scheme-handler/openhuman=OpenHuman-handler.desktop
6262 x-scheme-handler/zcode=zcode.desktop
6363 x-scheme-handler/logseq=logseq.desktop
64+x-scheme-handler/fluxer=app.fluxer.FluxerDesktopCanary.desktop
6465
6566 [Added Associations]
6667 video/mp4=mpv.desktop;
.config/niri/config.kdlmodified+9 -9
@@ -78,7 +78,7 @@ layout {
7878 width 3
7979
8080 // WALLUST-GRADIENT
81- active-gradient from="#9B1A1A" to="#FCAE03" angle=90 in="oklch"
81+ active-gradient from="#5C112D" to="#CD5B74" angle=90 in="oklch"
8282
8383 inactive-color "#595959aa"
8484 urgent-color "#9b0000"
@@ -160,8 +160,8 @@ binds {
160160 Alt+F3 hotkey-overlay-title="Clipboard history" { spawn-sh "cliphist list | rofi -dmenu -show-icons -i | cliphist decode | wl-copy"; }
161161 Alt+3 hotkey-overlay-title="Clipboard history" { spawn-sh "cliphist list | rofi -dmenu -show-icons -i | cliphist decode | wl-copy"; }
162162
163- Alt+F hotkey-overlay-title="Browser" { spawn-sh "flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll"; }
164- Shift+Alt+F hotkey-overlay-title="Browser (incognito, outside VPN)" { spawn-sh "mullvad-exclude flatpak run org.chromium.Chromium --incognito --enable-features=MiddleClickAutoscroll,AllowLegacyMV2Extensions --disable-features=ExtensionManifestV2Unsupported,ExtensionManifestV2Disabled,ExtensionsManifestV3Only"; }
163+ Alt+F hotkey-overlay-title="Browser" { spawn-sh "flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll,HardwareMediaKeyHandling"; }
164+ Shift+Alt+F hotkey-overlay-title="Browser (incognito, outside VPN)" { spawn-sh "mullvad-exclude flatpak run org.chromium.Chromium --incognito --enable-features=MiddleClickAutoscroll,HardwareMediaKeyHandling,AllowLegacyMV2Extensions --disable-features=ExtensionManifestV2Unsupported,ExtensionManifestV2Disabled,ExtensionsManifestV3Only"; }
165165
166166 Alt+C hotkey-overlay-title="Workspace: code" { focus-workspace "code"; }
167167 Alt+G hotkey-overlay-title="Workspace: github" { focus-workspace "github"; }
@@ -175,7 +175,7 @@ binds {
175175 Shift+Alt+W hotkey-overlay-title="Launch: whatsapp" { spawn-sh "~/.config/scripts/shared/webapp.sh --mullvad https://web.whatsapp.com/ aW2IMaZ8"; }
176176 Shift+Alt+D hotkey-overlay-title="Launch: discord" { spawn-sh "flatpak run org.equicord.equibop"; }
177177 Shift+Alt+S hotkey-overlay-title="Launch: deezer" { spawn-sh "~/.config/scripts/shared/webapp.sh --mullvad https://deezer.com/ VjW8vTQ3"; }
178- Shift+Alt+Y hotkey-overlay-title="Launch: youtube" { spawn-sh "mullvad-exclude flatpak run io.freetubeapp.FreeTube"; }
178+ Shift+Alt+Y hotkey-overlay-title="Launch: youtube" { spawn-sh "mullvad-exclude flatpak run --command=bash io.freetubeapp.FreeTube -c 'true & wait; run.sh; exit $?'"; }
179179 Shift+Alt+P hotkey-overlay-title="Launch: mail" { spawn-sh "~/.config/scripts/shared/webapp.sh https://mail.proton.me/ eIpzVtL8"; }
180180
181181 Mod+Shift+C { move-column-to-workspace "code"; }
@@ -202,16 +202,16 @@ binds {
202202 Mod+Shift+Escape allow-inhibiting=false { toggle-keyboard-shortcuts-inhibit; }
203203 Mod+Shift+Slash { show-hotkey-overlay; }
204204 Mod+O repeat=false { toggle-overview; }
205- Super+Alt+S allow-when-locked=true hotkey-overlay-title=null { spawn-sh "pkill orca || exec orca"; }
205+ // Super+Alt+S allow-when-locked=true hotkey-overlay-title=null { spawn-sh "pkill orca || exec orca"; }
206206
207207 XF86AudioRaiseVolume allow-when-locked=true { spawn-sh "wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1+ -l 1.0"; }
208208 XF86AudioLowerVolume allow-when-locked=true { spawn-sh "wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1-"; }
209209 XF86AudioMute allow-when-locked=true { spawn-sh "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"; }
210210 XF86AudioMicMute allow-when-locked=true { spawn-sh "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"; }
211- XF86AudioPlay allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl-active.sh play-pause"; }
212- XF86AudioStop allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl-active.sh pause"; }
213- XF86AudioPrev allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl-active.sh previous"; }
214- XF86AudioNext allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl-active.sh next"; }
211+ XF86AudioPlay allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl_active.sh play-pause"; }
212+ XF86AudioStop allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl_active.sh pause"; }
213+ XF86AudioPrev allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl_active.sh previous"; }
214+ XF86AudioNext allow-when-locked=true { spawn-sh "~/.config/scripts/shared/playerctl_active.sh next"; }
215215 XF86MonBrightnessUp allow-when-locked=true { spawn "brightnessctl" "--class=backlight" "set" "+10%"; }
216216 XF86MonBrightnessDown allow-when-locked=true { spawn "brightnessctl" "--class=backlight" "set" "10%-"; }
217217
.config/scripts/shared/media_menu.shadded+103 -0
@@ -0,0 +1,103 @@
1+#!/bin/bash
2+# Media picker (rofi): choose which MPRIS player the waybar music module follows.
3+# Auto (no pin file) follows the latest player; picking a player writes
4+# /tmp/playerctl_pin (line 1 bus name, 2 url host, 3 base name, 4 timestamp).
5+# Bound to middle-click on custom/music.
6+
7+PIN=/tmp/playerctl_pin
8+
9+notify() {
10+ notify-send "$@" 2>/dev/null || true
11+}
12+
13+# host of an http(s) url, empty otherwise
14+host_of() {
15+ local url=$1
16+ [[ $url =~ ^https?:// ]] || return 0
17+ sed -E 's#^[a-z]+://([^/]+).*#\1#' <<<"$url"
18+}
19+
20+# --- collect players ----------------------------------------------------------
21+
22+players=()
23+while IFS= read -r p; do
24+ [[ -n $p ]] && players+=("$p")
25+done < <(playerctl -l 2>/dev/null)
26+
27+if (( ${#players[@]} == 0 )); then
28+ notify "No media players"
29+ exit 0
30+fi
31+
32+pinned=""
33+if [[ -f $PIN ]]; then
34+ pinned=$(sed -n 1p "$PIN" 2>/dev/null)
35+fi
36+
37+# parallel arrays, index-aligned with players[]
38+titles=()
39+labels=()
40+places=()
41+entries=()
42+
43+if [[ -z $pinned ]]; then
44+ entries+=("📌 Auto (follow latest)")
45+else
46+ entries+=("Auto (follow latest)")
47+fi
48+
49+for p in "${players[@]}"; do
50+ status=$(playerctl -p "$p" status 2>/dev/null)
51+ artist=$(playerctl -p "$p" metadata artist 2>/dev/null)
52+ title=$(playerctl -p "$p" metadata title 2>/dev/null)
53+ url=$(playerctl -p "$p" metadata xesam:url 2>/dev/null)
54+
55+ case "$status" in
56+ Playing) icon="▶" ;;
57+ Paused) icon="⏸" ;;
58+ *) icon="⏹" ;;
59+ esac
60+
61+ if [[ -n $artist && -n $title ]]; then
62+ label="$artist - $title"
63+ elif [[ -n $title ]]; then
64+ label=$title
65+ else
66+ label="(no title)"
67+ fi
68+
69+ host=$(host_of "$url")
70+ base=${p%%.*}
71+ place=${host:-$base}
72+
73+ titles+=("${title:-(no title)}")
74+ labels+=("$label")
75+ places+=("$place")
76+
77+ prefix=""
78+ [[ $p == "$pinned" ]] && prefix="📌 "
79+ entries+=("${prefix}${icon} ${label} — ${place} [${p}]")
80+done
81+
82+# --- menu -------------------------------------------------------------------
83+
84+idx=$(printf '%s\n' "${entries[@]}" | rofi -dmenu -i -p "Media" -format i)
85+[[ -z $idx ]] && exit 0
86+[[ $idx =~ ^[0-9]+$ ]] || exit 0
87+
88+if (( idx == 0 )); then
89+ rm -f "$PIN"
90+ notify "Media: auto"
91+ exit 0
92+fi
93+
94+(( idx <= ${#players[@]} )) || exit 0
95+i=$((idx - 1))
96+player=${players[i]}
97+
98+tmp=$(mktemp /tmp/playerctl_pin.XXXXXX) || exit 1
99+host=$(host_of "$(playerctl -p "$player" metadata xesam:url 2>/dev/null)")
100+printf '%s\n%s\n%s\n%s\n' "$player" "$host" "${player%%.*}" "$(date +%s)" > "$tmp"
101+mv -f "$tmp" "$PIN"
102+
103+notify "Media pinned" "${titles[i]} — ${places[i]}"
.config/scripts/shared/playerctl-active.shdeleted+0 -35
@@ -1,35 +0,0 @@
1-#!/bin/bash
2-# Forward playerctl commands to the ACTIVE player: the one currently Playing,
3-# else the most recently Playing (now Paused) one — the same selection
4-# song_detail_writer.sh makes for the waybar display, so clicks hit the
5-# player the bar is showing instead of the first in `playerctl -l` order.
6-#
7-# Usage: playerctl-active.sh play-pause|stop|next|previous|status|metadata ...
8-
9-ACTIVITY_PREFIX="/tmp/playerctl_activity_"
10-sanitize() { printf '%s' "$1" | tr -c 'A-Za-z0-9._-' '_'; }
11-
12-chosen=""
13-fallback=""
14-fallback_ts=0
15-while IFS= read -r player; do
16- [[ -z "$player" ]] && continue
17- status=$(playerctl -p "$player" status 2>/dev/null) || continue
18- if [[ "$status" == "Playing" ]]; then
19- chosen="$player"
20- break
21- elif [[ "$status" == "Paused" ]]; then
22- ts=0
23- act_file="${ACTIVITY_PREFIX}$(sanitize "$player")"
24- [[ -f "$act_file" ]] && ts=$(cat "$act_file" 2>/dev/null) && [[ -z "$ts" ]] && ts=0
25- if (( ts > fallback_ts )); then
26- fallback_ts="$ts"
27- fallback="$player"
28- fi
29- fi
30-done < <(playerctl -l 2>/dev/null)
31-
32-chosen="${chosen:-$fallback}"
33-[[ -z "$chosen" ]] && exit 1
34-
35-exec playerctl -p "$chosen" "$@"
.config/scripts/shared/playerctl_active.shadded+61 -0
@@ -0,0 +1,61 @@
1+#!/bin/bash
2+# Forward playerctl commands to the player the bar is showing, so clicks hit
3+# what song_detail_writer.sh displays instead of the first in `playerctl -l`.
4+# Target order:
5+# 1. /tmp/song_detail_player (the writer's current player), if still listed
6+# 2. pin file line 1 (/tmp/playerctl_pin), if still listed
7+# 3. Playing player with the most recent start (/tmp/playerctl_started_*)
8+# 4. Paused player with the latest activity (/tmp/playerctl_activity_*)
9+#
10+# Usage: playerctl_active.sh play-pause|stop|next|previous|status|metadata ...
11+
12+ACTIVITY_PREFIX="/tmp/playerctl_activity_"
13+STARTED_PREFIX="/tmp/playerctl_started_"
14+CHOSEN_FILE="/tmp/song_detail_player"
15+PIN_FILE="/tmp/playerctl_pin"
16+sanitize() { printf '%s' "$1" | tr -c 'A-Za-z0-9._-' '_'; }
17+
18+list=$(playerctl -l 2>/dev/null)
19+in_list() { grep -qxF -- "$1" <<< "$list"; }
20+
21+chosen=""
22+if [[ -s "$CHOSEN_FILE" ]]; then
23+ cand=$(head -n 1 "$CHOSEN_FILE")
24+ [[ -n "$cand" ]] && in_list "$cand" && chosen="$cand"
25+fi
26+if [[ -z "$chosen" && -f "$PIN_FILE" ]]; then
27+ cand=$(head -n 1 "$PIN_FILE")
28+ [[ -n "$cand" ]] && in_list "$cand" && chosen="$cand"
29+fi
30+
31+if [[ -z "$chosen" ]]; then
32+ best_playing=""
33+ best_playing_ts=-1
34+ fallback=""
35+ fallback_ts=0
36+ while IFS= read -r player; do
37+ [[ -z "$player" ]] && continue
38+ status=$(playerctl -p "$player" status 2>/dev/null) || continue
39+ if [[ "$status" == "Playing" ]]; then
40+ started=$(cat "${STARTED_PREFIX}$(sanitize "$player")" 2>/dev/null)
41+ [[ "$started" =~ ^[0-9]+$ ]] || started=0
42+ if (( started > best_playing_ts )); then
43+ best_playing_ts="$started"
44+ best_playing="$player"
45+ fi
46+ elif [[ "$status" == "Paused" ]]; then
47+ ts=0
48+ act_file="${ACTIVITY_PREFIX}$(sanitize "$player")"
49+ [[ -f "$act_file" ]] && ts=$(cat "$act_file" 2>/dev/null) && [[ -z "$ts" ]] && ts=0
50+ if (( ts > fallback_ts )); then
51+ fallback_ts="$ts"
52+ fallback="$player"
53+ fi
54+ fi
55+ done <<< "$list"
56+ chosen="${best_playing:-$fallback}"
57+fi
58+
59+[[ -z "$chosen" ]] && exit 1
60+
61+exec playerctl -p "$chosen" "$@"
.config/scripts/shared/show_cover.shmodified+1 -1
@@ -1,7 +1,7 @@
11 #!/bin/bash
22
33 # Get cover art URL from playerctl
4-cover_url=$(bash ~/.config/scripts/shared/playerctl-active.sh metadata mpris:artUrl 2>/dev/null)
4+cover_url=$(bash ~/.config/scripts/shared/playerctl_active.sh metadata mpris:artUrl 2>/dev/null)
55
66 if [[ -z "$cover_url" ]]; then
77 notify-send "No cover art available"
.config/scripts/shared/song_detail_writer.shmodified+193 -58
@@ -8,16 +8,25 @@
88 # the file each interval always see the live line. Whatever was in the file
99 # before — including a leftover in-place log from an older build — is dropped.
1010 #
11+# Pin mode: /tmp/playerctl_pin (line 1 = bus name, 2 = url host, 3 = base name,
12+# 4 = pinned epoch) keeps the display on one player. While pinned the line gets
13+# a 📌 prefix and holds the last good line through short gaps.
14+# /tmp/song_detail_player always holds the player currently shown.
15+#
1116 # niri spawn-at-startup re-runs on compositor restart and used to stack
1217 # copies; newest instance takes over (singleton below).
1318
1419 OUTPUT_FILE="/tmp/song_detail_last"
20+CHOSEN_FILE="/tmp/song_detail_player"
21+PIN_FILE="/tmp/playerctl_pin"
1522 POSITION_CACHE_PREFIX="/tmp/playerctl_position_cache_"
1623 ACTIVITY_PREFIX="/tmp/playerctl_activity_"
24+STARTED_PREFIX="/tmp/playerctl_started_"
1725 LOCK_FILE="/tmp/song_detail_writer.lock"
1826 PID_FILE="/tmp/song_detail_writer.pid"
1927 INTERVAL=1
2028 EMPTY_GRACE=3
29+PIN_GRACE=300
2130
2231 takeover_singleton() {
2332 local pid
@@ -49,6 +58,8 @@ atomic_write() {
4958 printf '%s\n' "$content" > "$tmp" && mv -f "$tmp" "$target"
5059 }
5160
61+sanitize() { printf '%s' "$1" | tr -c 'A-Za-z0-9._-' '_'; }
62+
5263 # Current line only. Truncate in place (same inode, same path) so a reader
5364 # that re-reads the file every interval gets the new content and never sees
5465 # a pile of old lines. Empty state = empty file.
@@ -60,10 +71,26 @@ write_output() {
6071 fi
6172 }
6273
74+# Written only when the shown player changes. Empty file = nothing shown.
75+last_chosen="__init__"
76+write_chosen() {
77+ [[ "$1" == "$last_chosen" ]] && return
78+ if [[ -z "$1" ]]; then
79+ : > "$CHOSEN_FILE"
80+ else
81+ atomic_write "$CHOSEN_FILE" "$1"
82+ fi && last_chosen="$1"
83+}
84+
6385 last_emit="__init__"
6486 empty_streak=0
6587 last_position=""
6688 last_track=""
89+declare -A prev_status=()
90+pin_missing_since=0
91+pin_noinfo_since=0
92+last_good_text=""
93+text_owner=""
6794
6895 emit() {
6996 local out="$1"
@@ -87,6 +114,20 @@ pango_escape() {
87114 printf '%s' "$s"
88115 }
89116
117+# Url host of a player's current page; empty for non-http(s) or no url.
118+host_of() {
119+ local url
120+ url=$(playerctl -p "$1" metadata xesam:url 2>/dev/null)
121+ case "$url" in
122+ http://*|https://*) printf '%s' "$url" | sed -E 's#^[a-z]+://([^/]+).*#\1#' ;;
123+ esac
124+}
125+
126+# Args: name host base epoch
127+write_pin() {
128+ atomic_write "$PIN_FILE" "$(printf '%s\n%s\n%s\n%s' "$1" "$2" "$3" "$4")"
129+}
130+
90131 # File must exist for readers. Carry over at most the current line — any
91132 # accumulated log from an older append-mode build is dropped here.
92133 if [[ -s "$OUTPUT_FILE" ]]; then
@@ -94,71 +135,160 @@ if [[ -s "$OUTPUT_FILE" ]]; then
94135 else
95136 : > "$OUTPUT_FILE"
96137 fi
138+[[ -f "$CHOSEN_FILE" ]] || : > "$CHOSEN_FILE"
97139
98-while true; do
99- if ! command -v playerctl &>/dev/null; then
100- emit ""
101- sleep "$INTERVAL"
102- continue
140+# Sets globals: out (line to show), chosen (player shown).
141+# Seconds -> MM:SS, or H:MM:SS once past an hour.
142+fmt_time() {
143+ local t=$1
144+ if (( t >= 3600 )); then
145+ printf "%d:%02d:%02d" $((t / 3600)) $((t % 3600 / 60)) $((t % 60))
146+ else
147+ printf "%02d:%02d" $((t / 60)) $((t % 60))
103148 fi
149+}
104150
105- player_list=$(playerctl -l 2>/dev/null)
106- if [[ -z "$player_list" ]]; then
107- emit ""
108- sleep "$INTERVAL"
109- continue
151+tick() {
152+ out=""
153+ chosen=""
154+ local now player_list player player_status started ts act_file info
155+ local status artist title duration_us position_us duration body
156+ local best_playing="" best_playing_ts=-1 best_paused="" best_paused_ts=0
157+ local pin_name="" pin_host="" pin_base="" pin_time="" pin_mode=0 pin_lines=()
158+ local cand cur_host icon position position_sec pos_minutes pos_seconds
159+ local duration_sec minutes seconds track_id POSITION_CACHE
160+ local -A status_of=()
161+
162+ if ! command -v playerctl &>/dev/null; then
163+ return
110164 fi
111165
112166 now=$(date +%s)
113- sanitize() { printf '%s' "$1" | tr -c 'A-Za-z0-9._-' '_'; }
167+ player_list=$(playerctl -l 2>/dev/null)
114168
115- best_playing=""
116- best_playing_ts=0
117- best_paused=""
118- best_paused_ts=0
169+ # Status pass: record status, mark Playing transitions, bump activity.
119170 while IFS= read -r player; do
120171 [[ -z "$player" ]] && continue
121172 player_status=$(playerctl -p "$player" status 2>/dev/null)
122- act_file="${ACTIVITY_PREFIX}$(sanitize "$player")"
173+ status_of["$player"]="$player_status"
123174 if [[ "$player_status" == "Playing" ]]; then
124- atomic_write "$act_file" "$now"
125- ts="$now"
126- if (( ts > best_playing_ts )); then
127- best_playing_ts="$ts"
128- best_playing="$player"
129- fi
130- elif [[ "$player_status" == "Paused" ]]; then
131- ts=0
132- [[ -f "$act_file" ]] && ts=$(cat "$act_file" 2>/dev/null) && [[ -z "$ts" ]] && ts=0
133- if (( ts > best_paused_ts )); then
134- best_paused_ts="$ts"
135- best_paused="$player"
175+ if [[ "${prev_status[$player]:-}" != "Playing" ]]; then
176+ atomic_write "${STARTED_PREFIX}$(sanitize "$player")" "$(date +%s%N)"
136177 fi
178+ atomic_write "${ACTIVITY_PREFIX}$(sanitize "$player")" "$now"
137179 fi
180+ prev_status["$player"]="$player_status"
138181 done <<< "$player_list"
139182
140- chosen="${best_playing:-$best_paused}"
183+ # Forget players that vanished, so a reappearing player counts as a new start.
184+ for p in "${!prev_status[@]}"; do
185+ [[ -n "${status_of[$p]+x}" ]] || unset "prev_status[$p]"
186+ done
141187
142- if [[ -z "$chosen" ]]; then
143- emit ""
144- sleep "$INTERVAL"
145- continue
188+ # Pin file, if any with a non-empty line 1.
189+ if [[ -f "$PIN_FILE" ]]; then
190+ mapfile -t pin_lines < "$PIN_FILE"
191+ pin_name="${pin_lines[0]:-}"
192+ pin_host="${pin_lines[1]:-}"
193+ pin_base="${pin_lines[2]:-}"
194+ pin_time="${pin_lines[3]:-$now}"
195+ [[ -z "$pin_base" ]] && pin_base="${pin_name%%.*}"
196+ fi
197+
198+ if [[ -n "$pin_name" ]]; then
199+ pin_mode=1
200+ # New pin target: drop the held text of the previous one.
201+ if [[ "$pin_name" != "$text_owner" ]]; then
202+ last_good_text=""
203+ text_owner="$pin_name"
204+ fi
205+
206+ if [[ -n "${status_of[$pin_name]+x}" ]]; then
207+ # Pinned player is listed: it wins over everything else.
208+ pin_missing_since=0
209+ chosen="$pin_name"
210+ cur_host=$(host_of "$pin_name")
211+ if [[ -n "$cur_host" && "$cur_host" != "$pin_host" ]]; then
212+ pin_host="$cur_host"
213+ write_pin "$pin_name" "$pin_host" "$pin_base" "$pin_time"
214+ fi
215+ else
216+ # Re-attach: same base name, and same host when one is pinned.
217+ cand=""
218+ while IFS= read -r player; do
219+ [[ -z "$player" || "${player%%.*}" != "$pin_base" ]] && continue
220+ if [[ -n "$pin_host" && "$(host_of "$player")" != "$pin_host" ]]; then
221+ continue
222+ fi
223+ if [[ "${status_of[$player]}" == "Playing" ]]; then
224+ cand="$player"
225+ break
226+ fi
227+ [[ -z "$cand" ]] && cand="$player"
228+ done <<< "$player_list"
229+
230+ if [[ -n "$cand" ]]; then
231+ pin_name="$cand"
232+ text_owner="$cand"
233+ pin_missing_since=0
234+ write_pin "$pin_name" "$pin_host" "$pin_base" "$pin_time"
235+ chosen="$pin_name"
236+ else
237+ [[ $pin_missing_since -eq 0 ]] && pin_missing_since="$now"
238+ if (( now - pin_missing_since < PIN_GRACE )); then
239+ out="📌 ⏳ ${last_good_text:-Loading…}"
240+ return
241+ fi
242+ rm -f "$PIN_FILE"
243+ notify-send "Media pin released" "$pin_name disappeared" 2>/dev/null || true
244+ pin_mode=0
245+ pin_missing_since=0
246+ fi
247+ fi
146248 fi
147249
148- info=$(playerctl -p "$chosen" metadata --format '{{status}} {{artist}} {{title}} {{mpris:length}} {{position}}' 2>/dev/null)
149- if [[ -z "$info" ]]; then
150- emit ""
151- sleep "$INTERVAL"
152- continue
250+ if (( pin_mode == 0 )); then
251+ # Auto: most recently started Playing player, else latest Paused.
252+ while IFS= read -r player; do
253+ [[ -z "$player" ]] && continue
254+ player_status="${status_of[$player]}"
255+ if [[ "$player_status" == "Playing" ]]; then
256+ started=$(cat "${STARTED_PREFIX}$(sanitize "$player")" 2>/dev/null)
257+ [[ "$started" =~ ^[0-9]+$ ]] || started=0
258+ if (( started > best_playing_ts )); then
259+ best_playing_ts="$started"
260+ best_playing="$player"
261+ fi
262+ elif [[ "$player_status" == "Paused" ]]; then
263+ ts=0
264+ act_file="${ACTIVITY_PREFIX}$(sanitize "$player")"
265+ [[ -f "$act_file" ]] && ts=$(cat "$act_file" 2>/dev/null) && [[ -z "$ts" ]] && ts=0
266+ if (( ts > best_paused_ts )); then
267+ best_paused_ts="$ts"
268+ best_paused="$player"
269+ fi
270+ fi
271+ done <<< "$player_list"
272+ chosen="${best_playing:-$best_paused}"
273+ [[ -z "$chosen" ]] && return
153274 fi
154275
155- IFS=$'\t' read -r status artist title duration_us position_us <<< "$info"
276+ # \x1f (unit separator), not tab: tab is IFS whitespace, so an empty
277+ # artist would collapse and shift every later field left.
278+ info=$(playerctl -p "$chosen" metadata --format $'{{status}}\x1f{{artist}}\x1f{{title}}\x1f{{mpris:length}}\x1f{{position}}' 2>/dev/null)
279+ IFS=$'\x1f' read -r status artist title duration_us position_us <<< "$info"
156280
157- if [[ "$status" == "Stopped" ]]; then
158- emit ""
159- sleep "$INTERVAL"
160- continue
281+ if [[ -z "$info" || "$status" == "Stopped" ]]; then
282+ # Pinned player with no info (slow track change): hold for a while.
283+ if (( pin_mode )); then
284+ [[ $pin_noinfo_since -eq 0 ]] && pin_noinfo_since="$now"
285+ if (( now - pin_noinfo_since < PIN_GRACE )); then
286+ out="📌 ⏳ ${last_good_text:-Loading…}"
287+ fi
288+ fi
289+ return
161290 fi
291+ pin_noinfo_since=0
162292
163293 if [[ "$status" == "Playing" ]]; then
164294 icon="▶"
@@ -168,10 +298,7 @@ while true; do
168298
169299 duration=""
170300 if [[ "$duration_us" =~ ^[0-9]+$ ]]; then
171- duration_sec=$((duration_us / 1000000))
172- minutes=$((duration_sec / 60))
173- seconds=$((duration_sec % 60))
174- duration=$(printf "%02d:%02d" $minutes $seconds)
301+ duration=$(fmt_time $((duration_us / 1000000)))
175302 fi
176303
177304 POSITION_CACHE="${POSITION_CACHE_PREFIX}$(sanitize "$chosen")"
@@ -183,10 +310,7 @@ while true; do
183310 fi
184311 if [[ "$status" == "Playing" ]]; then
185312 if [[ "$position_us" =~ ^[0-9]+$ ]]; then
186- position_sec=$((position_us / 1000000))
187- pos_minutes=$((position_sec / 60))
188- pos_seconds=$((position_sec % 60))
189- position=$(printf "%02d:%02d" $pos_minutes $pos_seconds)
313+ position=$(fmt_time $((position_us / 1000000)))
190314 atomic_write "$POSITION_CACHE" "$position"
191315 last_position="$position"
192316 elif [[ -n "$last_position" ]]; then
@@ -202,21 +326,32 @@ while true; do
202326 title=$(pango_escape "$title")
203327
204328 if [[ -n "$artist" && -n "$title" && -n "$duration" && -n "$position" ]]; then
205- out="$icon $artist - $title ($position / $duration)"
329+ body="$artist - $title ($position / $duration)"
206330 elif [[ -n "$artist" && -n "$title" && -n "$duration" ]]; then
207- out="$icon $artist - $title ($duration)"
331+ body="$artist - $title ($duration)"
208332 elif [[ -n "$title" && -n "$duration" && -n "$position" ]]; then
209- out="$icon $title ($position / $duration)"
333+ body="$title ($position / $duration)"
210334 elif [[ -n "$title" && -n "$duration" ]]; then
211- out="$icon $title ($duration)"
335+ body="$title ($duration)"
212336 elif [[ -n "$artist" && -n "$title" ]]; then
213- out="$icon $artist - $title"
337+ body="$artist - $title"
214338 elif [[ -n "$title" ]]; then
215- out="$icon $title"
339+ body="$title"
216340 else
217- out="$icon Something's Playing"
341+ body="Something's Playing"
218342 fi
219343
344+ if (( pin_mode )); then
345+ last_good_text="$body"
346+ out="📌 $icon $body"
347+ else
348+ out="$icon $body"
349+ fi
350+}
351+
352+while true; do
353+ tick
354+ write_chosen "$chosen"
220355 emit "$out"
221356 sleep "$INTERVAL"
222357 done
.config/scripts/shared/webapp.shmodified+8 -1
@@ -31,7 +31,14 @@ HOST="${URL#*://}"
3131 HOST="${HOST%%/*}"
3232 CLASS="chrome-${HOST}__-Default"
3333
34-cmd=(flatpak run "$BROWSER_ID"
34+# Chromium names its MPRIS player chromium.instance<pid>, and inside a flatpak
35+# sandbox the browser is always pid 2 — so this app, the Chromium flatpak and
36+# FreeTube all fight over chromium.instance2 and only one shows in playerctl.
37+# Running chromium as a child of a sandbox shell moves it to pid 3, giving the
38+# web apps their own player name. The trailing `exit` stops bash from exec'ing
39+# a lone command (which would keep chromium at pid 2).
40+cmd=(flatpak run --command=bash "$BROWSER_ID"
41+ -c 'chromium "$@"; exit $?' bash
3542 --no-first-run
3643 --app="$URL"
3744 --class="$CLASS"
.config/waybar/config-hyprlandmodified+2 -1
@@ -81,8 +81,9 @@
8181 "format": "{}",
8282 "exec": "cat /tmp/song_detail_last 2>/dev/null",
8383 "interval": 1,
84- "on-click": "bash ~/.config/scripts/shared/playerctl-active.sh play-pause",
84+ "on-click": "bash ~/.config/scripts/shared/playerctl_active.sh play-pause",
8585 "on-click-right": "bash ~/.config/scripts/shared/show_cover.sh",
86+ "on-click-middle": "bash ~/.config/scripts/shared/media_menu.sh",
8687 "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+",
8788 "on-scroll-down": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
8889 },
.config/waybar/config-nirimodified+2 -1
@@ -81,8 +81,9 @@
8181 "format": "{}",
8282 "exec": "cat /tmp/song_detail_last 2>/dev/null",
8383 "interval": 1,
84- "on-click": "bash ~/.config/scripts/shared/playerctl-active.sh play-pause",
84+ "on-click": "bash ~/.config/scripts/shared/playerctl_active.sh play-pause",
8585 "on-click-right": "bash ~/.config/scripts/shared/show_cover.sh",
86+ "on-click-middle": "bash ~/.config/scripts/shared/media_menu.sh",
8687 "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+",
8788 "on-scroll-down": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
8889 },