In case when slurp is used to select part of screen or a window, if user aborts
the selection, grimshot will capture the whole screen instead of exiting. This
is fixed with check for empty variable.
(cherry picked from commit c65cd1cffa)
Make notifications a separate flag. Personally, I trigger grimshot
myself most of the time (via sway bindsym) rather than by some external
means, so I don't need to be notified of it happening.
However, keep a flag with this functionality there for those scenarios
there it's necessary to inform the user.
Also print the file location when saving the screenshot.
Show the usage output when an invalid command is received. Otherwise
things like `grimshot --help` save a screenshot, which is really
unexpected and hurts users trying to remember the right commands /
arguments.
Due to the date format used, if several screenshots are taken in
succession, each one overwrote the other.
This change set makes each one have a different name to avoid this.
Also avoid using spaces, since many scripts and tools are unhappy with
file names with spaces.
`$XDG_PICTURES_DIR` is a very loosely defined thing; it's a directory
where "pictures" are stored, which no clearer definition.
Some people use it for photographs they take, other use it for images
they save from the internet, and others use it for screenshots.
Having lots of tools save their output there (anything that's an image
goes there) can easily make it a kitchen sink.
To work around this, use `$XDG_SCREENSHOTS_DIR` as a target directory
for screenshots by default. If not-so-standard variable is unset, fall
back to the previous setting; `$XDG_PICTURES_DIR`.
This also drops an external dependency, which was (a) an overkill (b)
not flexible enough.
Transparency gets reset when the script is terminated.
Added command line option to set transparency strength without changing
the script.
Added support for multiple displays.
The previous behavior was incorrect because `if` was checking the return
status of the `[` command which was never going to be an error. `[`
seems to only return an error if no args are provided. This was
basically a useless use of `[` anyway since it was just meant as a
straight interpretation of command exit, something that `if` can do
itself.
Compare:
```sh
[ ]; echo ?=$?
[ /bin/false ]; echo ?=$?
if [ /bin/false ]; then echo this is the unintended bug; fi
if /bin/false; then echo this will not be printed; fi
```
Usage:
grimshot copy|save win|screen|area [FILE]
Troubleshoot:
grimshot check
Requirements:
- `grim`: screenshot utility for wayland
- `slurp`: to select an area
- `swaymsg`: to read properties of current window
- `wl-copy`: clipboard utility
- `jq`: json uliity to parse swaymsg output
- `notify-send`: to show notifications
Those are needed to be installed, if unsure, run `grimshot check`
Examples:
`grimshot copy win` - to copy current window
`grimshot save area` - to select area and save it to default file (Pictures/Grimshot-$datetime.png)
`grimshot save screen ~/screenshot.png` - to save screenshot under ~/screenshot.png
`grimshot` - usage
`grimshot check` - verify if tools are installed
Sway has ability to apply transparency to arbitrary windows. This script
wires up this functional to one of popular use-cases from
i3+<compositor_name>.
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>