diff --git a/home/programs/graphical/wms/hyprland/default.nix b/home/programs/graphical/wms/hyprland/default.nix index fac274d..65bbb1c 100644 --- a/home/programs/graphical/wms/hyprland/default.nix +++ b/home/programs/graphical/wms/hyprland/default.nix @@ -18,6 +18,7 @@ in { home.packages = [ hyprPkgs.hyprland-move-window hyprPkgs.hyprland-screenshot + hyprPkgs.quick-record pkgs.brightnessctl pkgs.hyprpicker hyprPkgs.brightness diff --git a/home/programs/graphical/wms/hyprland/packages/default.nix b/home/programs/graphical/wms/hyprland/packages/default.nix index c3d2e3a..2a178f7 100644 --- a/home/programs/graphical/wms/hyprland/packages/default.nix +++ b/home/programs/graphical/wms/hyprland/packages/default.nix @@ -6,6 +6,7 @@ hyprland-move-window = pkgs.callPackage ./hyprland-move-window {}; brightness = pkgs.callPackage ./brightness {}; hyprland-screenshot = pkgs.callPackage ./hyprland-screenshot {}; + quick-record = pkgs.callPackage ./quick-record {}; }; in packages diff --git a/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix b/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix index 06cfe2e..94f27d4 100644 --- a/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix +++ b/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix @@ -1,11 +1,4 @@ # - `grim`: screenshot utility for wayland -# - `slurp`: to select an area -# - `hyprctl`: to read properties of current window -# - `wl-copy`: clipboard utility -# - `jq`: json utility to parse hyprctl output -# - `notify-send`: to show notifications -# - `swappy`: for editing the screenshots (only required for --edit) - {pkgs, ...}: pkgs.writeShellApplication { name = "hyprland-screenshot"; diff --git a/home/programs/graphical/wms/hyprland/packages/quick-record/default.nix b/home/programs/graphical/wms/hyprland/packages/quick-record/default.nix new file mode 100644 index 0000000..7d85224 --- /dev/null +++ b/home/programs/graphical/wms/hyprland/packages/quick-record/default.nix @@ -0,0 +1,16 @@ +{pkgs, ...}: +pkgs.writeShellApplication { + name = "quick-record"; + runtimeInputs = with pkgs; [ + slurp + wl-clipboard + libnotify + procps + killall + wf-recorder + ]; + text = '' + ${builtins.readFile ./quick-record.sh} + ''; +} + diff --git a/home/programs/graphical/wms/hyprland/packages/quick-record/quick-record.sh b/home/programs/graphical/wms/hyprland/packages/quick-record/quick-record.sh new file mode 100644 index 0000000..9e4c751 --- /dev/null +++ b/home/programs/graphical/wms/hyprland/packages/quick-record/quick-record.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +EXTENSION="mp4" +NOTIFY=0 + +save_file() { + wl-copy -t text/uri-list "file://${file}" + [ "$NOTIFY" -eq 1 ] && notify-send -a "quick-record" "Recording saved" "$file " + echo "Recording saved: $file" +} + +stop_recording() { + if pidof -s wf-recorder >/dev/null 2>&1; then + [ "$NOTIFY" -eq 1 ] && notify-send -a "quick-record" "Recording stopped" + killall -s SIGINT wf-recorder + else + >&2 echo "No active recording to stop" + return 1 + fi +} + +start_recording() { + # Remove all previous recordings + # No need to clutter /tmp, since this is used for copying the recording + # as a file, it's unlikely that we'll need any of the old recordings + # when a new one is requested + rm "${TMPDIR:-/tmp}"/wf-recorder-video-*."$EXTENSION" 2>/dev/null || true + + file="$(mktemp -t "wf-recorder-video-XXXXX.$EXTENSION")" + geom="$(slurp)" + + [ "$NOTIFY" -eq 1 ] && notify-send "quick-record" "Recording starting" + + trap save_file SIGINT + trap save_file SIGTERM + trap save_file SIGHUP + + # Wee need 'y' stdin to confirm that we want to override the file + # since mktemp creates a blank file there already + echo "y" | wf-recorder -g "$geom" -f "$file" + + # If wf-recorder process ends directly, rather than a trap being hit + # we also want to run the save_file func + save_file +} + +# Parse any CLI flags first, before getting to positional args +# (As long as we have $2, meaning there's at least 2 args, treat + +# $1 arg as CLI flag``) +while [ "${2-}" ]; do + case "$1" in + -h | --help) + cat </dev/null; then + exit 0 + else + start_recording + fi +else + >&2 echo "Error: No argument provided!" + >&2 echo "Expected one of: start, stop, toggle" + exit 1 +fi