From 427a0f9ec6f1643c6a90a5d852804fb2e5c24ae2 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 23 Dec 2024 01:28:26 +0100 Subject: [PATCH] update screen grab scripts to partially support wayland --- scripts/record_mp4.sh | 38 ++++++++++++++++++++++----------- scripts/screenshot_full.sh | 11 ++++++++-- scripts/screenshot_selection.sh | 8 ++++++- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/scripts/record_mp4.sh b/scripts/record_mp4.sh index 9c7d5c8..40a7b42 100755 --- a/scripts/record_mp4.sh +++ b/scripts/record_mp4.sh @@ -1,20 +1,27 @@ #!/bin/bash -statusfile="/tmp/running_screen_recorder" +STATUSFILE="/tmp/running_screen_recorder" # check for running instance, stop it and exit -if [ -f $statusfile ]; then - ffpid=$(<$statusfile) - kill $ffpid - rm $statusfile +if [ -f $STATUSFILE ]; then + FFPID=$(<$STATUSFILE) + kill $FFPID + rm $STATUSFILE exit 0 fi # select area of screen -slop=$(slop -f "%x %y %w %h %g %i" --color=0.8,0.4,1.0,1.0 -t 16) || exit 1 -read -r X Y W H G ID < <(echo $slop) +if [ $XDG_SESSION_TYPE = 'wayland' ]; then + SLURP=$(slurp -b#ff44ff22 -w0) || exit 1 + read -r POS DIMS < <(echo $SLURP) + W=${DIMS%x*} + H=${DIMS#*x} +else + SLOP=$(slop -f "%x,%y %w %h" --color=0.8,0.4,1.0,1.0 -t 16) || exit 1 + read -r POS W H< <(echo $SLOP) +fi -videofile=$(xdg-user-dir VIDEOS)/sel_$(date "+%Y-%m-%d_%H.%M.%S").mp4 -logfile="/tmp/screen_recorder_ffmpeg.log" +OUTPUT_FILE=$(xdg-user-dir VIDEOS)/sel_$(date "+%Y-%m-%d_%H.%M.%S").mp4 +LOGFILE="/tmp/screen_recorder_ffmpeg.log" # make sure selection width and height is even # even video size needed for yuv420p format @@ -22,10 +29,15 @@ logfile="/tmp/screen_recorder_ffmpeg.log" H=$(( $H - $H%2 )) W=$(( $W - $W%2 )) +# empty audio track to prevent videos showing up as "GIF" on certain platforms (mastodon) dummy_audio="-f lavfi -i anullsrc=cl=mono" -ffmpeg -y $dummy_audio -video_size "$W"x"$H" -f x11grab -framerate 60 \ --i $DISPLAY+$X,$Y -pix_fmt yuv420p $videofile 2> $logfile & - +if [ $XDG_SESSION_TYPE = 'wayland' ]; then + echo "fuck (todo figure out wayland ffmpeg shit)" + # ffmpeg $video_settings -device /dev/dri/card1-re-fkms-grab -i - $OUTPUT_FILE 2> $LOGFILE & +else + ffmpeg -y $dummy_audio -video_size "$W"x"$H" -f x11grab -framerate 60 \ + -i $DISPLAY+$POS -pix_fmt yuv420p $OUTPUT_FILE 2> $LOGFILE & +fi # store pid so that recording can be stopped next time the script is run -echo $! > $statusfile +echo $! > $STATUSFILE diff --git a/scripts/screenshot_full.sh b/scripts/screenshot_full.sh index e71f796..0faf0d4 100755 --- a/scripts/screenshot_full.sh +++ b/scripts/screenshot_full.sh @@ -1,5 +1,12 @@ #!/bin/bash path=$(xdg-user-dir PICTURES)/screenshots/screen-$(date "+%Y-%m-%d_%H:%M:%S").png mkdir -p $(xdg-user-dir PICTURES)/screenshots -maim -u -o $path -xclip -selection clipboard -target image/png -i $path + +if [ $XDG_SESSION_TYPE = 'wayland' ]; then + grim $path + wl-copy -t image/png < $path +else + maim -u -o $path + xclip -selection clipboard -target image/png -i $path +fi + diff --git a/scripts/screenshot_selection.sh b/scripts/screenshot_selection.sh index 6315712..ff540bf 100755 --- a/scripts/screenshot_selection.sh +++ b/scripts/screenshot_selection.sh @@ -1,2 +1,8 @@ #!/bin/bash -maim -s -u --color=1.0,0.5,0.0,1.0 -t 16 | xclip -selection clipboard -t image/png + +if [ $XDG_SESSION_TYPE = 'wayland' ]; then + grim -g "$(slurp -b#ffff4411 -w0)" - | wl-copy -t image/png +else + maim -s -u --color=1.0,0.5,0.0,1.0 -t 16 | xclip -selection clipboard -t image/png +fi +