From 60b1a627c8e0dbd6aa8e83f17467c72fb262e5bb Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 3 Dec 2020 12:47:37 +0100 Subject: bin/grimshot: various updates * set icon for notify-send * handle null selection * handle OUTPUT --- bin/grimshot | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bin/grimshot b/bin/grimshot index 08ad03d..434c97f 100755 --- a/bin/grimshot +++ b/bin/grimshot @@ -32,8 +32,8 @@ case "$ACTION" in esac notify() { - # notify-send -i "${TMP:-${FILE}}" -t 3000 -a grimshot "$@" - notify-send -i "${TMP:-${FILE}}" -t 3000 "$@" + notify-send -i "${TMP:-${FILE}}" -t 3000 -a grimshot "$@" + # notify-send -i "${TMP:-${FILE}}" -t 3000 "$@" } notifyOk() { TITLE=${2:-"Screenshot"} @@ -43,6 +43,7 @@ notifyOk() { notifyError() { TITLE=${2:-"Screenshot"} MESSAGE=${1:-"Error taking screenshot with grim"} + TMP=/usr/share/icons/Adwaita/scalable/apps/applets-screenshooter-symbolic.svg notify -u critical "$TITLE" "$MESSAGE" } @@ -66,10 +67,13 @@ check() { takeScreenshot() { FILE=$1 GEOM=$2 - if [ -z "$GEOM" ]; then - grim "$FILE" || die "Unable to invoke grim" - else + OUTPUT=$3 + if [ -n "$GEOM" ]; then grim -g "$GEOM" "$FILE" || die "Unable to invoke grim" + elif [ -n "$OUTPUT" ]; then + grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim" + else + grim "$FILE" || die "Unable to invoke grim" fi } @@ -101,6 +105,7 @@ if [ "$ACTION" = "check" ] ; then exit elif [ "$SUBJECT" = "area" ] ; then GEOM=$(slurp -d) + [ -z "$GEOM" ] && die "Selection cancelled" WHAT="Area" elif [ "$SUBJECT" = "win" ] ; then FOCUSED=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?, .floating_nodes[]?) | select(.focused)') @@ -113,19 +118,19 @@ elif [ "$SUBJECT" = "screen" ] ; then elif [ "$SUBJECT" = "output" ] ; then GEOM="" OUTPUT="$(swq current output)" - WHAT="$OUTPUT output" + WHAT="output $OUTPUT" else die "Unknown subject to take a screen shot from" "$SUBJECT" fi if [ "$ACTION" = "copy" ] ; then TMP=$(mktemp) || die "Unable to create temp file: is mktemp installed?" - takeScreenshot "$TMP" "$GEOM" + takeScreenshot "$TMP" "$GEOM" "$OUTPUT" wl-copy --type image/png < "$TMP" || die "Clipboard error" - notifyOk "$WHAT copied to buffer" + notifyOk "$WHAT copied to clipboard" rm "$TMP" elif [ "$ACTION" = "save" ] ; then - takeScreenshot "$FILE" "$GEOM" + takeScreenshot "$FILE" "$GEOM" "$OUTPUT" if [ $? ]; then TITLE="Screenshot of $SUBJECT" MESSAGE=$(basename "$FILE") @@ -139,7 +144,7 @@ elif [ "$ACTION" = "rec" ] ; then FILE=$(xdg-user-dir VIDEOS)/grimshot/$(now).mp4 # create dir if not exists [ -d "$(dirname "$FILE")" ] || mkdir -p "$(dirname "$FILE")" - recordScreen "$FILE" "$GEOM" + recordScreen "$FILE" "$GEOM" "$OUTPUT" wl-copy "$FILE" || die "Clipboard error" if [ $? ]; then TITLE="Screen recording of $SUBJECT" -- cgit 1.4.1