From 49545189ac6ea677babd4d4232516b66f2fb6607 Mon Sep 17 00:00:00 2001 From: Ragnar Groot Koerkamp Date: Thu, 20 May 2021 13:37:26 +0200 Subject: [PATCH] Add `selection` subject option to grimshot This enables selecting a window, output, or area within one invocation. - Drag for an area - Click on a window to select it - Click outside of all windows (e.g. in gaps or on the statusbar) to select the output --- contrib/grimshot | 10 +++++++++- contrib/grimshot.1 | 9 ++++++++- contrib/grimshot.1.scd | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/contrib/grimshot b/contrib/grimshot index 4ce31f29f..900e9a10c 100755 --- a/contrib/grimshot +++ b/contrib/grimshot @@ -32,7 +32,7 @@ FILE=${3:-$(getTargetDirectory)/$(date -Ins).png} if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then echo "Usage:" - echo " grimshot [--notify] (copy|save) [active|screen|output|area|window] [FILE|-]" + echo " grimshot [--notify] (copy|save) [active|screen|output|area|window|selection] [FILE|-]" echo " grimshot check" echo " grimshot usage" echo "" @@ -48,6 +48,7 @@ if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" echo " output: Currently active output." echo " area: Manually select a region." echo " window: Manually select a window." + echo " selection: Manually select an area, window, or output." exit fi @@ -135,6 +136,13 @@ elif [ "$SUBJECT" = "window" ] ; then exit 1 fi WHAT="Window" +elif [ "$SUBJECT" = "selection" ] ; then + GEOM=$(swaymsg -t get_tree | jq -r '.. | select((.pid? and .visible?) or (.type == "output" and .active)) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) + # Check if user exited slurp without selecting the area + if [ -z "$GEOM" ]; then + exit + fi + WHAT="Selection" else die "Unknown subject to take a screen shot from" "$SUBJECT" fi diff --git a/contrib/grimshot.1 b/contrib/grimshot.1 index e4baccfdd..95b435aa9 100644 --- a/contrib/grimshot.1 +++ b/contrib/grimshot.1 @@ -5,7 +5,7 @@ .nh .ad l .\" Begin generated content: -.TH "grimshot" "1" "2021-02-23" +.TH "grimshot" "1" "2021-05-20" .P .SH NAME .P @@ -94,6 +94,13 @@ captures it.\& Captures the currently active output.\& .P .RE +\fIselection\fR +.RS 4 +Allows manually selection a single window (by clicking on it), an output (by +clicking outside of all windows, e.\&g.\& on the status bar), or an area (by +using click and drag).\& +.P +.RE .SH OUTPUT .P Grimshot will print the filename of the captured screenshot to stdout if called diff --git a/contrib/grimshot.1.scd b/contrib/grimshot.1.scd index d2a577599..f650ab9bb 100644 --- a/contrib/grimshot.1.scd +++ b/contrib/grimshot.1.scd @@ -67,6 +67,11 @@ _window_ _output_ Captures the currently active output. +_selection_ + Allows manually selection a single window (by clicking on it), an output (by + clicking outside of all windows, e.g. on the status bar), or an area (by + using click and drag). + # OUTPUT Grimshot will print the filename of the captured screenshot to stdout if called