added script to connect and disconnect headset

This commit is contained in:
twoneis 2025-03-19 11:20:05 +01:00
parent 6d005a373a
commit c2a5b6b617
3 changed files with 60 additions and 51 deletions

11
modules/niri/connect-headset.sh Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
set -l mac "FC:C3:3A:00:04:C2"
set -l connected (bluetoothctl info $mac | grep "Connected:")
if string match -qr ".*yes" $connected
bluetoothctl disconnect $mac
else
bluetoothctl connect $mac
end

View file

@ -7,57 +7,8 @@
inherit (config.conf) keys extraLayout;
inherit (lib.attrsets) genAttrs;
inherit (lib) mkMerge;
switch-sink =
pkgs.writeScript "switch-sink"
''
#!/usr/bin/env fish
# set -l regex '^.* (\*?) \s+ ([[:digit:]]*)\. .* \[.*$'
set -l sed 's/^.* ([[:digit:]]*)\. .*$/\1/'
set -l awk 'BEGIN { A=0; S=0; } /^Audio/ { A=1; } /Sinks/ { S=1; } /Sources/ { S=0; } /^Video/ { A=0; } { if (A==1 && S==1 && / [[:digit:]]*\./) { print; } }'
set -l lines (wpctl status | awk $awk)
set -l len (count $lines)
set -l current
set -l sinks
for i in (seq 1 $len)
set -l sink (echo $lines[$i] | sed -E $sed)
set -a sinks $sink
if string match -qr '\*' $lines[$i]
set current $sink
end
end
set -l len (count $sinks)
set -l index
for i in (seq 1 $len)
if [ $sinks[$i] = $current ]
if [ $argv[1] = '-f' ]
if [ $i = $len ]
set index 1
else
set index (math $i + 1)
end
else if [ $argv[1] = '-b' ]
if [ $i = 1 ]
set index $len
else
set index (math $i - 1)
end
else
exit 1
end
break
end
end
wpctl set-default $sinks[$index]
'';
switch-sink = pkgs.writeScript "switch-sink" (builtins.readFile ./switch-sink.sh);
connect-headset = pkgs.writeScript "connect-headset" (builtins.readFile ./connect-headset.sh);
in {
input = {
keyboard = {
@ -196,6 +147,7 @@ in {
"XF86AudioNext".action.spawn = ["${switch-sink}" "-f"];
"XF86AudioPrev".action.spawn = ["${switch-sink}" "-b"];
"XF86AudioPlay".action.spawn = ["${connect-headset}"];
"XF86AudioRaiseVolume".action.spawn = [
"swayosd-client"

46
modules/niri/switch-sink.sh Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env fish
set -l sed 's/^.* ([[:digit:]]*)\. .*$/\1/'
set -l awk 'BEGIN { A=0; S=0; } /^Audio/ { A=1; } /Sinks/ { S=1; } /Sources/ { S=0; } /^Video/ { A=0; } { if (A==1 && S==1 && / [[:digit:]]*\./) { print; } }'
set -l lines (wpctl status | awk $awk)
set -l len (count $lines)
set -l current
set -l sinks
for i in (seq 1 $len)
set -l sink (echo $lines[$i] | sed -E $sed)
set -a sinks $sink
if string match -qr '\*' $lines[$i]
set current $sink
end
end
set -l len (count $sinks)
set -l index
for i in (seq 1 $len)
if [ $sinks[$i] = $current ]
if [ $argv[1] = '-f' ]
if [ $i = $len ]
set index 1
else
set index (math $i + 1)
end
else if [ $argv[1] = '-b' ]
if [ $i = 1 ]
set index $len
else
set index (math $i - 1)
end
else
exit 1
end
break
end
end
wpctl set-default $sinks[$index]