Add support for grim for screenshots

This commit is contained in:
Jacob 2023-09-12 15:59:36 +02:00
parent 806e4373a7
commit a8ea8e24e5
2 changed files with 22 additions and 30 deletions

View file

@ -16,8 +16,9 @@ Install the script and any dependencies and run it.
- If X11 is used
- maim
- If X11 is used
- wayshot
- grim OR wayshot
- If Wayland is used
- grim tends to work a bit better from my experience, but both are supported.
- wl-clipboard
- If Wayland is used
- slurp

View file

@ -15,36 +15,32 @@
[ -z "$PREFIX" ] && PREFIX="screenshot-"
[ -z "$SEND_NOTIF" ] && SEND_NOTIF="true"
wait_scr() {
[ -z "$2" ] && printf "You must specify a number\n" && exit 1
take_scr() {
sleep "$2"
if [ "$x11" = "true" ]; then
if [ "$x11" = "true" ] && [ -x "$(command -v maim)" ]; then
maim -s"${ARG2}"B > "$1" || exit 1
else
elif [ -x "$(command -v slurp)" ] && [ -x "$(command -v grim)" ]; then
grim -g "$(slurp)" - > "$1" || exit 1
elif [ -x "$(command -v slurp)" ] && [ -x "$(command -v wayshot)" ]; then
wayshot --stdout -s "$(slurp)" > "$1" || exit 1
fi
}
wait_full() {
[ -z "$3" ] && printf "You must specify a number.\n" && exit 1
sleep "$3"
if [ "$x11" = "true" ]; then
maim -"${ARG2}"B > "$1" || exit 1
else
wayshot --stdout > "$1" || exit 1
printf "Failed to take screenshot: Appropriate screenshot tools not found.\n" > /dev/stderr
fi
}
full_scr() {
[ ! -e "$1" ] && [ "$x11" = "true" ] && maim -"${ARG2}"B > "$1" && return
[ ! -e "$1" ] && wayshot --stdout > "$1"
}
take_full() {
sleep "$2"
sel_scr() {
[ ! -e "$1" ] && [ "$x11" = "true" ] && maim -sB > "$1" && return
[ ! -e "$1" ] && wayshot --stdout -s "$(slurp)" > "$1"
if [ "$x11" = "true" ] && [ -x "$(command -v maim)" ]; then
maim "${ARG2}"B > "$1" || exit 1
elif [ -x "$(command -v grim)" ]; then
grim - > "$1" || exit 1
elif [ -x "$(command -v wayshot)" ]; then
wayshot --stdout > "$1" || exit 1
else
printf "Failed to take screenshot: Appropriate screenshot tools not found.\n" > /dev/stderr
fi
}
send_notif() {
@ -104,13 +100,8 @@ rm -f /tmp/screenshot*
# check arguments
case "$1" in
"") print_help; exit 0 ;;
"-t")
[ "$2" = "-f" ] && wait_full "$@"
wait_scr "/tmp/screenshot-$DATE" "$2"
;;
"-f") full_scr "/tmp/screenshot-$DATE" ;;
"-s") sel_scr "/tmp/screenshot-$DATE" ;;
"-f") take_full "/tmp/screenshot-$DATE" "0" ;;
"-s") take_scr "/tmp/screenshot-$DATE" "0" ;;
*) print_help; exit 0 ;;
esac
@ -121,7 +112,7 @@ esac
[ ! -s "/tmp/screenshot-$DATE" ] && exit 0
[ -e "/tmp/screenshot-$DATE" ] && u_i="$(printf "${IMGPREFIX}${IMG}\tPNG\n${IMGPREFIX}${IMG}\tURL\n${IMGPREFIX}${IMG}\tSave\n" | $RUNLAUNCHER -l 3 -g 1 $IMGARG -p "Copy to clipboard as:")"
if [ "$x11" = "true" ]; then
if [ "$x11" = "true" ] && [ -x "$(command -v maim)" ]; then
img_clipboard_cmd="xclip -selection clipboard -t image/png"
clipboard_cmd="xclip -selection clipboard"
else