dotfiles.git

commit 6768ceb116beb3229d04422c1ffb13a8779c992f

Author: Adam <git@apiote.xyz>

fix bluetooth hangup when playing in mpv

 .local/bin/bar_bluetooth | 5 ++++-
 .local/bin/bt | 21 ++++++++++-----------


diff --git a/.local/bin/bar_bluetooth b/.local/bin/bar_bluetooth
index 150aa9d038f638241933e39ae4df60d997708f83..71355aafa3ad74d8a14c2275547e708fe8cc4f31 100755
--- a/.local/bin/bar_bluetooth
+++ b/.local/bin/bar_bluetooth
@@ -12,7 +12,10 @@ 		printf ''
 	fi
 }
 
-if [ -e /tmp/swaybar/pipe ]
+mpv_count=$(cat /tmp/mpv_count 2>/dev/null)
+mpv_count=${mpv_count:-0}
+
+if [ -e /tmp/swaybar/pipe ] && [ "$mpv_count" -eq 0 ]
 then
 	printf "bluetooth|%s\n" "$(render)" >/tmp/swaybar/pipe
 fi




diff --git a/.local/bin/bt b/.local/bin/bt
index 558b7e32da04bf865add337cd5752e2450133dfa..a253004ffaa04ebd7dc9162b07b2b85667db20fc 100755
--- a/.local/bin/bt
+++ b/.local/bin/bt
@@ -1,21 +1,20 @@
 #!/bin/sh
 
+trap bar_bluetooth SIGINT
+
 if [ "$1" = 'on' ]
 then
-	doas rfkill unblock bluetooth
-	bluetoothctl power on
-	bluetoothctl connect 9C:19:C2:95:5D:E1
-
-	# asound=$(sed 's/slave.pcm dmix/slave.pcm blue/' < ~/.asoundrc)
-	# echo "$asound" > ~/.asoundrc
-
-	# sleep 5
-	# amixer -D bluealsa sset 'Mittens - A2DP' 50% >/dev/null 2>&1
+	(
+		set -e
+		doas rfkill unblock bluetooth
+		sleep 1
+		bluetoothctl power on || (sleep 2; bluetoothctl power on)
+		sleep 1
+		bluetoothctl connect 9C:19:C2:95:5D:E1
+	)
 elif [ "$1" = 'off' ]
 then
 	bluetoothctl power off
-	# asound=$(sed 's/slave.pcm blue/slave.pcm dmix/' < ~/.asoundrc)
-	# echo "$asound" > ~/.asoundrc
 else
 	bluetoothctl show | grep Powered | cut -f2
 	bluetoothctl info | grep -E '(Alias|Connected)' | cut -f2