diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-06-05 22:22:45 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-06-05 22:22:45 +0530 |
commit | 7437a37e9ae174033e336e5d29f435ec78df27e0 (patch) | |
tree | 6d2a22b17a23b1136649173ed5d487bcbbfdf4ae /home/wayland/pkgs/wayland-scripts | |
parent | 1368cff428c3eb2112afeb53f4756bfdddaff363 (diff) |
home/wayland/pkgs/wayland-scripts/freezshot: init
Diffstat (limited to 'home/wayland/pkgs/wayland-scripts')
-rw-r--r-- | home/wayland/pkgs/wayland-scripts/default.nix | 7 | ||||
-rwxr-xr-x | home/wayland/pkgs/wayland-scripts/src/bin/freezshot | 51 |
2 files changed, 57 insertions, 1 deletions
diff --git a/home/wayland/pkgs/wayland-scripts/default.nix b/home/wayland/pkgs/wayland-scripts/default.nix index bded5e7..c98def5 100644 --- a/home/wayland/pkgs/wayland-scripts/default.nix +++ b/home/wayland/pkgs/wayland-scripts/default.nix @@ -7,11 +7,14 @@ sway, ffmpeg, libnotify, + imv, + grim, + slurp, }: stdenvNoCC.mkDerivation { pname = "wayland-scipts"; - version = "1717572072"; + version = "1717606223"; src = ./src; strictDeps = true; @@ -34,6 +37,8 @@ stdenvNoCC.mkDerivation { postInstall = '' wrapProgram $out/bin/cwall \ --prefix PATH : ${lib.makeBinPath [ ffmpeg libnotify sway ]} + wrapProgram $out/bin/freezshot \ + --prefix PATH : ${lib.makeBinPath [ ffmpeg sway grim slurp imv ]} ''; meta = { diff --git a/home/wayland/pkgs/wayland-scripts/src/bin/freezshot b/home/wayland/pkgs/wayland-scripts/src/bin/freezshot new file mode 100755 index 0000000..a47e9c8 --- /dev/null +++ b/home/wayland/pkgs/wayland-scripts/src/bin/freezshot @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +tmp="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}" +tmp="$(mktemp -d "${tmp}/freezhot.XXXX")" +out="${GRIM_DEFAULT_DIR:-${XDG_PICTURES_DIR:-.}}" + +wl_res() +{ + swaymsg -pt get_outputs | while read -r line; do + case "$line" in + "Current mode"*) + line="${line#*Current mode: }" + echo "${line%% *}" + return + esac + done +} + +######## +# MAIN # +######## + +if [ ! -d "$out" ]; then + mkdir -p "$out" +fi +GRIM_DEFAULT_DIR="$tmp" grim +trap 'rm -r "$tmp"' EXIT +imv -f "$tmp"/* & +view_pid=$! + +region=$(slurp -f '%wx%h %x:%y') > /dev/null 2>&1 +r=$? +kill $view_pid +if [ $r != 0 ]; then + exit 1 +fi + +img="$(ls "$tmp")" +res="${region% *}" +if [ "$res" = "$(wl_res)" ]; then + cp "$tmp/$img" "$out" +else + width=${res%x*} + hight="${res#*x}" + position="${region#* }" + ffmpeg \ + -loglevel quiet \ + -i "$tmp/$img" \ + -vf "crop=$width:$hight:$position" \ + "$out/$img" +fi |