This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/dotfiles/scripts/sway-screenshare

47 lines
1.6 KiB
Plaintext
Raw Normal View History

2020-11-03 06:15:23 +01:00
#!/bin/sh
set -x
2020-04-22 19:34:34 +02:00
if ! lsmod | grep v4l2loopback > /dev/null; then
2020-12-07 03:38:41 +01:00
echo "Adding v42loopback module to kernel"
sudo modprobe v4l2loopback
2020-04-22 19:34:34 +02:00
fi
geometry(){
2020-12-07 03:38:41 +01:00
windowGeometries=$(
# `height - 1` is there because of: https://github.com/ammen99/wf-recorder/pull/56 (I could remove it if it's merged, maybe)
swaymsg -t get_workspaces -r | jq -r '.[] | select(.focused) | .rect | "\(.x),\(.y) \(.width)x\(.height - 1)"'; \
swaymsg -t get_outputs -r | jq -r '.[] | select(.active) | .rect | "\(.x),\(.y) \(.width)x\(.height)"'
)
geometry=$(slurp -b "#45858820" -c "#45858880" -w 3 -d <<< "$windowGeometries") || exit $?
echo $geometry
2020-04-22 19:34:34 +02:00
}
{
2020-10-06 09:08:16 +02:00
if pidof wf-recorder > /dev/null && pidof ffplay > /dev/null
2020-06-16 21:58:16 +02:00
then
2020-12-07 03:38:41 +01:00
if pidof ffplay > /dev/null; then
pkill ffplay > /dev/null
fi
if pidof wf-recorder > /dev/null; then
pkill wf-recorder > /dev/null
fi
notify-send -t 2000 "Wayland recording has been stopped"
2020-04-22 19:34:34 +02:00
else
2020-12-07 03:38:41 +01:00
if ! pidof wf-recorder > /dev/null; then
geometry=$(geometry) || exit $?
wf-recorder --muxer=v4l2 --codec=rawvideo --file=/dev/video2 --geometry="$geometry" &
fi
if ! pidof ffplay; then
swaymsg assign [class=ffplay] workspace 11
2020-06-16 21:58:16 +02:00
2020-12-07 03:38:41 +01:00
unset SDL_VIDEODRIVER
ffplay /dev/video2 -fflags nobuffer &
sleep 0.5
# a hack so FPS is not dropping
swaymsg [class=ffplay] floating enable
# swaymsg [class=ffplay] move position 1900 1000
# swaymsg focus tiling
fi
notify-send -t 2000 "Wayland recording has been started"
2020-04-22 19:34:34 +02:00
fi
} > ~/.wayland-share-screen.log 2>&1