From 1810959292510d12f8531f18335b2bb9f32cd51a Mon Sep 17 00:00:00 2001 From: Alexander Oakman Date: Sat, 24 Aug 2024 19:47:33 +0300 Subject: [PATCH 1/3] Fix notifications in recording mode --- usr/share/sway/scripts/recorder.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/share/sway/scripts/recorder.sh b/usr/share/sway/scripts/recorder.sh index 5b77da1..6909ac4 100755 --- a/usr/share/sway/scripts/recorder.sh +++ b/usr/share/sway/scripts/recorder.sh @@ -16,7 +16,7 @@ countdown() { notify() { line=$1 shift - notify-send "Recording" "${line}" -i /usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg "$*" + notify-send "${line}" -i /usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg "$@" } if [ $status != 0 ]; then From d59a58120bf758943c74e1e4b443dd3e636c4bfa Mon Sep 17 00:00:00 2001 From: Alexander Oakman Date: Sat, 24 Aug 2024 20:15:31 +0300 Subject: [PATCH 2/3] Improve the recorder script Make it possible to interrupt the recording area selection process by pressing the $mod + Escape key combination. --- etc/sway/modes/recording.conf | 2 +- usr/share/sway/scripts/recorder.sh | 38 +++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/etc/sway/modes/recording.conf b/etc/sway/modes/recording.conf index 41a2b58..410bd4e 100644 --- a/etc/sway/modes/recording.conf +++ b/etc/sway/modes/recording.conf @@ -16,4 +16,4 @@ mode --pango_markup $mode_recording { $bindsym $mod+Shift+r mode $mode_recording ## Launch // Stop Recording Mode ## -$bindsym $mod+Escape exec killall -s SIGINT wf-recorder +$bindsym $mod+Escape exec $recorder diff --git a/usr/share/sway/scripts/recorder.sh b/usr/share/sway/scripts/recorder.sh index 6909ac4..eae2abd 100755 --- a/usr/share/sway/scripts/recorder.sh +++ b/usr/share/sway/scripts/recorder.sh @@ -1,8 +1,4 @@ #!/bin/bash -set -x - -pgrep wf-recorder -status=$? countdown() { notify "Recording in 3 seconds" -t 1000 @@ -19,7 +15,28 @@ notify() { notify-send "${line}" -i /usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg "$@" } -if [ $status != 0 ]; then +kill_waybar() { + pkill -RTMIN+8 waybar +} + +kill_recursive() { + ps -o sid= -p "$1" | xargs pkill --signal SIGINT -g +} + +cleanup() { + pid=$(cat "$1") + rm "$1" + kill_waybar + kill_recursive "$pid" + exit +} + +main() { + pid_file="/tmp/screenrecorder-$UID.pid" + + test -e "$pid_file" && cleanup "$pid_file" + echo "$$" > "$pid_file" + target_path=$(xdg-user-dir VIDEOS) timestamp=$(date +'recording_%Y%m%d-%H%M%S') @@ -27,7 +44,7 @@ if [ $status != 0 ]; then area=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) countdown - (sleep 0.5 && pkill -RTMIN+8 waybar) & + (sleep 0.5 && kill_waybar) & if [ "$1" == "-a" ]; then file="$target_path/$timestamp.mp4" @@ -37,8 +54,7 @@ if [ $status != 0 ]; then wf-recorder -g "$area" -c libvpx --codec-param="qmin=0" --codec-param="qmax=25" --codec-param="crf=4" --codec-param="b:v=1M" --file="$file" fi - pkill -RTMIN+8 waybar && notify "Finished recording ${file}" -else - pkill --signal SIGINT wf-recorder - pkill -RTMIN+8 waybar -fi + kill_waybar && notify "Finished recording ${file}" + rm $pid_file +} +main "$@" From bca213279fc527a3a086fe0685257217de8de22f Mon Sep 17 00:00:00 2001 From: Alexander Oakman Date: Sat, 24 Aug 2024 20:19:43 +0300 Subject: [PATCH 3/3] Make the recorder script more readable --- usr/share/sway/scripts/recorder.sh | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/usr/share/sway/scripts/recorder.sh b/usr/share/sway/scripts/recorder.sh index eae2abd..0f0dedd 100755 --- a/usr/share/sway/scripts/recorder.sh +++ b/usr/share/sway/scripts/recorder.sh @@ -1,18 +1,17 @@ #!/bin/bash countdown() { - notify "Recording in 3 seconds" -t 1000 - sleep 1 - notify "Recording in 2 seconds" -t 1000 - sleep 1 - notify "Recording in 1 seconds" -t 1000 - sleep 1 + for count in {3..1}; do + notify "Recording in $count seconds" -t 1000 + sleep 1 + done } notify() { - line=$1 - shift - notify-send "${line}" -i /usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg "$@" + notify-send \ + "$1" \ + -i "/usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg" \ + "${@:2}" } kill_waybar() { @@ -41,17 +40,25 @@ main() { timestamp=$(date +'recording_%Y%m%d-%H%M%S') notify "Select a region to record" -t 1000 - area=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) + area=$(swaymsg -t get_tree | \ + jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | \ + slurp) countdown (sleep 0.5 && kill_waybar) & - if [ "$1" == "-a" ]; then + if [[ "$1" == "-a" ]]; then file="$target_path/$timestamp.mp4" wf-recorder --audio -g "$area" --file="$file" else file="$target_path/$timestamp.webm" - wf-recorder -g "$area" -c libvpx --codec-param="qmin=0" --codec-param="qmax=25" --codec-param="crf=4" --codec-param="b:v=1M" --file="$file" + wf-recorder \ + -g "$area" -c libvpx \ + --codec-param="qmin=0" \ + --codec-param="qmax=25" \ + --codec-param="crf=4" \ + --codec-param="b:v=1M" \ + --file="$file" fi kill_waybar && notify "Finished recording ${file}"