From a57060ee31e4b2e48ad47fa26454ff478b122fd6 Mon Sep 17 00:00:00 2001 From: Ofir Levitan Date: Wed, 10 Sep 2025 16:48:55 +0300 Subject: [PATCH] feat(waybar): add recording indicator (#1561) * init * remove comment format * add pulse animation * change to signals * Move file to an internal location, match signal with what's being sent * Need to sleep a second to ensure that the recording has either started or stopped before we render config * Put it in a more prominent place * Use OMARCHY_PATH * Sharpen icons and add on-click to stop * Drop animation but reserve space * Lean entirely on waybar indicator rather than notification when starting * Use an explaining function instead of comments * Give time to ensure the process is dead before updating the indicator * No longer needed * Don't need to repeat the on-click * Don't need a full second * Naming * SIRGTMIN shouldn't be here * Don't need any of this that isn't seen or used * Explain the sleep * Mirror start/stop functions * Go all-in on explaining functions * Inline audio toggle * Better just to move the clock rather than have it be permanently offset * Fix all parameters and name them * Add migration * There is now a later omarchy-refresh-waybar offer --------- Co-authored-by: David Heinemeier Hansson --- bin/omarchy-cmd-screenrecord | 44 +++++++++++++------ bin/omarchy-cmd-screenrecord-stop | 7 --- config/waybar/config.jsonc | 8 +++- config/waybar/style.css | 11 +++++ default/waybar/indicators/screen-recording.sh | 7 +++ migrations/1755930114.sh | 3 -- migrations/1757511571.sh | 3 ++ 7 files changed, 58 insertions(+), 25 deletions(-) delete mode 100755 bin/omarchy-cmd-screenrecord-stop create mode 100755 default/waybar/indicators/screen-recording.sh create mode 100644 migrations/1757511571.sh diff --git a/bin/omarchy-cmd-screenrecord b/bin/omarchy-cmd-screenrecord index f9a604b..570fb58 100755 --- a/bin/omarchy-cmd-screenrecord +++ b/bin/omarchy-cmd-screenrecord @@ -8,31 +8,47 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then exit 1 fi -if [[ $2 == "audio" ]]; then - AUDIO="--audio" -else - AUDIO="" -fi +# Selects region or output +SCOPE="$1" -screenrecording() { +# Selects audio inclusion or not +AUDIO=$([[ $2 == "audio" ]] && echo "--audio") + +start_screenrecording() { filename="$OUTPUT_DIR/screenrecording-$(date +'%Y-%m-%d_%H-%M-%S').mp4" - notify-send "Screen recording starting..." -t 1000 - sleep 1 if lspci | grep -Eqi 'nvidia|intel.*graphics'; then - wf-recorder $AUDIO -f "$filename" -c libx264 -p crf=23 -p preset=medium -p movflags=+faststart "$@" + wf-recorder $AUDIO -f "$filename" -c libx264 -p crf=23 -p preset=medium -p movflags=+faststart "$@" & else - wl-screenrec $AUDIO -f "$filename" --ffmpeg-encoder-options="-c:v libx264 -crf 23 -preset medium -movflags +faststart" "$@" + wl-screenrec $AUDIO -f "$filename" --ffmpeg-encoder-options="-c:v libx264 -crf 23 -preset medium -movflags +faststart" "$@" & fi + + toggle_screenrecording_indicator } -if pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null; then +stop_screenrecording() { pkill -x wl-screenrec pkill -x wf-recorder + notify-send "Screen recording saved to $OUTPUT_DIR" -t 2000 -elif [[ "$1" == "output" ]]; then - screenrecording + + sleep 0.2 # ensures the process is actually dead before we check + toggle_screenrecording_indicator +} + +toggle_screenrecording_indicator() { + pkill -RTMIN+8 waybar +} + +screenrecording_active() { + pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null +} + +if screenrecording_active; then + stop_screenrecording +elif [[ "$SCOPE" == "output" ]]; then + start_screenrecording else region=$(slurp) || exit 1 - screenrecording -g "$region" + start_screenrecording -g "$region" fi diff --git a/bin/omarchy-cmd-screenrecord-stop b/bin/omarchy-cmd-screenrecord-stop deleted file mode 100755 index 5631920..0000000 --- a/bin/omarchy-cmd-screenrecord-stop +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -if pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null; then - pkill -x wl-screenrec - pkill -x wf-recorder - notify-send "Screen recording stopped" -t 2000 -fi diff --git a/config/waybar/config.jsonc b/config/waybar/config.jsonc index 0ec9af4..f93a161 100644 --- a/config/waybar/config.jsonc +++ b/config/waybar/config.jsonc @@ -5,7 +5,7 @@ "spacing": 0, "height": 26, "modules-left": ["custom/omarchy", "hyprland/workspaces"], - "modules-center": ["clock", "custom/update"], + "modules-center": ["clock", "custom/update", "custom/screenrecording-indicator"], "modules-right": [ "group/tray-expander", "bluetooth", @@ -124,6 +124,12 @@ "format": " ", "tooltip": false }, + "custom/screenrecording-indicator": { + "on-click": "omarchy-cmd-screenrecord", + "exec": "$OMARCHY_PATH/default/waybar/indicators/screen-recording.sh", + "signal": 8, + "return-type": "json" + }, "tray": { "icon-size": 12, "spacing": 12 diff --git a/config/waybar/style.css b/config/waybar/style.css index 924e185..2cf371b 100644 --- a/config/waybar/style.css +++ b/config/waybar/style.css @@ -37,6 +37,7 @@ #bluetooth, #pulseaudio, #custom-omarchy, +#custom-screenrecording-indicator, #custom-update { min-width: 12px; margin: 0 7.5px; @@ -61,3 +62,13 @@ tooltip { .hidden { opacity: 0; } + +#custom-screenrecording-indicator { + min-width: 12px; + margin-left: 8.75px; + font-size: 10px; +} + +#custom-screenrecording-indicator.active { + color: #a55555; +} diff --git a/default/waybar/indicators/screen-recording.sh b/default/waybar/indicators/screen-recording.sh new file mode 100755 index 0000000..d0d0082 --- /dev/null +++ b/default/waybar/indicators/screen-recording.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null; then + echo '{"text": "󰻂", "tooltip": "Stop recording", "class": "active"}' +else + echo '{"text": ""}' +fi diff --git a/migrations/1755930114.sh b/migrations/1755930114.sh index 90d44e5..fd491d6 100644 --- a/migrations/1755930114.sh +++ b/migrations/1755930114.sh @@ -3,6 +3,3 @@ echo "Add new Omarchy Menu icon to Waybar" mkdir -p ~/.local/share/fonts cp ~/.local/share/omarchy/config/omarchy.ttf ~/.local/share/fonts/ fc-cache - -echo -gum confirm "Replace current Waybar config (backup will be made)?" && omarchy-refresh-waybar diff --git a/migrations/1757511571.sh b/migrations/1757511571.sh new file mode 100644 index 0000000..7753a28 --- /dev/null +++ b/migrations/1757511571.sh @@ -0,0 +1,3 @@ +echo "Add screen recording indicator to Waybar" + +gum confirm "Replace current Waybar config (backup will be made)?" && omarchy-refresh-waybar