summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--completions/caelestia.fish12
-rwxr-xr-xmain.fish5
-rwxr-xr-xrecord.fish127
-rwxr-xr-xscreenshot.fish2
4 files changed, 142 insertions, 4 deletions
diff --git a/completions/caelestia.fish b/completions/caelestia.fish
index 93b6462..060d54d 100644
--- a/completions/caelestia.fish
+++ b/completions/caelestia.fish
@@ -1,6 +1,6 @@
set -l seen '__fish_seen_subcommand_from'
set -l has_opt '__fish_contains_opt'
-set -l commands help shell toggle workspace-action scheme screenshot clipboard clipboard-delete emoji-picker wallpaper pip
+set -l commands help shell toggle workspace-action scheme screenshot record clipboard clipboard-delete emoji-picker wallpaper pip
set -l not_seen "not $seen $commands"
# Disable file completions
@@ -13,6 +13,7 @@ complete -c caelestia -n $not_seen -a 'toggle' -d 'Toggle a special workspace'
complete -c caelestia -n $not_seen -a 'workspace-action' -d 'Exec a dispatcher in the current group'
complete -c caelestia -n $not_seen -a 'scheme' -d 'Switch the current colour scheme'
complete -c caelestia -n $not_seen -a 'screenshot' -d 'Take a screenshot'
+complete -c caelestia -n $not_seen -a 'record' -d 'Take a screen recording'
complete -c caelestia -n $not_seen -a 'clipboard' -d 'Open clipboard history'
complete -c caelestia -n $not_seen -a 'clipboard-delete' -d 'Delete from clipboard history'
complete -c caelestia -n $not_seen -a 'emoji-picker' -d 'Open the emoji picker'
@@ -47,6 +48,15 @@ complete -c caelestia -n "$seen workspace-action && not $seen $commands" -a "$co
set -l commands mocha macchiato frappe latte
complete -c caelestia -n "$seen scheme && not $seen $commands" -a "$commands"
+# Record
+set -l not_seen "$seen record && not $has_opt -s h help"
+complete -c caelestia -n "$not_seen && not $has_opt -s s sound && not $has_opt -s r region && not $has_opt -s c compression && not $has_opt -s H hwaccel" \
+ -s 'h' -l 'help' -d 'Show help'
+complete -c caelestia -n "$not_seen && not $has_opt -s s sound" -s 's' -l 'sound' -d 'Capture sound'
+complete -c caelestia -n "$not_seen && not $has_opt -s r region" -s 'r' -l 'region' -d 'Capture region'
+complete -c caelestia -n "$not_seen && not $has_opt -s c compression" -s 'c' -l 'compression' -d 'Compression level of file' -r
+complete -c caelestia -n "$not_seen && not $has_opt -s H hwaccel" -s 'H' -l 'hwaccel' -d 'Use hardware acceleration'
+
# Wallpaper
set -l not_seen "$seen wallpaper && not $has_opt -s h help && not $has_opt -s f file && not $has_opt -s d directory"
complete -c caelestia -n $not_seen -s 'h' -l 'help' -d 'Show help'
diff --git a/main.fish b/main.fish
index f57955b..1cfdf7c 100755
--- a/main.fish
+++ b/main.fish
@@ -37,7 +37,7 @@ if test "$argv[1]" = scheme
exit
end
-set valid_subcommands screenshot clipboard clipboard-delete emoji-picker wallpaper pip
+set valid_subcommands screenshot record clipboard clipboard-delete emoji-picker wallpaper pip
if contains "$argv[1]" $valid_subcommands
./$argv[1].fish $argv[2..]
@@ -48,7 +48,7 @@ test "$argv[1]" != help && error "Unknown command: $argv[1]"
echo 'Usage: caelestia COMMAND [ ...args ]'
echo
-echo 'COMMAND := help | shell | toggle | workspace-action | scheme | screenshot | clipboard | clipboard-delete | emoji-picker | wallpaper | pip'
+echo 'COMMAND := help | shell | toggle | workspace-action | scheme | screenshot | record | clipboard | clipboard-delete | emoji-picker | wallpaper | pip'
echo
echo ' help: show this help message'
echo ' shell: start the shell or message it'
@@ -56,6 +56,7 @@ echo ' toggle: toggle a special workspace'
echo ' workspace-action: execute a Hyprland workspace dispatcher in the current group'
echo ' scheme: change the current colour scheme'
echo ' screenshot: take a screenshot'
+echo ' record: take a screen recording'
echo ' clipboard: open clipboard history'
echo ' clipboard-delete: delete an item from clipboard history'
echo ' emoji-picker: open the emoji picker'
diff --git a/record.fish b/record.fish
new file mode 100755
index 0000000..1463346
--- /dev/null
+++ b/record.fish
@@ -0,0 +1,127 @@
+#!/bin/fish
+
+function get-audio-source
+ pactl list sources | grep 'Name' | grep 'monitor' | cut -d ' ' -f2
+end
+
+function get-active-monitor
+ hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .name'
+end
+
+function has-gpu
+ test -e /dev/dri/renderD128
+end
+
+function supports-codec -a codec
+ ffmpeg -hide_banner -encoders | grep -E '^ V' | grep -F '(codec' | grep $codec >/dev/null
+end
+
+function supports-gpu-codecs
+ supports-codec hevc_vaapi || supports-codec h264_vaapi
+end
+
+argparse -n 'caelestia-record' -X 0 \
+ 'h/help' \
+ 's/sound' \
+ 'r/region=?' \
+ 'c/compression=!_validate_int' \
+ 'H/hwaccel' \
+ -- $argv
+or exit
+
+if set -q _flag_h
+ echo 'Usage:'
+ echo ' caelestia record ( -h | --help )'
+ echo ' caelestia record [ -s | --sound ] [ -r | --region ] [ -c | --compression ] [ -H | --hwaccel ]'
+ echo
+ echo 'Options:'
+ echo ' -h, --help Print this help message and exit'
+ echo ' -s, --sound Enable audio capturing'
+ echo ' -r, --region [ <region> ] The region to capture, current monitor if option not given, default region slurp'
+ echo ' -c, --compression <compression> Use given compression level, lower = better quality, higher = better compression'
+ echo ' -H, --hwaccel Use hardware acceleration if available'
+
+ exit
+end
+
+. (dirname (status filename))/util.fish
+
+set storage_dir (xdg-user-dir VIDEOS)/Recordings
+set cache_dir $CACHE/record
+
+mkdir -p $storage_dir
+mkdir -p $cache_dir
+
+set file_ext 'mp4'
+set recording_path "$cache_dir/recording.$file_ext"
+set notif_id_path "$cache_dir/notifid.txt"
+
+if pgrep wf-recorder > /dev/null
+ pkill wf-recorder
+
+ # Move to recordings folder
+ set -l new_recording_path "$storage_dir/recording_$(date '+%Y%m%d_%H-%M-%S').$file_ext"
+ mv $recording_path $new_recording_path
+
+ # Close start notification
+ if test -f $notif_id_path
+ gdbus call --session \
+ --dest org.freedesktop.Notifications \
+ --object-path /org/freedesktop/Notifications \
+ --method org.freedesktop.Notifications.CloseNotification \
+ (cat $notif_id_path)
+ end
+
+ # Notification with actions
+ set -l action (notify-send 'Recording stopped' "Stopped recording $new_recording_path" -i 'video-x-generic-symbolic' -a 'caelestia-record' \
+ --action='watch=Watch' --action='open=Open' --action='save=Save As')
+
+ switch $action
+ case 'watch'
+ xdg-open $new_recording_path
+ case 'open'
+ dbus-send --session --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"file://$new_recording_path" string:'' \
+ || xdg-open (dirname $new_recording_path)
+ case 'save'
+ set -l save_file (uwsm app -- zenity --file-selection --save --title='Save As')
+ test -n "$save_file" && mv $new_recording_path $save_file || warn 'No file selected'
+ end
+else
+ # Set region if flag given otherwise active monitor
+ if set -q _flag_r
+ # Use given region if value otherwise slurp
+ set region -g (test -n "$_flag_r" && echo $_flag_r || slurp)
+
+ # No hardware encoding when smaller than 256x128 cause unsupported
+ if set -q _flag_H
+ set -l size (echo $region[2] | string split -n -f 2 ' ' | string split x)
+ if test $size[1] -lt 256 -o $size[2] -lt 128
+ warn 'Hardware encoding unsupported below size 256x128. Falling back to software encoding.'
+ set -e _flag_H
+ end
+ end
+ else
+ set region -o (get-active-monitor)
+ end
+
+ # Sound if enabled
+ set -q _flag_s && set audio --audio=(get-audio-source)
+
+ # Codec stuff
+ if set -q _flag_H && has-gpu && supports-gpu-codecs
+ # Hardware encoding (GPU)
+ supports-codec hevc_vaapi && set codec hevc_vaapi || set codec h264_vaapi
+ set -q _flag_c && set compression -p qp=$_flag_c -p rc_mode=CQP
+ set codec_flags -d /dev/dri/renderD128
+ else
+ # Software encoding (CPU)
+ set -q _flag_H && warn 'Unable to use hardware acceleration. Falling back to software encoding.'
+ supports-codec libx265 && set codec libx265 || set codec libx264
+ set -q _flag_c && set compression -p crf=$_flag_c
+ set codec_flags -x yuv420p
+ end
+
+ wf-recorder -c $codec $codec_flags $compression $region $audio -f $recording_path & disown
+
+ notify-send 'Recording started' 'Recording...' -i 'video-x-generic-symbolic' -a 'caelestia-record' -p > $notif_id_path
+end
diff --git a/screenshot.fish b/screenshot.fish
index 1798b3b..bf65b9d 100755
--- a/screenshot.fish
+++ b/screenshot.fish
@@ -7,7 +7,7 @@ set tmp_file "$CACHE/screenshots/$(date +'%Y%m%d%H%M%S')"
grim $argv $tmp_file; and wl-copy < $tmp_file; or exit 1
set action (notify-send -i 'image-x-generic-symbolic' -h "STRING:image-path:$tmp_file" \
- -a (basename (status current-filename)) --action='open=Open' --action='save=Save' \
+ -a 'caelestia-screenshot' --action='open=Open' --action='save=Save' \
'Screenshot taken' "Screenshot stored in $tmp_file and copied to clipboard")
switch $action
case 'open'