feat(capture): screen recording — menu start, bar-click stop (item 12)
All checks were successful
Check / eval (push) Successful in 2m56s
All checks were successful
Check / eval (push) Successful in 2m56s
nomarchy-record owns the lifecycle: start prefers wl-screenrec (VAAPI hardware encode) and falls back to wf-recorder if it dies at startup (the no-VAAPI case), stop SIGINTs so the file finalizes cleanly, and status feeds a self-gating Waybar ⏺ REC (alert red) whose click is the one stop surface — signal 8 pokes make it appear/vanish instantly. Capture gains Record region/screen (+ audio variants) and self-swaps to '■ Stop recording' while one runs. Parity: both summer whole-swap bars carry the same module. Recordings land in ~/Videos/Recordings with the screenshot timestamp naming (deviation from 'next to Screenshots': an .mp4 in Pictures felt wrong). V1: rendered bar config + CSS asserted, summer jsonc parse, recorder dry-run state machine correct (idle/active/usage exits), both recorders in home-path. Real capture needs a session → V3 queued (incl. the VAAPI-vs-fallback check on the AMD box). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
./fastfetch.nix # system info with the themed Nomarchy logo
|
||||
./viewers.nix # zathura (Stylix-themed) + imv — PDF/image viewing
|
||||
./mime.nix # default applications (mimeapps.list), degrades with the suite
|
||||
./recording.nix # nomarchy-record: screen recording behind Capture + the bar ⏺
|
||||
];
|
||||
|
||||
# Clipboard history (wl-paste watcher); browsed via the SUPER+CTRL+V
|
||||
|
||||
99
modules/home/recording.nix
Normal file
99
modules/home/recording.nix
Normal file
@@ -0,0 +1,99 @@
|
||||
# Screen recording (menu › Tools › Capture). One helper owns the whole
|
||||
# lifecycle: `start` launches wl-screenrec (VAAPI hardware encode) and
|
||||
# falls back to wf-recorder (software x264) if it dies on the spot —
|
||||
# e.g. no usable VAAPI device; `status` feeds the self-gating Waybar
|
||||
# indicator (waybar.nix, signal 8), whose click is the ONE stop surface
|
||||
# (`stop` SIGINTs the recorder so it finalizes the file cleanly). State
|
||||
# is a runtime pidfile — nothing persists across sessions.
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
lib.mkIf config.nomarchy.rofi.enable {
|
||||
home.packages = [
|
||||
pkgs.wl-screenrec
|
||||
pkgs.wf-recorder
|
||||
|
||||
(pkgs.writeShellScriptBin "nomarchy-record" ''
|
||||
run="''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
|
||||
pidfile="$run/nomarchy-record.pid"
|
||||
filefile="$run/nomarchy-record.file"
|
||||
|
||||
alive() { [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; }
|
||||
poke_bar() { pkill -RTMIN+8 waybar 2>/dev/null || true; }
|
||||
|
||||
case "''${1:-}" in
|
||||
start)
|
||||
if alive; then
|
||||
notify-send "Screen recording" "Already recording — stop it via the ⏺ in the bar."
|
||||
exit 1
|
||||
fi
|
||||
target="''${2:-screen}"; audio="''${3:-}"
|
||||
geo=""
|
||||
if [ "$target" = region ]; then
|
||||
geo=$(slurp) || exit 0 # Esc in slurp = cancel, silently
|
||||
fi
|
||||
dir="$HOME/Videos/Recordings"
|
||||
mkdir -p "$dir"
|
||||
file="$dir/$(date +%Y%m%d-%H%M%S).mp4"
|
||||
|
||||
launch() { # launch <recorder> -> 0 if it survived startup
|
||||
case "$1" in
|
||||
wl-screenrec)
|
||||
setsid wl-screenrec ''${geo:+-g "$geo"} \
|
||||
''${audio:+--audio} -f "$file" >/dev/null 2>&1 & ;;
|
||||
wf-recorder)
|
||||
setsid wf-recorder ''${geo:+-g "$geo"} \
|
||||
''${audio:+-a} -f "$file" >/dev/null 2>&1 & ;;
|
||||
esac
|
||||
echo $! > "$pidfile"
|
||||
sleep 0.7
|
||||
alive
|
||||
}
|
||||
|
||||
started=""
|
||||
if command -v wl-screenrec >/dev/null 2>&1 && launch wl-screenrec; then
|
||||
started=wl-screenrec
|
||||
elif command -v wf-recorder >/dev/null 2>&1 && launch wf-recorder; then
|
||||
started=wf-recorder # software fallback (no VAAPI device)
|
||||
fi
|
||||
if [ -z "$started" ]; then
|
||||
rm -f "$pidfile"
|
||||
notify-send "Screen recording" "Recorder failed to start (no wl-screenrec/wf-recorder able to run)."
|
||||
exit 1
|
||||
fi
|
||||
printf '%s' "$file" > "$filefile"
|
||||
poke_bar
|
||||
notify-send "Screen recording" "Recording ($started)''${audio:+ with audio} — click the ⏺ in the bar to stop." ;;
|
||||
|
||||
stop)
|
||||
if ! alive; then
|
||||
rm -f "$pidfile" "$filefile"; poke_bar
|
||||
notify-send "Screen recording" "No recording is running."
|
||||
exit 0
|
||||
fi
|
||||
pid=$(cat "$pidfile")
|
||||
kill -INT "$pid" 2>/dev/null # graceful: both recorders finalize on INT
|
||||
for _ in $(seq 1 50); do kill -0 "$pid" 2>/dev/null || break; sleep 0.1; done
|
||||
kill -0 "$pid" 2>/dev/null && kill "$pid" 2>/dev/null
|
||||
file=$(cat "$filefile" 2>/dev/null || echo "?")
|
||||
rm -f "$pidfile" "$filefile"
|
||||
poke_bar
|
||||
notify-send "Screen recording saved" "$file" ;;
|
||||
|
||||
active)
|
||||
alive ;;
|
||||
|
||||
status)
|
||||
# Waybar JSON while recording; nothing => module hidden.
|
||||
if alive; then
|
||||
file=$(cat "$filefile" 2>/dev/null || echo "")
|
||||
printf '{"text":"⏺ REC","class":"recording","tooltip":"Recording to %s — click to stop"}\n' "''${file##*/}"
|
||||
fi
|
||||
exit 0 ;;
|
||||
|
||||
*)
|
||||
echo "usage: nomarchy-record start [region|screen] [audio] | stop | active | status" >&2
|
||||
exit 2 ;;
|
||||
esac
|
||||
'')
|
||||
];
|
||||
}
|
||||
@@ -341,11 +341,23 @@ ${themeRows}
|
||||
fi ;;
|
||||
|
||||
capture)
|
||||
# Screenshots + screen recording. Recording rows self-swap: while
|
||||
# one runs, the only offer is Stop (same surface as the bar's ⏺).
|
||||
choice=$( {
|
||||
row "Region → clipboard" applets-screenshooter
|
||||
row "Region → file" applets-screenshooter
|
||||
row "Full screen → clipboard" camera-photo
|
||||
row "Full screen → file" camera-photo
|
||||
if command -v nomarchy-record >/dev/null 2>&1; then
|
||||
if nomarchy-record active; then
|
||||
row "■ Stop recording" media-playback-stop
|
||||
else
|
||||
row "Record region" media-record
|
||||
row "Record screen" media-record
|
||||
row "Record region + audio" audio-input-microphone
|
||||
row "Record screen + audio" audio-input-microphone
|
||||
fi
|
||||
fi
|
||||
back
|
||||
} | rofi -dmenu -show-icons -p Capture) || exit 0
|
||||
dir="$HOME/Pictures/Screenshots"
|
||||
@@ -358,6 +370,11 @@ ${themeRows}
|
||||
*"Full screen → clipboard"*) grim - | wl-copy ;;
|
||||
*"Full screen → file"*) mkdir -p "$dir"; grim "$file" \
|
||||
&& notify-send "Screenshot saved" "$file" ;;
|
||||
*"Stop recording"*) exec nomarchy-record stop ;;
|
||||
*"Record region + audio"*) exec nomarchy-record start region audio ;;
|
||||
*"Record screen + audio"*) exec nomarchy-record start screen audio ;;
|
||||
*"Record region"*) exec nomarchy-record start region ;;
|
||||
*"Record screen"*) exec nomarchy-record start screen ;;
|
||||
esac ;;
|
||||
|
||||
keybinds)
|
||||
|
||||
@@ -121,7 +121,7 @@ let
|
||||
|
||||
modules-left = [ "hyprland/workspaces" "hyprland/window" ];
|
||||
modules-center = [ "clock" ];
|
||||
modules-right = [ "tray" "custom/vpn" "pulseaudio" "cpu" "memory" "custom/powerprofile" "custom/nightlight" ]
|
||||
modules-right = [ "custom/recording" "tray" "custom/vpn" "pulseaudio" "cpu" "memory" "custom/powerprofile" "custom/nightlight" ]
|
||||
++ lib.optional showLanguage "hyprland/language"
|
||||
++ [ "battery" "custom/updates" "custom/notification" ];
|
||||
|
||||
@@ -184,6 +184,19 @@ let
|
||||
on-click = "nomarchy-vpn";
|
||||
};
|
||||
|
||||
# Screen recording indicator. Self-gates: visible only while
|
||||
# nomarchy-record runs (status prints nothing otherwise), and the
|
||||
# click IS the stop surface — the menu only starts recordings.
|
||||
# signal 8: the recorder pokes the bar on start/stop so the ⏺
|
||||
# appears/vanishes instantly (the interval is just a safety net).
|
||||
"custom/recording" = {
|
||||
exec = "nomarchy-record status";
|
||||
return-type = "json";
|
||||
interval = 10;
|
||||
signal = 8;
|
||||
on-click = "nomarchy-record stop";
|
||||
};
|
||||
|
||||
# Night-light (hyprsunset) indicator. Self-gates: the moon shows only while
|
||||
# the schedule runs; otherwise the status helper prints nothing => hidden
|
||||
# (enable / re-enable from the System menu). Click toggles instantly — writes
|
||||
@@ -283,11 +296,14 @@ let
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#tray, #pulseaudio, #cpu, #memory, #custom-powerprofile, #custom-nightlight, #custom-updates, #custom-vpn, #language, #battery, #custom-notification {
|
||||
#tray, #pulseaudio, #cpu, #memory, #custom-powerprofile, #custom-nightlight, #custom-updates, #custom-vpn, #custom-recording, #language, #battery, #custom-notification {
|
||||
color: alpha(@text, 0.85);
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
/* Recording in progress → the alert red; the ⏺ is also the stop button. */
|
||||
#custom-recording.recording { color: @bad; }
|
||||
|
||||
/* VPN active → accent green, reading as "connected / protected". */
|
||||
#custom-vpn.on { color: @good; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user