From 24ceb6c14f37f54977ff9c9c9defd27e974df429 Mon Sep 17 00:00:00 2001 From: Gustavo Parreira Date: Thu, 10 Nov 2022 15:03:33 +0000 Subject: [PATCH] refactor: generating boxes for windows instead of selecting single pixel --- hyprshot | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hyprshot b/hyprshot index 1faaa20..76f049b 100755 --- a/hyprshot +++ b/hyprshot @@ -66,17 +66,12 @@ function begin_grab() { } function grab_window() { - # SELECTION is an array where the first element is the - # selected x coordinate and the second element is the - # selected y coordinate. - local selection=(`slurp -pf "%x %y" 2>/dev/null`) - - [ -z $selection ] && exit 1; - - local x=${selection[0]} - local y=${selection[1]} - local client=`hyprctl -j clients | jq -r '[.[] | select(.workspace.id | contains('$(hyprctl -j monitors | jq -r 'map(.activeWorkspace.id) | join(",")')')) | select(.at[0] <= '$x' and '$x' <= .at[0] + .size[0] and .at[1] <= '$y' and '$y' <= .at[1] + .size[1])] | last'` - echo $client | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' + local clients=`hyprctl -j clients | jq -r '[.[] | select(.workspace.id | contains('$(hyprctl -j monitors | jq -r 'map(.activeWorkspace.id) | join(",")')'))] | reverse'` + # 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])"')" + Print "Boxes:\n%s\n" "$boxes" + slurp -r <<< "$boxes" 2>/dev/null } function args() {