Screenshot : Add Latest ref file for easy edit.

This commit is contained in:
Dmitry Voronin 2024-09-14 22:38:04 +03:00
parent 6ca438ed37
commit 7451477d06
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k

View file

@ -9,16 +9,20 @@
pixfmt = "yuv420p10le"; pixfmt = "yuv420p10le";
in { in {
text = let text = let
picEdit = ''| swappy -f - -o -''; picEdit = ''swappy -f - -o -'';
picFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; picFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -'';
picSelected = ''-g "''${scrSelection}" -''; picPrepFile = prepFile "\${XDG_PICTURES_DIR[0]}" "png";
picToBuffer = ''| wl-copy -t image/png''; picRefLatestFile = refLatestFile "png";
picToFile = ''| tee "''${scrFile}"''; picSelected = ''-g "''${scrSelection}" -'';
screenshot = ''grim''; picToBuffer = ''wl-copy -t image/png'';
updateWaybar = ''pkill -RTMIN+4 waybar''; picToFile = ''tee "''${scrFile}"'';
vidFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; screenshot = ''grim'';
vidSelected = ''--geometry "''${scrSelection}"''; updateWaybar = ''pkill -RTMIN+4 waybar'';
vidStop = ''pkill -SIGINT wf-recorder''; vidFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -'';
vidPrepFile = prepFile "\${XDG_VIDEOS_DIR[0]}" container;
vidRefLatestFile = refLatestFile container;
vidSelected = ''--geometry "''${scrSelection}"'';
vidStop = ''pkill -SIGINT wf-recorder'';
prepFile = path: ext: '' prepFile = path: ext: ''
# Focused app id by default. # Focused app id by default.
@ -28,16 +32,22 @@ in {
[[ "''${curWindow}" = "null" ]] && curWindow=$(parse_snake $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .name')) [[ "''${curWindow}" = "null" ]] && curWindow=$(parse_snake $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .name'))
# If no app in focus, use "unknown" dir. # If no app in focus, use "unknown" dir.
[[ "''${curWindow}" -eq "''${curWindow}" ]] && curWindow="unknown" [[ "''${curWindow}" =~ ^[0-9]+$ ]] && curWindow="unknown"
# Prepare dir and file path. # Prepare dir and file path.
scrPath="${path}"
scrDir="${path}/''${curWindow}" scrDir="${path}/''${curWindow}"
mkdir -p "''${scrDir}" mkdir -p "''${scrDir}"
scrFile="''${scrDir}/$(date +${format}).${ext}" scrName="$(date +${format}).${ext}"
scrFile="''${scrDir}/''${scrName}"
scrLatestRef="./''${curWindow}/''${scrName}"
''; '';
vidPrepFile = prepFile "\${XDG_VIDEOS_DIR[0]}" container; refLatestFile = ext: ''
picPrepFile = prepFile "\${XDG_PICTURES_DIR[0]}" "png"; scrLatest="''${scrPath}/Latest.${ext}"
rm "''${scrLatest}"
ln -s "''${scrLatestRef}" "''${scrLatest}"
'';
getSelection = '' getSelection = ''
scrSelection=$(${selection}) scrSelection=$(${selection})
@ -93,6 +103,7 @@ in {
${vidStart} ${vidSelected} ${vidStart} ${vidSelected}
${vidMuxAudio} ${vidMuxAudio}
${vidTransform} ${vidTransform}
${vidRefLatestFile}
${updateWaybar} ${updateWaybar}
}; };
''; '';
@ -105,6 +116,7 @@ in {
${vidStart} ${vidFull} ${vidStart} ${vidFull}
${vidMuxAudio} ${vidMuxAudio}
${vidTransform} ${vidTransform}
${vidRefLatestFile}
${updateWaybar} ${updateWaybar}
}; };
''; '';
@ -112,14 +124,14 @@ in {
FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" '' FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" ''
${picPrepFile} ${picPrepFile}
${screenshot} ${picFull} ${picToFile} ${picToBuffer} ${screenshot} ${picFull} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile}
''; '';
SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" '' SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" ''
${getSelection} ${getSelection}
${picPrepFile} ${picPrepFile}
${screenshot} ${picSelected} ${picEdit} ${picToFile} ${picToBuffer} ${screenshot} ${picSelected} | ${picEdit} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile}
''; '';
in '' in ''
bindsym --to-code $mod+y exec ${lib.getExe FullscreenScreenshot} bindsym --to-code $mod+y exec ${lib.getExe FullscreenScreenshot}