diff --git a/README.md b/README.md index a4efd9f..24039fe 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/screenshot-spmenu b/screenshot-spmenu index 15bc987..18c3e04 100755 --- a/screenshot-spmenu +++ b/screenshot-spmenu @@ -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