diff --git a/share/dotfiles/.config/hypr/conf/keybindings/default.conf b/share/dotfiles/.config/hypr/conf/keybindings/default.conf index 5eb97dd7f..3cf1825e9 100644 --- a/share/dotfiles/.config/hypr/conf/keybindings/default.conf +++ b/share/dotfiles/.config/hypr/conf/keybindings/default.conf @@ -46,6 +46,7 @@ binde = ALT,Tab,bringactivetotop bind = $mainMod CTRL, R, exec, hyprctl reload # Reload Hyprland configuration bind = $mainMod SHIFT, A, exec, $HYPRSCRIPTS/toggle-animations.sh # Toggle animations bind = $mainMod, PRINT, exec, $HYPRSCRIPTS/screenshot.sh # Take a screenshot +bind = $mainMod, R, exec, $HYPRSCRIPTS/screen_record.sh # Record the screen bind = $mainMod SHIFT, S, exec, $HYPRSCRIPTS/screenshot.sh # Take a screenshot bind = $mainMod CTRL, Q, exec, ~/.config/ml4w/scripts/wlogout.sh # Start wlogout bind = $mainMod SHIFT, W, exec, waypaper --random # Change the wallpaper diff --git a/share/dotfiles/.config/hypr/scripts/screen_record.sh b/share/dotfiles/.config/hypr/scripts/screen_record.sh new file mode 100755 index 000000000..73ab437de --- /dev/null +++ b/share/dotfiles/.config/hypr/scripts/screen_record.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +# Get the user's video directory based on system settings +DIR="$(xdg-user-dir VIDEOS)" + +# Create the directory if it does not exist +if [[ ! -d "$DIR" ]]; then + mkdir -p "$DIR" +fi + +# Temporary file to store the recording filename +TEMP_FILE="/tmp/wf-recorder-filename" + +# Function to stop recording and compress the video +cleanup() { + if pgrep -x "wf-recorder" > /dev/null; then + pkill --signal SIGINT wf-recorder + notify-send "šŸ“¹ Recording stopped" + + # Wait to ensure the file is completely saved + sleep 2 + + # Retrieve the filename from the temporary file + if [[ -f "$TEMP_FILE" ]]; then + MKV_FILE=$(cat "$TEMP_FILE") + MP4_FILE="${MKV_FILE%.mkv}.mp4" + else + notify-send "āŒ Error" "Recording file not found!" + exit 1 + fi + + # Ensure the recorded file exists before proceeding + if [[ -f "$MKV_FILE" ]]; then + notify-send "šŸ“¦ Compressing video..." "Please wait..." + ffmpeg -i "$MKV_FILE" -c:v libx264 -preset fast -crf 28 -pix_fmt yuv420p -threads $(nproc) -y "$MP4_FILE" && { + notify-send "āœ… Recording saved!" "File: $MP4_FILE" + echo "āœ” Video saved: $MP4_FILE" + wl-copy < "$MP4_FILE" + + # šŸ”„ Remove the temporary MKV file after compression + rm -f "$MKV_FILE" + } + else + notify-send "āŒ Error" "Recording file not found!" + fi + fi + exit 0 +} + +# Capture Ctrl+C (SIGINT) and call the stop function +trap cleanup SIGINT + +# If already recording, show menu to stop it +if pgrep -x "wf-recorder" > /dev/null; then + SELECTION=$(echo -e "ā¹ Stop Recording" | rofi -dmenu -replace -config ~/.config/rofi/config-screenshot.rasi -i -no-show-icons -l 1 -width 30 -p "šŸ“¹ Recording in progress") + if [[ "$SELECTION" == "ā¹ Stop Recording" ]]; then + cleanup + else + exit 0 + fi +fi + +# Show rofi menu to choose recording mode +SELECTION=$(echo -e "šŸŽ„ Record Active Window\nšŸŽ„ Record Selection" | rofi -dmenu -replace -config ~/.config/rofi/config-screenshot.rasi -i -no-show-icons -l 2 -width 30 -p "šŸ“¹ Choose recording mode") + +case "$SELECTION" in + "šŸŽ„ Record Active Window") + MKV_FILE="$DIR/recording_$(date +'%Y-%m-%d_%H-%M-%S').mkv" + echo "$MKV_FILE" > "$TEMP_FILE" # Save the filename temporarily + wf-recorder -g "$(hyprctl activewindow -j | jq -r '.at[0], .at[1], .size[0], .size[1]' | paste -sd ' ')" -f "$MKV_FILE" & + notify-send "šŸ“¹ Recording Active Window" "Press '$mainMod + Shift + R' to stop." + ;; + "šŸŽ„ Record Selection") + MKV_FILE="$DIR/recording_$(date +'%Y-%m-%d_%H-%M-%S').mkv" + echo "$MKV_FILE" > "$TEMP_FILE" # Save the filename temporarily + wf-recorder -g "$(slurp)" -f "$MKV_FILE" & + notify-send "šŸ“¹ Recording Selection" "Press '$mainMod + Shift + R' to stop." + ;; + *) + notify-send "āŒ Canceled" "No action was selected." + exit 1 + ;; +esac +