diff --git a/bin/scrcap b/bin/scrcap index d1478b3c..6a2284b0 100755 --- a/bin/scrcap +++ b/bin/scrcap @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env cached-nix-shell +#! nix-shell -i bash -p maim slop # A script that takes a screenshot (prompts you for what region/window to # capture) and stores it in the clipboard. @@ -8,7 +9,7 @@ cleanup() { rm -f "$tmp"; } trap cleanup EXIT # Delay for long enough that we can refocus the targeted window -if maim --delay=${1:-0.6} -us >"$tmp"; then +if maim --delay=${2:-1} -us >"$tmp"; then xclip -selection clipboard -t image/png "$tmp" && notify-send "Screenshot saved" else diff --git a/bin/scrrec b/bin/scrrec index 020dd0fd..2aa0c8e4 100755 --- a/bin/scrrec +++ b/bin/scrrec @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env cached-nix-shell +#! nix-shell -i bash -p ffmpeg slop # Select a region and record it. # @@ -14,26 +15,25 @@ geom= delay=1 count=3 fps=30 -compton=1 stopfile=/tmp/_stop -while getopts spg:d:c: opt; do +while getopts c:d:f:g:ps opt; do case $opt in - s) is_script=1 ;; c) count=$OPTARG ;; - p) compton= ;; + d) delay="$OPTARG" ;; f) fps=$OPTARG ;; g) geom="$OPTARG" ;; - d) delay="$OPTARG" ;; + p) compton= ;; + s) is_script=1 ;; esac done shift $((OPTIND-1)) ## -select_region() { +select-region() { if [[ $geom ]]; then echo "${geom//[x+]/ }" else - slop -n -f "%x %y %w %h" + slop -nof "%w %h %x %y" fi } @@ -55,11 +55,9 @@ countdown() { } recording-start() { - local X Y W H - read -r X Y W H < <(select_region) - local ffmpeg_opts="-y -f x11grab -show_region 1 -ss $delay -s ${W}x${H} -i :0.0+${X},${Y} -framerate ${fps}" + local ffmpeg_opts="-y -f x11grab -show_region 1 -ss $delay -s ${4}x${5} -i :0.0+${2},${3} -framerate ${fps}" local dest=${1:-./rec.mp4} - local mp4dest + local mp4dest= [[ $dest == *.gif ]] && mp4dest="${dest%.*}.mp4" countdown touch $stopfile @@ -80,14 +78,19 @@ if [[ $is_script && -f $stopfile ]]; then exit 0 fi +read -r W H X Y < <(select-region) + # Compton with blur and/or transparencies cause unbearable flickering in # recordings, so temporarily disable it. +compton= if systemctl is-enabled --user compton >/dev/null; then systemctl --user stop compton + compton=1 fi -recording-start "$dest" -if systemctl is-enabled --user compton >/dev/null; then - systemctl --user start compton -fi +cleanup() { [[ $compton ]] && systemctl --user start compton; } +trap cleanup EXIT + +# Let 'er rip +recording-start "$dest" "$X" "$Y" "$W" "$H" # vim:set ft=sh shiftwidth=2: