diff options
| author | Patrick Spek <p.spek@tyil.nl> | 2026-05-19 13:59:24 +0200 |
|---|---|---|
| committer | Patrick Spek <p.spek@tyil.nl> | 2026-05-19 13:59:24 +0200 |
| commit | 81b3ca0ea0dc5d361881df3c18a3df47753af926 (patch) | |
| tree | 7e96215ff89d9b9795fac9db00b5de086721409a | |
| parent | a3f71e7f1241924a7c585dab4b977c49faa11da1 (diff) | |
| download | dotfiles-81b3ca0ea0dc5d361881df3c18a3df47753af926.tar.gz dotfiles-81b3ca0ea0dc5d361881df3c18a3df47753af926.tar.bz2 | |
Make screenshot util work on Wayland
The window selection currently has no WM-agnostic way of working.
Perhaps I'll look at it again in the future, for now being able to use
the region is Good Enough.
| -rwxr-xr-x | .local/bin/denv-app-screenshot-region | 33 | ||||
| -rwxr-xr-x | .local/bin/denv-app-screenshot-screen | 34 | ||||
| -rw-r--r-- | .local/lib/dotfiles/main.sh | 18 | ||||
| -rw-r--r-- | .local/share/applications/scrot-region.desktop | 9 | ||||
| -rw-r--r-- | .local/share/applications/scrot-screen.desktop | 9 |
5 files changed, 77 insertions, 26 deletions
diff --git a/.local/bin/denv-app-screenshot-region b/.local/bin/denv-app-screenshot-region index 1d864a7..43d8161 100755 --- a/.local/bin/denv-app-screenshot-region +++ b/.local/bin/denv-app-screenshot-region @@ -3,28 +3,41 @@ . "$HOME/.local/lib/dotfiles/main.sh" main() { - protocol="$(denv-meta-get-protocol)" - output_dir="$HOME/pictures/scrot/$(date +%Y)" + protocol="$("$HOME/.local/bin/denv-meta-get-protocol")" + output_dir="$HOME/pictures/scrot/$(date +%Y)/$(date +%m)" output_file="scrot-$(date +%Y%m%dT%H%M%S)-region.png" + stdout= mkdir -p -- "$output_dir" case "$protocol" in - wayland) main_wayland "$@" ;; - x11) main_x11 "$@" ;; + wayland*) stdout="$(main_wayland "$@" 2>&1)" ;; + x11) stdout="$(main_x11 "$@" 2>&1)" ;; *) - printf "Unknown or unsupported display protocol %s\n" "$protocol" + notify "Screenshot" "Unknown or unsupported display protocol \"%s\"" "$protocol" return 1 esac - notify-send "Screenshot" "Saved screenshot as \"$output_file\"" + exitc=$? + + if [ $exitc -gt 0 ] + then + notify "Screenshot" "Failed screenshot with \"%s\" (%d)" "$stdout" "$exitc" + return 1 + fi + + notify "Screenshot" "Saved screenshot as \"%s\"" "$output_file" } main_wayland() { - hyprshot \ - -m region \ - -o "$output_dir" \ - -f "$output_file" + require "grim" + require "slurp" + + region="$(slurp)" + + grim \ + -g "$region" \ + "$output_dir/$output_file" } main_x11() { diff --git a/.local/bin/denv-app-screenshot-screen b/.local/bin/denv-app-screenshot-screen index da641da..e9a1abd 100755 --- a/.local/bin/denv-app-screenshot-screen +++ b/.local/bin/denv-app-screenshot-screen @@ -3,29 +3,41 @@ . "$HOME/.local/lib/dotfiles/main.sh" main() { - protocol="$(denv-meta-get-protocol)" - output_dir="$HOME/pictures/scrot/$(date +%Y)" + protocol="$("$HOME/.local/bin/denv-meta-get-protocol")" + output_dir="$HOME/pictures/scrot/$(date +%Y)/$(date +%m)" output_file="scrot-$(date +%Y%m%dT%H%M%S)-screen.png" + stdout= mkdir -p -- "$output_dir" case "$protocol" in - wayland) main_wayland "$@" ;; - x11) main_x11 "$@" ;; + wayland*) stdout="$(main_wayland "$@" 2>&1)" ;; + x11) stdout="$(main_x11 "$@" 2>&1)" ;; *) - printf "Unknown or unsupported display protocol %s\n" "$protocol" + notify "Screenshot" "Unknown or unsupported display protocol \"%s\"" "$protocol" return 1 esac - notify-send "Screenshot" "Saved screenshot as \"$output_file\"" + exitc=$? + + if [ $exitc -gt 0 ] + then + notify "Screenshot" "Failed screenshot with \"%s\" (%d)" "$stdout" "$exitc" + return 1 + fi + + notify "Screenshot" "Saved screenshot as \"%s\"" "$output_file" } main_wayland() { - hyprshot \ - -m active \ - -m screen \ - -o "$output_dir" \ - -f "$output_file" + require "grim" + require "slurp" + + region="$(slurp -o -r)" + + grim \ + -g "$region" \ + "$output_dir/$output_file" } main_x11() { diff --git a/.local/lib/dotfiles/main.sh b/.local/lib/dotfiles/main.sh index fb7091f..8145f33 100644 --- a/.local/lib/dotfiles/main.sh +++ b/.local/lib/dotfiles/main.sh @@ -1,17 +1,25 @@ #!/bin/sh +die() { + exit 1 +} + dotfiles_etc() { printf "%s/.local/etc/dotfiles" "$HOME" } +notify() { + DOTFILES_NOTIFY_TITLE=$1 ; shift + DOTFILES_NOTIFY_FORMAT=$1 ; shift + + printf "\033[32m[%s]\033[39m \033[33m%s:\033[39m $DOTFILES_NOTIFY_FORMAT\n" "$(date +%FT%T.%N)" "$DOTFILES_NOTIFY_TITLE" "$@" >&2 + command -v notify-send >/dev/null 2>&1 && notify-send "$DOTFILES_NOTIFY_TITLE" "$(printf "$DOTFILES_NOTIFY_FORMAT" "$@")" +} + require() { if ! command -v "$1" > /dev/null then - printf "%s\n" "$1" >&2 + printf "Required executable missing: %s" "$1" die fi } - -die() { - exit 1 -} diff --git a/.local/share/applications/scrot-region.desktop b/.local/share/applications/scrot-region.desktop new file mode 100644 index 0000000..aef47d0 --- /dev/null +++ b/.local/share/applications/scrot-region.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=Screenshot (region) +Comment=Desktop-agnostic screenshot utility +Exec=/home/tyil/.local/bin/denv-app-screenshot-region +Terminal=true +Type=Application +Keywords=scrot;screenshot; +Icon=applets-screenshooter +StartupNotify=false diff --git a/.local/share/applications/scrot-screen.desktop b/.local/share/applications/scrot-screen.desktop new file mode 100644 index 0000000..1884a07 --- /dev/null +++ b/.local/share/applications/scrot-screen.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=Screenshot (screen) +Comment=Desktop-agnostic screenshot utility +Exec=/home/tyil/.local/bin/denv-app-screenshot-screen +Terminal=true +Type=Application +Keywords=scrot;screenshot; +Icon=applets-screenshooter +StartupNotify=false |
