Guanran Wang
f1b0d66756
- rename script `wrapped-slurp` to `wrapped-grim` - add keybinds to sway in `home.nix` - remove needed environment variables on hyprland in `autostart.conf` - remove unneeded fcitx5 autostart in `autostart.conf` and `home.nix` - remove `hyprland.bak` - remove tabs in `main.conf`
56 lines
1.7 KiB
Bash
Executable file
56 lines
1.7 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# Original script based on some early version of https://github.com/moverest/sway-interactive-screenshot
|
|
# modified for use with key bindings. For now supports sway & Hyprland.
|
|
|
|
SWAY=$(echo "$SWAYSOCK")
|
|
HYPR=$(echo "$HYPRLAND_INSTANCE_SIGNATURE")
|
|
if [[ -n "$SWAY" && -n "$HYPR" ]]; then
|
|
echo "This script only works on sway or Hyprland, terminating.";
|
|
exit 1
|
|
fi
|
|
|
|
list_geometry()
|
|
{
|
|
swaymsg -t get_tree | jq -r '.. | try select(.'"$1"' and .pid) | "\(.rect.x),\(.rect.y) \(.rect.width)x\(.rect.height)''"'
|
|
}
|
|
|
|
list_geometry_hypr()
|
|
{
|
|
hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])''"'
|
|
}
|
|
|
|
CHOICE=$1
|
|
EDIT=$2
|
|
DIR=${SCREENSHOT_DIR:=~/Pictures/Screenshots}
|
|
|
|
mkdir -p "$DIR"
|
|
|
|
if [[ -n "$SWAY" ]]; then
|
|
FOCUSED=$(list_geometry focused)
|
|
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_sway_screenshot.png')"
|
|
case $CHOICE in
|
|
fullscreen) grim "$FILENAME" ;;
|
|
region) grim -g "$(slurp)" "$FILENAME" ;;
|
|
focused) grim -g "$FOCUSED" "$FILENAME" ;;
|
|
display) grim -o "$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')" "$FILENAME" ;;
|
|
esac
|
|
fi
|
|
|
|
if [[ -n "$HYPR" ]]; then
|
|
FOCUSED=$(list_geometry_hypr)
|
|
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_hypr_screenshot.png')"
|
|
case $CHOICE in
|
|
fullscreen) grim "$FILENAME" ;;
|
|
region) grim -g "$(slurp)" "$FILENAME" ;;
|
|
focused) grim -g "$FOCUSED" "$FILENAME" ;;
|
|
display) grim -o "$(hyprctl -j monitors | jq -r '.[] | select(.focused) | .name')" "$FILENAME" ;;
|
|
esac
|
|
fi
|
|
|
|
wl-copy < "$FILENAME"
|
|
notify-send "Screenshot" "File saved as <i>'$FILENAME'</i> and copied to the clipboard." -i "$FILENAME"
|
|
|
|
if [[ "$EDIT" = "edit" ]]; then
|
|
swappy -f "$FILENAME"
|
|
fi
|