nix/home/config/sway/module/Screenshot.nix

22 lines
1.3 KiB
Nix
Raw Normal View History

2024-08-22 19:13:40 +03:00
{ config, ... }: let
2024-08-22 19:54:20 +03:00
codec = "libsvtav1";
2024-08-22 19:13:40 +03:00
color = config.style.color;
container = "mp4";
2024-08-22 19:54:20 +03:00
format = "%Y-%m-%d_%H-%M-%S";
2024-08-28 03:09:03 +03:00
framerate = 10;
2024-08-22 19:13:40 +03:00
opacity = "26";
selection = "slurp -d -b ${color.bg.light}${opacity} -c ${color.fg.light} -w 0 -s 00000000";
2024-08-22 20:53:39 +03:00
pixfmt = "yuv420p10le";
2024-08-22 19:13:40 +03:00
in {
2024-04-06 03:03:58 +03:00
text = ''
# Fullscreen screenshot.
2024-09-07 04:49:58 +03:00
bindsym --to-code $mod+y exec 'export scrFile="''${XDG_PICTURES_DIR[0]}/$(date +${format}).png"; grim -o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") - | tee "''${scrFile}" | wl-copy -t image/png'
2024-04-06 03:03:58 +03:00
# Select screenshot.
2024-09-07 04:49:58 +03:00
bindsym --to-code $mod+v exec 'export scrFile="''${XDG_PICTURES_DIR[0]}/$(date +${format}).png"; { grim -g "$(${selection})" - || rm "''${scrFile}"; } | tee "''${scrFile}" | wl-copy -t image/png'
2024-08-22 19:13:40 +03:00
# Select recording.
2024-09-07 04:49:58 +03:00
bindsym --to-code $mod+shift+v exec 'pkill -SIGINT wf-recorder || { export scrRecFile="''${XDG_VIDEOS_DIR[0]}/$(date +${format}).${container}"; wf-recorder --geometry "$(${selection})" --codec ${codec} --file "''${scrRecFile}" --framerate ${toString framerate} --pixel-format ${pixfmt} && ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i "''${scrRecFile}" -c:v copy -c:a libopus -shortest -f ${container} "''${scrRecFile}_" && mv "''${scrRecFile}_" "''${scrRecFile}"; }'
2024-04-06 03:03:58 +03:00
'';
}