aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alice Carroll <git@alice-carroll.pet>2022-03-31 19:28:16 +0300
committerLibravatar Simon Ser <contact@emersion.fr>2022-04-21 10:41:48 +0200
commita5f01a0e04642cf035e5ae416e7bc631988e30a6 (patch)
treebded23c78c91734e17a91f80ae3ee1b6946aa848
parentAdd Swedish README (diff)
downloadsway-a5f01a0e04642cf035e5ae416e7bc631988e30a6.tar.gz
sway-a5f01a0e04642cf035e5ae416e7bc631988e30a6.tar.zst
sway-a5f01a0e04642cf035e5ae416e7bc631988e30a6.zip
Support cursor capture in grimshot
Refactor argument parser Bring back `sh` compatibility Default to NOTIFY=no
-rwxr-xr-xcontrib/grimshot46
-rw-r--r--contrib/grimshot.113
-rw-r--r--contrib/grimshot.1.scd5
3 files changed, 43 insertions, 21 deletions
diff --git a/contrib/grimshot b/contrib/grimshot
index 4ce31f29..d42fe9d8 100755
--- a/contrib/grimshot
+++ b/contrib/grimshot
@@ -13,18 +13,32 @@
13## See `man 1 grimshot` or `grimshot usage` for further details. 13## See `man 1 grimshot` or `grimshot usage` for further details.
14 14
15getTargetDirectory() { 15getTargetDirectory() {
16 test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && \ 16 test -f "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs" && \
17 . ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs 17 . "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs"
18 18
19 echo ${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}} 19 echo "${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}"
20} 20}
21 21
22if [ "$1" = "--notify" ]; then 22NOTIFY=no
23 NOTIFY=yes 23CURSOR=
24 shift 1 24
25else 25while [ $# -gt 0 ]; do
26 NOTIFY=no 26 key="$1"
27fi 27
28 case $key in
29 -n|--notify)
30 NOTIFY=yes
31 shift # past argument
32 ;;
33 -c|--cursor)
34 CURSOR=yes
35 shift # past argument
36 ;;
37 *) # unknown option
38 break # done with parsing --flags
39 ;;
40 esac
41done
28 42
29ACTION=${1:-usage} 43ACTION=${1:-usage}
30SUBJECT=${2:-screen} 44SUBJECT=${2:-screen}
@@ -32,7 +46,7 @@ FILE=${3:-$(getTargetDirectory)/$(date -Ins).png}
32 46
33if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then 47if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then
34 echo "Usage:" 48 echo "Usage:"
35 echo " grimshot [--notify] (copy|save) [active|screen|output|area|window] [FILE|-]" 49 echo " grimshot [--notify] [--cursor] (copy|save) [active|screen|output|area|window] [FILE|-]"
36 echo " grimshot check" 50 echo " grimshot check"
37 echo " grimshot usage" 51 echo " grimshot usage"
38 echo "" 52 echo ""
@@ -67,7 +81,7 @@ notifyError() {
67 MESSAGE=${1:-"Error taking screenshot with grim"} 81 MESSAGE=${1:-"Error taking screenshot with grim"}
68 notify -u critical "$TITLE" "$MESSAGE" 82 notify -u critical "$TITLE" "$MESSAGE"
69 else 83 else
70 echo $1 84 echo "$1"
71 fi 85 fi
72} 86}
73 87
@@ -91,12 +105,12 @@ takeScreenshot() {
91 FILE=$1 105 FILE=$1
92 GEOM=$2 106 GEOM=$2
93 OUTPUT=$3 107 OUTPUT=$3
94 if [ ! -z "$OUTPUT" ]; then 108 if [ -n "$OUTPUT" ]; then
95 grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim" 109 grim ${CURSOR:+-c} -o "$OUTPUT" "$FILE" || die "Unable to invoke grim"
96 elif [ -z "$GEOM" ]; then 110 elif [ -z "$GEOM" ]; then
97 grim "$FILE" || die "Unable to invoke grim" 111 grim ${CURSOR:+-c} "$FILE" || die "Unable to invoke grim"
98 else 112 else
99 grim -g "$GEOM" "$FILE" || die "Unable to invoke grim" 113 grim ${CURSOR:+-c} -g "$GEOM" "$FILE" || die "Unable to invoke grim"
100 fi 114 fi
101} 115}
102 116
@@ -147,7 +161,7 @@ else
147 TITLE="Screenshot of $SUBJECT" 161 TITLE="Screenshot of $SUBJECT"
148 MESSAGE=$(basename "$FILE") 162 MESSAGE=$(basename "$FILE")
149 notifyOk "$MESSAGE" "$TITLE" 163 notifyOk "$MESSAGE" "$TITLE"
150 echo $FILE 164 echo "$FILE"
151 else 165 else
152 notifyError "Error taking screenshot with grim" 166 notifyError "Error taking screenshot with grim"
153 fi 167 fi
diff --git a/contrib/grimshot.1 b/contrib/grimshot.1
index e4baccfd..2c4c6a95 100644
--- a/contrib/grimshot.1
+++ b/contrib/grimshot.1
@@ -1,11 +1,11 @@
1.\" Generated by scdoc 1.11.1 1.\" Generated by scdoc 1.11.2
2.\" Complete documentation for this program is not available as a GNU info page 2.\" Complete documentation for this program is not available as a GNU info page
3.ie \n(.g .ds Aq \(aq 3.ie \n(.g .ds Aq \(aq
4.el .ds Aq ' 4.el .ds Aq '
5.nh 5.nh
6.ad l 6.ad l
7.\" Begin generated content: 7.\" Begin generated content:
8.TH "grimshot" "1" "2021-02-23" 8.TH "grimshot" "1" "2022-03-31"
9.P 9.P
10.SH NAME 10.SH NAME
11.P 11.P
@@ -13,7 +13,7 @@ grimshot - a helper for screenshots within sway
13.P 13.P
14.SH SYNOPSIS 14.SH SYNOPSIS
15.P 15.P
16\fBgrimshot\fR [--notify] (copy|save) [TARGET] [FILE] 16\fBgrimshot\fR [--notify] [--cursor] (copy|save) [TARGET] [FILE]
17.br 17.br
18\fBgrimshot\fR check 18\fBgrimshot\fR check
19.br 19.br
@@ -26,12 +26,17 @@ grimshot - a helper for screenshots within sway
26Show notifications to the user that a screenshot has been taken.\& 26Show notifications to the user that a screenshot has been taken.\&
27.P 27.P
28.RE 28.RE
29\fB--cursor\fR
30.RS 4
31Include cursors in the screenshot.\&
32.P
33.RE
29\fBsave\fR 34\fBsave\fR
30.RS 4 35.RS 4
31Save the screenshot into a regular file.\& Grimshot will write images 36Save the screenshot into a regular file.\& Grimshot will write images
32files to \fBXDG_SCREENSHOTS_DIR\fR if this is set (or defined 37files to \fBXDG_SCREENSHOTS_DIR\fR if this is set (or defined
33in \fBuser-dirs.\&dir\fR), or otherwise fall back to \fBXDG_PICTURES_DIR\fR.\& 38in \fBuser-dirs.\&dir\fR), or otherwise fall back to \fBXDG_PICTURES_DIR\fR.\&
34Set FILE to '-' to pipe the output to STDOUT.\& 39Set FILE to '\&-'\& to pipe the output to STDOUT.\&
35.P 40.P
36.RE 41.RE
37\fBcopy\fR 42\fBcopy\fR
diff --git a/contrib/grimshot.1.scd b/contrib/grimshot.1.scd
index d2a57759..ccdce2c1 100644
--- a/contrib/grimshot.1.scd
+++ b/contrib/grimshot.1.scd
@@ -6,7 +6,7 @@ grimshot - a helper for screenshots within sway
6 6
7# SYNOPSIS 7# SYNOPSIS
8 8
9*grimshot* [--notify] (copy|save) [TARGET] [FILE]++ 9*grimshot* [--notify] [--cursor] (copy|save) [TARGET] [FILE]++
10*grimshot* check++ 10*grimshot* check++
11*grimshot* usage 11*grimshot* usage
12 12
@@ -15,6 +15,9 @@ grimshot - a helper for screenshots within sway
15*--notify* 15*--notify*
16 Show notifications to the user that a screenshot has been taken. 16 Show notifications to the user that a screenshot has been taken.
17 17
18*--cursor*
19 Include cursors in the screenshot.
20
18*save* 21*save*
19 Save the screenshot into a regular file. Grimshot will write images 22 Save the screenshot into a regular file. Grimshot will write images
20 files to *XDG_SCREENSHOTS_DIR* if this is set (or defined 23 files to *XDG_SCREENSHOTS_DIR* if this is set (or defined