55 lines
2.2 KiB
Bash
Executable File
55 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
###
|
|
### ~/.config/hypr/scripts/screenshot/screenshot_monitor.sh
|
|
###
|
|
|
|
time=$(date +%Y-%m-%d-%H%M%S)
|
|
dir="$(xdg-user-dir PICTURES)/Screenshots"
|
|
|
|
monitor=$(hyprctl monitors -j | jq -r '.[] | select(.focused) | .name')
|
|
[ -n "$monitor" ] || exit 1
|
|
|
|
file="Screenshot_${time}_${monitor}.png"
|
|
|
|
mkdir -p "$dir"
|
|
|
|
# Capture the focused monitor, save it and copy to clipboard
|
|
grim -o "$monitor" "$dir/$file" || exit 1
|
|
wl-copy -t image/png < "$dir/$file"
|
|
|
|
if command -v notify-send >/dev/null 2>&1; then
|
|
notify-send --app-name "Screenshot" --icon "camera-photo" -u normal "Monitor" "Screenshot saved $file"
|
|
fi
|
|
|
|
# Open the editor if satty is available (blocks until it is closed).
|
|
# satty writes the annotated image to --output-filename on Ctrl+s (and on
|
|
# Esc/Enter here) and exits immediately. It is launched floating, without
|
|
# decorations, with the pen preselected and moved over the captured area.
|
|
if command -v satty >/dev/null 2>&1; then
|
|
x=$(hyprctl monitors -j | jq -r --arg m "$monitor" '.[] | select(.name == $m) | .x')
|
|
y=$(hyprctl monitors -j | jq -r --arg m "$monitor" '.[] | select(.name == $m) | .y')
|
|
satty --filename "$dir/$file" --output-filename "$dir/$file" \
|
|
--copy-command wl-copy --actions-on-escape save-to-file --early-exit \
|
|
--floating-hack --no-window-decoration --initial-tool brush &
|
|
pid=$!
|
|
for _ in $(seq 1 20); do
|
|
addr=$(hyprctl clients -j 2>/dev/null | jq -r --argjson p "$pid" '.[] | select(.pid == $p) | .address' | head -1)
|
|
[ -n "$addr" ] && break
|
|
sleep 0.1
|
|
done
|
|
if [ -n "$addr" ]; then
|
|
# Lua config (Hyprland 0.55+) dispatches through hl.dsp.*, so try
|
|
# hyprctl eval first, then the raw lua dispatch, then classic syntax.
|
|
hyprctl eval "hl.dispatch(hl.dsp.window.move({ x = $x, y = $y, window = 'address:$addr' }))" >/dev/null 2>&1 ||
|
|
hyprctl dispatch "hl.dsp.window.move({ x = $x, y = $y, window = 'address:$addr' })" >/dev/null 2>&1 ||
|
|
hyprctl dispatch movewindowpixel "exact $x $y,address:$addr" >/dev/null 2>&1
|
|
fi
|
|
wait "$pid"
|
|
wl-copy -t image/png < "$dir/$file"
|
|
fi
|
|
|
|
# Compress the resulting image in the background if oxipng is available
|
|
if command -v oxipng >/dev/null 2>&1; then
|
|
oxipng --strip safe -o 4 "$dir/$file" &
|
|
fi
|