summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-12-03 12:47:37 +0100
committerRobert Günzler <r@gnzler.io>2020-12-03 12:47:37 +0100
commit60b1a627c8e0dbd6aa8e83f17467c72fb262e5bb (patch)
tree35f889cbcdab673770506997ceba22504f6ba33c /bin
parent7013fa78b840b5754dda685ea081994a167e12c6 (diff)
bin/grimshot: various updates
* set icon for notify-send
* handle null selection
* handle OUTPUT
Diffstat (limited to '')
-rwxr-xr-xbin/grimshot25
1 files 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"