Files
nixos/scripts/WMScripts/screenshot_float.sh
2026-10-06 22:34:05 +02:00

48 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# This script allows the user to make a screenshot (through flameshot)
# and will then open said screenshot from the clipboard into feh
# it will also make the feh window floating
case "$XDG_CURRENT_DESKTOP" in
"Hyprland")
paste="wl-paste -t image/png"
move () {
bash -c "hyprctl dispatch 'hl.dsp.window.move({ x = \"$1\", y = \"$2\", relative = false})'"
}
;;
"sway")
paste="wl-paste -t image/png"
move () {
bash -c "swaymsg move absolute position $1 $2"
}
;;
"i3")
paste="xclip -selection clipboard -t image/png -o"
move () {
bash -c "i3-msg move position $1 $2"
}
;;
*)
dunstify -t 2000 -u low -i ~/.icons/candy-icons/apps/scalable/image-viewer.svg "Current desktop is not supported by floatshot."
exit
;;
esac
out=$(flameshot gui -g)
# If the capture was cancelled, out will be empty
if [[ -n "$out" ]]; then
# get x,y of selection
x=$(echo "$out" | awk -F'+' '{print $2}')
y=$(echo "$out" | awk -F'+' '{print $3}')
bash -c "$paste" | feh - -T notitle --class 'floatme' &
pid="$!"
while [[ -z $(wmctrl -lp | awk -vpid=$pid '$3==pid {print $1; exit}') ]]; do
sleep 0.05
done
move "$x" "$y"
fi