Screenshot : Refactor.
This commit is contained in:
parent
9d33afd84f
commit
5b56b00eda
|
@ -9,47 +9,39 @@
|
||||||
pixfmt = "yuv420p10le";
|
pixfmt = "yuv420p10le";
|
||||||
in {
|
in {
|
||||||
text = let
|
text = let
|
||||||
fullscr = pkgs.writeShellScriptBin "FullscreenScreenshot" ''
|
picEdit = ''| swappy -f - -o -'';
|
||||||
scrFile="''${XDG_PICTURES_DIR[0]}/$(date +${format}).png"
|
picFile = ''scrFile="''${XDG_PICTURES_DIR[0]}/$(date +${format}).png"'';
|
||||||
|
picFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -'';
|
||||||
|
picSelect = ''-g "''${scrSelection}" -'';
|
||||||
|
picToBuffer = ''| wl-copy -t image/png'';
|
||||||
|
picToFile = ''| tee "''${scrFile}"'';
|
||||||
|
screenshot = ''grim'';
|
||||||
|
updateWaybar = ''pkill -RTMIN+4 waybar'';
|
||||||
|
vidFile = ''scrFile="''${XDG_VIDEOS_DIR[0]}/$(date +${format}).${container}"'';
|
||||||
|
vidFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -'';
|
||||||
|
vidSelect = ''--geometry "''${scrSelection}"'';
|
||||||
|
vidStop = ''pkill -SIGINT wf-recorder'';
|
||||||
|
|
||||||
grim \
|
getSelection = ''
|
||||||
-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") - \
|
|
||||||
| tee "''${scrFile}" \
|
|
||||||
| wl-copy -t image/png
|
|
||||||
'';
|
|
||||||
|
|
||||||
selectscr = pkgs.writeShellScriptBin "SelectScreenshot" ''
|
|
||||||
scrSelection=$(${selection})
|
scrSelection=$(${selection})
|
||||||
[[ -n "''${scrSelection}" ]] || exit
|
[[ -n "''${scrSelection}" ]] || exit
|
||||||
|
|
||||||
scrFile="''${XDG_PICTURES_DIR[0]}/$(date +${format}).png"
|
|
||||||
|
|
||||||
grim \
|
|
||||||
-g "''${scrSelection}" - \
|
|
||||||
| swappy -f - -o - \
|
|
||||||
| tee "''${scrFile}" \
|
|
||||||
| wl-copy -t image/png
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
selectrec = pkgs.writeShellScriptBin "SelectRecording" ''
|
getTransform = ''
|
||||||
pkill -SIGINT wf-recorder \
|
|
||||||
|| {
|
|
||||||
scrSelection=$(${selection})
|
|
||||||
[[ -n "''${scrSelection}" ]] || exit
|
|
||||||
|
|
||||||
scrFile="''${XDG_VIDEOS_DIR[0]}/$(date +${format}).${container}"
|
|
||||||
|
|
||||||
scrTransform="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .transform')"
|
scrTransform="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .transform')"
|
||||||
[[ "''${scrTransform}" = "normal" ]] && scrTransform=""
|
[[ "''${scrTransform}" = "normal" ]] && scrTransform=""
|
||||||
|
'';
|
||||||
|
|
||||||
pkill -RTMIN+4 waybar \
|
vidStart = ''
|
||||||
& wf-recorder \
|
wf-recorder \
|
||||||
--geometry "''${scrSelection}" \
|
|
||||||
--codec ${codec} \
|
--codec ${codec} \
|
||||||
--file "''${scrFile}" \
|
--file "''${scrFile}" \
|
||||||
--framerate ${toString framerate} \
|
--framerate ${toString framerate} \
|
||||||
--pixel-format ${pixfmt} \
|
--pixel-format ${pixfmt} \
|
||||||
&& ffmpeg \
|
'';
|
||||||
|
|
||||||
|
vidMuxAudio = ''
|
||||||
|
ffmpeg \
|
||||||
-f lavfi \
|
-f lavfi \
|
||||||
-i anullsrc=channel_layout=stereo:sample_rate=44100 \
|
-i anullsrc=channel_layout=stereo:sample_rate=44100 \
|
||||||
-i "''${scrFile}" \
|
-i "''${scrFile}" \
|
||||||
|
@ -59,8 +51,12 @@ in {
|
||||||
-f ${container} \
|
-f ${container} \
|
||||||
"''${scrFile}_" \
|
"''${scrFile}_" \
|
||||||
&& mv "''${scrFile}_" "''${scrFile}" \
|
&& mv "''${scrFile}_" "''${scrFile}" \
|
||||||
&& [[ -n "''${scrTransform}" ]] \
|
|| rm "''${scrFile}_"
|
||||||
&& ffmpeg \
|
'';
|
||||||
|
|
||||||
|
vidTransform = ''
|
||||||
|
if [[ -n "''${scrTransform}" ]]; then
|
||||||
|
ffmpeg \
|
||||||
-display_rotation ''${scrTransform} \
|
-display_rotation ''${scrTransform} \
|
||||||
-i "''${scrFile}" \
|
-i "''${scrFile}" \
|
||||||
-c copy \
|
-c copy \
|
||||||
|
@ -68,59 +64,57 @@ in {
|
||||||
"''${scrFile}_" \
|
"''${scrFile}_" \
|
||||||
&& mv "''${scrFile}_" "''${scrFile}" \
|
&& mv "''${scrFile}_" "''${scrFile}" \
|
||||||
|| rm "''${scrFile}_"
|
|| rm "''${scrFile}_"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
pkill -RTMIN+4 waybar
|
SelectRecording = pkgs.writeShellScriptBin "SelectRecording" ''
|
||||||
|
${vidStop} || {
|
||||||
|
${getSelection}
|
||||||
|
${vidFile}
|
||||||
|
${getTransform}
|
||||||
|
${updateWaybar}
|
||||||
|
${vidStart} ${vidSelect}
|
||||||
|
${vidMuxAudio}
|
||||||
|
${vidTransform}
|
||||||
|
${updateWaybar}
|
||||||
};
|
};
|
||||||
'';
|
'';
|
||||||
|
|
||||||
fullrec = pkgs.writeShellScriptBin "FullscreenRecording" ''
|
FullscreenRecording = pkgs.writeShellScriptBin "FullscreenRecording" ''
|
||||||
pkill -SIGINT wf-recorder \
|
${vidStop} || {
|
||||||
|| {
|
${vidFile}
|
||||||
scrFile="''${XDG_VIDEOS_DIR[0]}/$(date +${format}).${container}"
|
${getTransform}
|
||||||
scrTransform="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .transform')"
|
${updateWaybar}
|
||||||
[[ "''${scrTransform}" = "normal" ]] && scrTransform=""
|
${vidStart} ${vidFull}
|
||||||
|
${vidMuxAudio}
|
||||||
pkill -RTMIN+4 waybar \
|
${vidTransform}
|
||||||
& wf-recorder \
|
${updateWaybar}
|
||||||
-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") - \
|
|
||||||
--codec ${codec} \
|
|
||||||
--file "''${scrFile}" \
|
|
||||||
--framerate ${toString framerate} \
|
|
||||||
--pixel-format ${pixfmt} \
|
|
||||||
&& ffmpeg \
|
|
||||||
-f lavfi \
|
|
||||||
-i anullsrc=channel_layout=stereo:sample_rate=44100 \
|
|
||||||
-i "''${scrFile}" \
|
|
||||||
-c:v copy \
|
|
||||||
-c:a libopus \
|
|
||||||
-shortest \
|
|
||||||
-f ${container} \
|
|
||||||
"''${scrFile}_" \
|
|
||||||
&& mv "''${scrFile}_" "''${scrFile}" \
|
|
||||||
&& [[ -n "''${scrTransform}" ]] \
|
|
||||||
&& ffmpeg \
|
|
||||||
-display_rotation ''${scrTransform} \
|
|
||||||
-i "''${scrFile}" \
|
|
||||||
-c copy \
|
|
||||||
-f ${container} \
|
|
||||||
"''${scrFile}_" \
|
|
||||||
&& mv "''${scrFile}_" "''${scrFile}" \
|
|
||||||
|| rm "''${scrFile}_"
|
|
||||||
|
|
||||||
pkill -RTMIN+4 waybar
|
|
||||||
};
|
};
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" ''
|
||||||
|
${picFile}
|
||||||
|
|
||||||
|
${screenshot} ${picFull} ${picToFile} ${picToBuffer}
|
||||||
|
'';
|
||||||
|
|
||||||
|
SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" ''
|
||||||
|
${getSelection}
|
||||||
|
${picFile}
|
||||||
|
|
||||||
|
${screenshot} ${picSelect} ${picEdit} ${picToFile} ${picToBuffer}
|
||||||
|
'';
|
||||||
in ''
|
in ''
|
||||||
# Fullscreen screenshot.
|
# Fullscreen screenshot.
|
||||||
bindsym --to-code $mod+y exec ${lib.getExe fullscr}
|
bindsym --to-code $mod+y exec ${lib.getExe FullscreenScreenshot}
|
||||||
|
|
||||||
# Fullscreen recording.
|
# Fullscreen recording.
|
||||||
bindsym --to-code $mod+shift+y exec ${lib.getExe fullrec}
|
bindsym --to-code $mod+shift+y exec ${lib.getExe FullscreenRecording}
|
||||||
|
|
||||||
# Select screenshot.
|
# Select screenshot.
|
||||||
bindsym --to-code $mod+v exec ${lib.getExe selectscr}
|
bindsym --to-code $mod+v exec ${lib.getExe SelectScreenshot}
|
||||||
|
|
||||||
# Select recording.
|
# Select recording.
|
||||||
bindsym --to-code $mod+shift+v exec ${lib.getExe selectrec}
|
bindsym --to-code $mod+shift+v exec ${lib.getExe SelectRecording}
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue