From d5dfbe16ee4103ca20a8b11cde5d70f27d954f58 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 20 Jun 2025 13:12:12 +0200 Subject: [PATCH] adds screen recording script and shortcut --- .config/hypr/config/keybinds.conf | 4 +- .config/hypr/scripts/record-or-screenshot.sh | 176 +++++++++++++++++++ 2 files changed, 179 insertions(+), 1 deletion(-) create mode 100755 .config/hypr/scripts/record-or-screenshot.sh diff --git a/.config/hypr/config/keybinds.conf b/.config/hypr/config/keybinds.conf index 82a26e1..17b57ca 100644 --- a/.config/hypr/config/keybinds.conf +++ b/.config/hypr/config/keybinds.conf @@ -141,7 +141,7 @@ bindd = $mainMod, slash, Switch to the previous workspace, workspace, previous bindd = $mainMod, minus, Move active window to Special workspace, movetoworkspace,special bindd = $mainMod, equal, Toggles the Special workspace, togglespecialworkspace, special bindd = $mainMod, F1, Call special workspace scratchpad, togglespecialworkspace, scratchpad -bindd = $mainMod ALT SHIFT, F1, Move active window to special workspace scratchpad, movetoworkspacesilent, special:scratchpad +bindd = $mainMod ALT SHIFT, F1, Move active window to s~/.config/hypr/scripts/pecial workspace scratchpad, movetoworkspacesilent, special:scratchpad # ======= Screenshot ======= # Screenshot a window @@ -150,6 +150,8 @@ bind = $mainMod, PRINT, exec, hyprshot -m window bind = , PRINT, exec, hyprshot -m output # Screenshot a region bind = $shiftMod, PRINT, exec, hyprshot -m region +# Screenrec +bind = $mainMod, S, exec, ~/.config/hypr/scripts/record-or-screenshot.sh # ======= Additional Settings ======= diff --git a/.config/hypr/scripts/record-or-screenshot.sh b/.config/hypr/scripts/record-or-screenshot.sh new file mode 100755 index 0000000..a9f8574 --- /dev/null +++ b/.config/hypr/scripts/record-or-screenshot.sh @@ -0,0 +1,176 @@ +#!/bin/env bash + +# Menu launcher wrapper +menu_prompt() { + if command -v tofi &>/dev/null; then + printf "%b" "$1" | tofi --prompt-text="$2" + elif command -v fuzzel &>/dev/null; then + printf "%b" "$1" | fuzzel -d -p "$2" -w 25 -l 10 + elif command -v wofi &>/dev/null; then + printf "%b" "$1" | wofi --dmenu --prompt="$2" + elif command -v rofi &>/dev/null; then + printf "%b" "$1" | rofi -dmenu -p "$2" + else + notify-send "No compatible launcher found" "Install tofi, fuzzel, wofi, or rofi." + exit 1 + fi +} + +# Directories +SCREENSHOT_DIR="${HOME}/Pictures" +RECORDING_DIR="${HOME}/Videos" + +# Ensure directories exist +mkdir -p "$SCREENSHOT_DIR" "$RECORDING_DIR" + +# Stop active wl-screenrec session +if pgrep -u "$USER" wl-screenrec > /dev/null; then + pkill -INT -u "$USER" wl-screenrec + notify-send "Recording stopped" + + # Ask if user wants to compress the video + COMPRESS=$(menu_prompt "āœ… compress\nāŒ keep original" "šŸ—œļø Compress video?") + if [[ "$COMPRESS" == "āœ… compress" ]]; then + # Find the most recent video file + LATEST_VIDEO=$(find "$RECORDING_DIR" -name "*.mp4" -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-) + if [[ -n "$LATEST_VIDEO" ]] && [[ -f "$LATEST_VIDEO" ]]; then + COMPRESSED_VIDEO="${LATEST_VIDEO%.mp4}_compressed.mp4" + notify-send "Compressing video..." "This may take a moment" + if ffmpeg -i "$LATEST_VIDEO" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k "$COMPRESSED_VIDEO" -y &>/dev/null; then + notify-send "Compression complete" "$COMPRESSED_VIDEO" + # Ask if user wants to delete original + DELETE_ORIGINAL=$(menu_prompt "šŸ—‘ļø delete original\nšŸ“ keep both" "Delete original?") + if [[ "$DELETE_ORIGINAL" == "šŸ—‘ļø delete original" ]]; then + rm "$LATEST_VIDEO" + notify-send "Original deleted" "Keeping compressed version only" + fi + else + notify-send "Compression failed" "Keeping original file" + fi + fi + fi + exit 0 +fi + +# Get current outputs dynamically +OUTPUTS=$(hyprctl monitors | grep "Monitor" | awk '{print $2}' | paste -sd " " -) + +OPTIONS=$( + cat <