From 4afad01affa01f6715ddfc11a97248bb2a5c6485 Mon Sep 17 00:00:00 2001 From: spl3g Date: Sun, 22 Sep 2024 01:51:16 +0300 Subject: feat(hyprland): add a script to switch sinks --- .../attachments/hypr-scripts/switch_sink.py | 39 ++++++++++++++++++++++ home-manager/homeModules/hyprland.nix | 7 +++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 home-manager/homeModules/attachments/hypr-scripts/switch_sink.py diff --git a/home-manager/homeModules/attachments/hypr-scripts/switch_sink.py b/home-manager/homeModules/attachments/hypr-scripts/switch_sink.py new file mode 100644 index 0000000..b8c4932 --- /dev/null +++ b/home-manager/homeModules/attachments/hypr-scripts/switch_sink.py @@ -0,0 +1,39 @@ +import subprocess + +status = subprocess.run(["wpctl", "status"], stdout=subprocess.PIPE).stdout.decode('utf-8') +status_lines = status.split('\n') +sink_line = 0 +selected_sink = 0 +sinks = [] +sink_names = [] + +# Get sink line +for i in range(len(status_lines) - 1): + if 'Sinks:' in status_lines[i]: + sink_line = i + 1 + break + +# Find unused sinks +for line in status_lines[sink_line:]: + if line == ' │ ': + break + line = line.split('.') + nums = line[0] + name = line[1] + end_name = line[1].index('[') + sink = nums[8:] + if nums[4] == '*': + selected_sink = sink + + sinks.append(sink) + sink_names.append(name[:end_name].strip()) + +next_sink = sinks.index(selected_sink) + 1 +if next_sink == len(sinks): + next_sink = 0 + +next_sink_name = sink_names[next_sink] +subprocess.run(["wpctl", "set-default", sinks[next_sink]]) + +subprocess.run(["notify-send", "Pipewire sink", "Selected " + next_sink_name]) + diff --git a/home-manager/homeModules/hyprland.nix b/home-manager/homeModules/hyprland.nix index 3bab526..5fb7d5a 100644 --- a/home-manager/homeModules/hyprland.nix +++ b/home-manager/homeModules/hyprland.nix @@ -24,6 +24,7 @@ polkit_gnome xwaylandvideobridge wl-clipboard + libnotify ]; xdg.portal = { @@ -105,9 +106,12 @@ "noborder, title:^(Firefox — Sharing Indicator)$" "rounding 0, title:^(Firefox — Sharing Indicator)$" "float, class:^(firefox)$, title:^(Picture-in-Picture)$" - "pin, title:^(firefox)$, title:^(Picture-in-Picture)$" + "pin, class:^(firefox)$, title:^(Picture-in-Picture)$" + "move 100%-w-20 100%-w-20, class:^(firefox)$, title:^(Picture-in-Picture)$" + "float, class:^(firefox)&, title:^Extension:.*\bBitwarden\b" "float, title:^(Save File)$" "pin, title:^(Save File)$" + "pin, class:^(dragon)$" "float, title:^(Torrent Options)$" "pin, title:^(Torrent Options)$" "opacity 0.0 override 0.0 override,class:^(xwaylandvideobridge)$" @@ -150,6 +154,7 @@ ",0x1008FF13,exec,wpctl set-volume @DEFAULT_SINK@ 5%+" ",0x1008FF12,exec,wpctl set-mute @DEFAULT_SINK@ toggle" ",XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_SOURCE@ toggle" + ",XF86Go, exec, python3 $scripts/switch_sink.py" # Brightness ",XF86MonBrightnessUp,exec,brightnessctl s +5%" -- cgit v1.2.3