From 68011d1163d32eead6ee1f3ebbbf1fb7f9c16102 Mon Sep 17 00:00:00 2001 From: jabuxas Date: Tue, 26 Nov 2024 09:05:30 -0300 Subject: [PATCH] feat: add print-window.sh --- .../configs/scripts/scripts/print-window.sh | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 desktop/configs/scripts/scripts/print-window.sh diff --git a/desktop/configs/scripts/scripts/print-window.sh b/desktop/configs/scripts/scripts/print-window.sh new file mode 100755 index 0000000..051e1aa --- /dev/null +++ b/desktop/configs/scripts/scripts/print-window.sh @@ -0,0 +1,30 @@ +#!/bin/bash +swpy_dir="${XDG_CONFIG_HOME:-$HOME/.config}/swappy" +save_dir="$HOME/pics/screenshots" +save_file="screenshot-$(date -Iseconds | cut -d '+' -f1).png" +temp_screenshot="/tmp/screenshot.png" + +mkdir -p $save_dir +mkdir -p $swpy_dir +echo -e "[Default]\nsave_dir=$save_dir\nsave_filename_format=$save_file" > $swpy_dir/config +if [[ $XDG_SESSION_TYPE == "x11" ]]; then + maim -i $(xdotool getactivewindow) | xclip -sel clip -t image/png +fi +if [[ $XDG_SESSION_TYPE == "wayland" ]]; then + if [[ $XDG_CURRENT_DESKTOP == "Hyprland" ]]; then + window_info=$(hyprctl activewindow) + coordinates=$(echo "$window_info" | grep -oP 'at: \K([0-9]+,[0-9]+)') + size=$(echo "$window_info" | grep -oP 'size: \K([0-9]+,[0-9]+)') + IFS=',' read -r x y <<< "$coordinates" + IFS=',' read -r width height <<< "$size" + grim -g "${x},${y} ${width}x${height}" ~/tmp/jabuxas.png + wl-copy < ~/tmp/jabuxas.png + fi + + if [[ $XDG_CURRENT_DESKTOP == "sway" ]]; then + rm $temp_screenshot + grim -g "$(swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" $temp_screenshot + wl-copy < ~/tmp/jabuxas.png + swappy -f $temp_screenshot + fi +fi