65 lines
2.2 KiB
Nix
65 lines
2.2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
util,
|
|
...
|
|
}:
|
|
# Keybound screen recording: pick a region, then toggle a video-only capture.
|
|
let
|
|
# A single key both starts and stops.
|
|
# A running wf-recorder is stopped with SIGINT so it finalises the file.
|
|
# Otherwise slurp picks a region and wf-recorder runs in the foreground until
|
|
# that stop arrives, so this instance lives for the whole recording and then
|
|
# reports it saved.
|
|
# No -a means no audio is captured.
|
|
toggle = pkgs.writeShellScript "screen-record-toggle" ''
|
|
if ${lib.getExe' pkgs.procps "pgrep"} -x wf-recorder >/dev/null; then
|
|
${lib.getExe' pkgs.procps "pkill"} -INT -x wf-recorder
|
|
exit 0
|
|
fi
|
|
|
|
region=$(${lib.getExe pkgs.slurp}) || exit 0
|
|
dir="$(${lib.getExe' pkgs.xdg-user-dirs "xdg-user-dir"} VIDEOS)/Recordings"
|
|
${lib.getExe' pkgs.coreutils "mkdir"} -p "$dir"
|
|
file="$dir/recording-$(${lib.getExe' pkgs.coreutils "date"} +%Y%m%d-%H%M%S).mp4"
|
|
|
|
${lib.getExe' pkgs.libnotify "notify-send"} -a "Screen recording" "Recording started" "Region capture, no audio."
|
|
${lib.getExe pkgs.wf-recorder} -g "$region" -f "$file"
|
|
${lib.getExe' pkgs.libnotify "notify-send"} -a "Screen recording" "Recording saved" "$file"
|
|
'';
|
|
|
|
# Lit while a wf-recorder capture is running.
|
|
# Empty text collapses the widget when idle, so it shows nothing until then.
|
|
recordingStatus = pkgs.writeShellScript "waybar-recording-status" ''
|
|
if ${lib.getExe' pkgs.procps "pgrep"} -x wf-recorder >/dev/null; then
|
|
printf '{"text":"${util.glyph "f03d"}","tooltip":"Recording","class":"recording"}\n'
|
|
else
|
|
printf '{"text":"","class":"idle"}\n'
|
|
fi
|
|
'';
|
|
in
|
|
{
|
|
options.modules.desktop.utilities.recording.enable =
|
|
lib.mkEnableOption "wf-recorder screen recording";
|
|
|
|
config = lib.mkIf config.modules.desktop.utilities.recording.enable {
|
|
registry.keybind.${config.networking.hostName}.recording-toggle = {
|
|
keys = "SUPER + SHIFT + R";
|
|
action = {
|
|
kind = "exec";
|
|
command = "${toggle}";
|
|
};
|
|
};
|
|
|
|
registry.waybar.${config.networking.hostName}."custom/recording" = {
|
|
order = 10;
|
|
settings = {
|
|
return-type = "json";
|
|
exec = "${recordingStatus}";
|
|
interval = 1;
|
|
};
|
|
};
|
|
};
|
|
}
|