Skip to content

Commit

Permalink
close #32
Browse files Browse the repository at this point in the history
  • Loading branch information
ProMix0 committed Feb 25, 2024
1 parent 36dbe2e commit 840b2a1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions hyprshot
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function send_notification() {
}

function trim() {
Print "Geometry: %s\n" "${1}"
local geometry="${1}"
local xy_str=$(echo "${geometry}" | cut -d' ' -f1)
local wh_str=$(echo "${geometry}" | cut -d' ' -f2)
Expand Down Expand Up @@ -93,32 +94,32 @@ function trim() {
cropped_height=$((cropped_height + y))
fi

printf "%s,%s %sx%s\n" \
local cropped=`printf "%s,%s %sx%s\n" \
"${cropped_x}" "${cropped_y}" \
"${cropped_width}" "${cropped_height}"
"${cropped_width}" "${cropped_height}"`
Print "Crop: %s\n" "${cropped}"
echo ${cropped}
}

function save_geometry() {
Print "Geometry: %s\n" "${1}"
local cropped_geometry=`trim "${1}"`
Print "Crop: %s\n" "${cropped_geometry}"
local geometry="${1}"
local output=""

if [ $RAW -eq 1 ]; then
grim -g "${cropped_geometry}" -
grim -g "${geometry}" -
return 0
fi

if [ $CLIPBOARD -eq 0 ]; then
mkdir -p "$SAVEDIR"
grim -g "${cropped_geometry}" "$SAVE_FULLPATH"
grim -g "${geometry}" "$SAVE_FULLPATH"
output="$SAVE_FULLPATH"
wl-copy < "$output"
[ -z "$COMMAND" ] || {
"$COMMAND" "$output"
}
else
wl-copy < <(grim -g "${cropped_geometry}" -)
wl-copy < <(grim -g "${geometry}" -)
fi

send_notification $output
Expand All @@ -145,6 +146,7 @@ function begin_grab() {
else
local geometry=`grab_window`
fi
geometry=`trim "${geometry}"`
;;
esac
save_geometry "${geometry}"
Expand Down Expand Up @@ -181,14 +183,14 @@ function grab_window() {
Print "Clients: %s\n" "$clients"
# Generate boxes for each visible window and send that to slurp
# through stdin
local boxes="$(echo $clients | jq -r '.[] | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1]) \(.title)"')"
local boxes="$(echo $clients | jq -r '.[] | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1]) \(.title)"' | cut -f1,2 -d' ')"
Print "Boxes:\n%s\n" "$boxes"
slurp -r <<< "$boxes"
}

function grab_active_window() {
local active_window=`hyprctl -j activewindow`
local box=$(echo $active_window | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')
local box=$(echo $active_window | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | cut -f1,2 -d' ')
Print "Box:\n%s\n" "$box"
echo "$box"
}
Expand Down

0 comments on commit 840b2a1

Please sign in to comment.