From 3d97448fee0e8bd1c3f4d54f4fbbdeab3f689633 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 4 Jun 2025 22:45:42 +0300 Subject: [PATCH] Write a script for selecting screenshot modes --- .config/sway/config | 4 +-- .local/bin/take-screenshot | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 .local/bin/take-screenshot diff --git a/.config/sway/config b/.config/sway/config index 8539f13..2cb286b 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -243,8 +243,8 @@ bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5% # Screenshots # -bindsym Print exec grim ~/Photos/screenshots/$(date +'fullscreen-%Y%m%dT%H%M%S.png') -bindsym Shift+Print exec grim -g "$(slurp)" ~/Photos/screenshots/$(date +'selection-%Y%m%dT%H%M%S.png') +bindsym Print exec take-screenshot everything +bindsym Shift+Print exec take-screenshot # # Start a password manager in the scratchpad diff --git a/.local/bin/take-screenshot b/.local/bin/take-screenshot new file mode 100755 index 0000000..43cbcf5 --- /dev/null +++ b/.local/bin/take-screenshot @@ -0,0 +1,55 @@ +#! /usr/bin/sh + +listopts() { + echo "Focused monitor" + echo "Focused monitor → 📋" + echo "Select region" + echo "Select region → 📋" + echo "Focused window" + echo "Focused window → 📋" + echo "Select window" + echo "Select window → 📋" +} + +gen_filename() { + echo ~/Photos/screenshots/$(date +'screenshot-%Y%m%dT%H%M%S.png') +} + +if [ -z "$1" ]; then + option=$(listopts | fuzzel --dmenu) +else + option="$1" +fi + +get_focused_monitor() { + swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name' +} + +get_focused_window() { + swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"' +} + +select_window() { + swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp +} + +case "${option}" in + "everything") + grim "$(gen_filename)";; + "Focused monitor") + grim -o "$(get_focused_monitor)" "$(gen_filename)";; + "Focused monitor → 📋") + grim -o "$(get_focused_monitor)" - | wl-copy;; + "Select region") + grim -g "$(slurp)" "$(gen_filename)";; + "Select region → 📋") + grim -g "$(slurp)" - | wl-copy;; + "Focused window") + grim -g "$(get_focused_window)" "$(gen_filename)";; + "Focused window → 📋") + grim -g "$(get_focused_window)" - | wl-copy;; + "Select window") + grim -g "$(select_window)" "$(gen_filename)";; + "Select window → 📋") + grim -g "$(select_window)" - | wl-copy;; +esac