Add screenshare script

This commit is contained in:
Jakob Lechner 2024-06-19 00:29:59 +02:00
parent 9663b395ce
commit 749710bbfb
2 changed files with 56 additions and 0 deletions

View file

@ -40,6 +40,7 @@ in
{
imports = lib.optionals nixosConfig.jalr.gui.enable [
./gammastep.nix
./screenshare.nix
./waybar.nix
./wofi.nix
./wofi-bluetooth.nix

View file

@ -0,0 +1,55 @@
{ pkgs, ... }:
{
home.packages = [
(
pkgs.writeShellScriptBin "screenshare" ''
# https://github.com/emersion/xdg-desktop-portal-wlr/issues/107
case "$1" in
start)
# Step 1: Create a new output
swaymsg create_output
# Step 2: Find the name of the newly created output
NEW_OUTPUT=$(swaymsg -t get_outputs | jq -r '.[] | select(.name | startswith("HEADLESS-")) | .name' | sort | tail -n 1)
# Check if the output was successfully created
if [ -z "$NEW_OUTPUT" ]; then
echo "Failed to create a new output."
exit 1
fi
# Step 3: Assign a workspace to the new output
swaymsg workspace sshr output "$NEW_OUTPUT"
# Step 4: Set the resolution for the new output
swaymsg output "$NEW_OUTPUT" resolution 1280x720
# Step 5: Set the background color for the new output
swaymsg output "$NEW_OUTPUT" bg "#220900" solid_color
# Step 6: Switch to workspace sshr and then back to the previous workspace
CURRENT_WORKSPACE=$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused) | .name')
swaymsg workspace sshr
swaymsg workspace "$CURRENT_WORKSPACE"
;;
stop)
headless_outputs=$(swaymsg -t get_outputs | jq -r '.[] | select(.name | startswith("HEADLESS-")) | .name')
# Check if there are any HEADLESS outputs
if [ -z "$headless_outputs" ]; then
echo "No HEADLESS outputs found."
exit 0
fi
# Unplug each HEADLESS output
for output in $headless_outputs; do
echo "Unplugging $output..."
swaymsg output "$output" unplug
done
;;
esac
''
)
];
}