screenshot: rewrite with argc
Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
parent
8b4fd047d9
commit
0a9abef2af
3 changed files with 70 additions and 16 deletions
|
@ -138,10 +138,10 @@ in {
|
|||
(key "Left" "Super" "movewindow" "l")
|
||||
(key "Left" "Super+Shift" "movewindoworgroup" "l")
|
||||
(key "Minus" "Super" "exec" "audio")
|
||||
(key "Print" "Shift" "exec" "screenshot -d")
|
||||
(key "Print" "Super" "exec" "screenshot -e")
|
||||
(key "Print" "Super+Shift" "exec" "screenshot -ed")
|
||||
(key "Print" null "exec" "screenshot")
|
||||
(key "Print" "Shift" "exec" "screenshot display")
|
||||
(key "Print" "Super" "exec" "screenshot selection --edit")
|
||||
(key "Print" "Super+Shift" "exec" "screenshot display --edit")
|
||||
(key "Print" null "exec" "screenshot selection")
|
||||
(key "Return" "Super" "fullscreen" "1") # Maximize
|
||||
(key "Return" "Super+Shift" "fullscreen" "0") # Fullscreen
|
||||
(key "Right" "Super" "movewindow" "r")
|
||||
|
|
|
@ -125,6 +125,7 @@ in {
|
|||
power-profiles-daemon
|
||||
])
|
||||
(bash "screenshot" [
|
||||
argc
|
||||
coreutils
|
||||
grimblast
|
||||
imagemagick
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
# Screenshot region or display with rounded corners
|
||||
# @describe Wrapper for screenshot tools
|
||||
#
|
||||
# https://github.com/sigoden/argc
|
||||
# https://github.com/hyprwm/contrib/tree/main/grimblast
|
||||
# https://github.com/jtheoof/swappy
|
||||
|
||||
r=20 # Radius
|
||||
# @meta combine-shorts
|
||||
# @meta inherit-flag-options
|
||||
# @flag -e --edit Edit screenshot with swappy
|
||||
# @flag -nc --no-copy Do not copy to clipboard after capturing
|
||||
# @flag -nf --no-freeze Do not freeze display before capturing
|
||||
|
||||
# TODO: May not be needed for rounded corners on Hyprland
|
||||
_round() {
|
||||
r=20 # Radius
|
||||
|
||||
function round() {
|
||||
magick - \
|
||||
\( +clone -alpha extract -draw "fill black polygon 0,0 0,$r $r,0 fill white circle $r,$r $r,0" \
|
||||
\( +clone -flip \) -compose Multiply -composite \
|
||||
|
@ -12,12 +23,54 @@ function round() {
|
|||
-alpha off -compose CopyOpacity -composite -
|
||||
}
|
||||
|
||||
# TODO: Use proper flags
|
||||
# TODO: Add clipboard support
|
||||
if [[ "${1-}" == '-e' ]]; then
|
||||
grimblast --freeze save area - | swappy --file -
|
||||
elif [[ "${1-}" == '-d' ]]; then
|
||||
grimblast --freeze save output - > "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').png"
|
||||
else
|
||||
grimblast --freeze save area - > "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').png"
|
||||
fi
|
||||
_capture() {
|
||||
# Build arguments in array
|
||||
command=(grimblast)
|
||||
|
||||
if [[ ! "${argc_no_freeze:-}" ]]; then
|
||||
command+=(--freeze)
|
||||
fi
|
||||
|
||||
# Always save
|
||||
if [[ ! "${argc_no_copy:-}" ]]; then
|
||||
command+=(copysave "$1")
|
||||
else
|
||||
command+=(save "$1")
|
||||
fi
|
||||
|
||||
command+=("${argc_file:-}")
|
||||
|
||||
"${command[@]}"
|
||||
|
||||
# Edit after first capture
|
||||
if [[ "${argc_edit:-}" ]]; then
|
||||
swappy --file "${argc_file:-}" --output-file "${argc_file_edit:-}"
|
||||
fi
|
||||
}
|
||||
|
||||
_default_file() {
|
||||
echo "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').png" # 1970-01-01 00-00-00.png
|
||||
}
|
||||
|
||||
_default_file_edit() {
|
||||
echo "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').edit.png" # 1970-01-01 00-00-00.edit.png
|
||||
}
|
||||
|
||||
# @cmd Screenshot entire display
|
||||
# @alias d,di,dis,disp,displ,displa,o,ou,out,outp,outpu,output
|
||||
# @arg file=`_default_file` <FILE> File to save screenshot as, defaults to "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').png"
|
||||
# @arg file_edit=`_default_file_edit` <FILE> File to save edited screenshot as with swappy, defaults to "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').edit.png"
|
||||
display() {
|
||||
_capture output
|
||||
}
|
||||
|
||||
# @cmd Screenshot selected area
|
||||
# @meta default-subcommand
|
||||
# @alias s,se,sel,sele,selec,select,selecti,selectio,a,ar,are,area
|
||||
# @arg file=`_default_file` <FILE> File to save screenshot as, defaults to "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').png"
|
||||
# @arg file_edit=`_default_file_edit` <FILE> File to save edited screenshot as with swappy, defaults to "$XDG_SCREENSHOTS_DIR/$(date +'%F %H-%M-%S').edit.png"
|
||||
selection() {
|
||||
_capture area
|
||||
}
|
||||
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
|
Loading…
Reference in a new issue