From 40083a5db57369332d8122207462eba5b64a1c30 Mon Sep 17 00:00:00 2001 From: ooks-io Date: Mon, 11 Mar 2024 17:28:11 +1300 Subject: [PATCH] feat(hyprrecord): add prototype screen recording script, still needs some work --- .../windowManager/hyprland/default.nix | 3 +- .../windowManager/hyprland/pkgs/default.nix | 1 + .../hyprland/pkgs/hyprrecord/default.nix | 10 ++++ .../hyprland/pkgs/hyprrecord/hyprrecord.sh | 48 +++++++++++++++++++ .../windowManager/hyprland/settings/binds.nix | 3 ++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/default.nix create mode 100755 home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/hyprrecord.sh diff --git a/home/modules/desktop/wayland/windowManager/hyprland/default.nix b/home/modules/desktop/wayland/windowManager/hyprland/default.nix index 8596b0b..1fd2fe6 100644 --- a/home/modules/desktop/wayland/windowManager/hyprland/default.nix +++ b/home/modules/desktop/wayland/windowManager/hyprland/default.nix @@ -1,7 +1,7 @@ { lib, config, pkgs, inputs, ... }: let cfg = config.homeModules.desktop.wayland.windowManager.hyprland; - inherit (import ./pkgs {inherit pkgs;}) hyprbrightness hyprvolume hyprkillsession; + inherit (import ./pkgs {inherit pkgs;}) hyprrecord hyprbrightness hyprvolume hyprkillsession; in { imports = [ @@ -22,6 +22,7 @@ in hyprvolume hyprkillsession hyprbrightness + hyprrecord ]; wayland.windowManager.hyprland = { diff --git a/home/modules/desktop/wayland/windowManager/hyprland/pkgs/default.nix b/home/modules/desktop/wayland/windowManager/hyprland/pkgs/default.nix index f03b479..5098d98 100644 --- a/home/modules/desktop/wayland/windowManager/hyprland/pkgs/default.nix +++ b/home/modules/desktop/wayland/windowManager/hyprland/pkgs/default.nix @@ -4,6 +4,7 @@ let packages = { hyprvolume = pkgs.callPackage ./hyprvolume.nix {}; hyprbrightness = pkgs.callPackage ./hyprbrightness.nix {}; + hyprrecord = pkgs.callPackage ./hyprrecord {}; # Script to help Hyprland quit https://github.com/hyprwm/Hyprland/issues/3558#issuecomment-1848768654 hyprkillsession = pkgs.callPackage ./hyprkillsession.nix {}; }; diff --git a/home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/default.nix b/home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/default.nix new file mode 100644 index 0000000..2b6d270 --- /dev/null +++ b/home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/default.nix @@ -0,0 +1,10 @@ +{ pkgs, ... }: + + +pkgs.writeShellScriptBin "hyprrecord" '' + ${builtins.readFile ./hyprrecord.sh} + '' + + + + diff --git a/home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/hyprrecord.sh b/home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/hyprrecord.sh new file mode 100755 index 0000000..623907a --- /dev/null +++ b/home/modules/desktop/wayland/windowManager/hyprland/pkgs/hyprrecord/hyprrecord.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +getTargetDirectory() { + test -f "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" && + . "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" + echo "${XDG_RECORDINGS_DIR:-${XDG_VIDEOS_DIR:-$HOME}}" +} + +SINK="$(pactl get-default-sink).monitor" +AUDIO="" +FILE="--file=$(getTargetDirectory)/$(date -Ins).mp4" +SET_REGION=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + -a | --audio) + AUDIO="--audio=$SINK" + shift + ;; + -r | --region) + SET_REGION=true + shift + ;; + *) + echo "Unknown parameter passed: $1" + exit 1 + ;; + esac +done + +notify() { + notify-send -t 5000 -a system-notify "$@" +} + +takeRecording() { + if pgrep -x "wf-recorder" >/dev/null; then + pkill -x "wf-recorder" + notify "Recording Stopped" + else + # Only invoke slurp if starting a new recording and the region option was set + if [ "$SET_REGION" = true ]; then + REGION="--geometry=$(slurp)" + fi + wf-recorder "$AUDIO" "$REGION" "$FILE" + fi +} + +echo $(takeRecording) diff --git a/home/modules/desktop/wayland/windowManager/hyprland/settings/binds.nix b/home/modules/desktop/wayland/windowManager/hyprland/settings/binds.nix index da28bc8..5f206c4 100644 --- a/home/modules/desktop/wayland/windowManager/hyprland/settings/binds.nix +++ b/home/modules/desktop/wayland/windowManager/hyprland/settings/binds.nix @@ -42,6 +42,9 @@ in ", Print, exec, grimblast --notify --cursor copysave area" "SUPER, Print, exec, grimblast --notify --cursor copysave screen" + "SUPER, r, exec, hyprrecord -a" + "SUPER CTRL, r, exec, hyprrecord -a -r" + # Brightness