Skip to content

Commit 5eecdf0

Browse files
eifrdhh
authored andcommitted
feat(waybar): add recording indicator (basecamp#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 <[email protected]>
1 parent 575ace2 commit 5eecdf0

File tree

7 files changed

+58
-25
lines changed

7 files changed

+58
-25
lines changed

bin/omarchy-cmd-screenrecord

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,47 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then
88
exit 1
99
fi
1010

11-
if [[ $2 == "audio" ]]; then
12-
AUDIO="--audio"
13-
else
14-
AUDIO=""
15-
fi
11+
# Selects region or output
12+
SCOPE="$1"
13+
14+
# Selects audio inclusion or not
15+
AUDIO=$([[ $2 == "audio" ]] && echo "--audio")
1616

17-
screenrecording() {
17+
start_screenrecording() {
1818
filename="$OUTPUT_DIR/screenrecording-$(date +'%Y-%m-%d_%H-%M-%S').mp4"
19-
notify-send "Screen recording starting..." -t 1000
20-
sleep 1
2119

2220
if lspci | grep -Eqi 'nvidia|intel.*graphics'; then
23-
wf-recorder $AUDIO -f "$filename" -c libx264 -p crf=23 -p preset=medium -p movflags=+faststart "$@"
21+
wf-recorder $AUDIO -f "$filename" -c libx264 -p crf=23 -p preset=medium -p movflags=+faststart "$@" &
2422
else
25-
wl-screenrec $AUDIO -f "$filename" --ffmpeg-encoder-options="-c:v libx264 -crf 23 -preset medium -movflags +faststart" "$@"
23+
wl-screenrec $AUDIO -f "$filename" --ffmpeg-encoder-options="-c:v libx264 -crf 23 -preset medium -movflags +faststart" "$@" &
2624
fi
25+
26+
toggle_screenrecording_indicator
2727
}
2828

29-
if pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null; then
29+
stop_screenrecording() {
3030
pkill -x wl-screenrec
3131
pkill -x wf-recorder
32+
3233
notify-send "Screen recording saved to $OUTPUT_DIR" -t 2000
33-
elif [[ "$1" == "output" ]]; then
34-
screenrecording
34+
35+
sleep 0.2 # ensures the process is actually dead before we check
36+
toggle_screenrecording_indicator
37+
}
38+
39+
toggle_screenrecording_indicator() {
40+
pkill -RTMIN+8 waybar
41+
}
42+
43+
screenrecording_active() {
44+
pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null
45+
}
46+
47+
if screenrecording_active; then
48+
stop_screenrecording
49+
elif [[ "$SCOPE" == "output" ]]; then
50+
start_screenrecording
3551
else
3652
region=$(slurp) || exit 1
37-
screenrecording -g "$region"
53+
start_screenrecording -g "$region"
3854
fi

bin/omarchy-cmd-screenrecord-stop

Lines changed: 0 additions & 7 deletions
This file was deleted.

config/waybar/config.jsonc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"spacing": 0,
66
"height": 26,
77
"modules-left": ["custom/omarchy", "hyprland/workspaces"],
8-
"modules-center": ["clock", "custom/update"],
8+
"modules-center": ["clock", "custom/update", "custom/screenrecording-indicator"],
99
"modules-right": [
1010
"group/tray-expander",
1111
"bluetooth",
@@ -124,6 +124,12 @@
124124
"format": "",
125125
"tooltip": false
126126
},
127+
"custom/screenrecording-indicator": {
128+
"on-click": "omarchy-cmd-screenrecord",
129+
"exec": "$OMARCHY_PATH/default/waybar/indicators/screen-recording.sh",
130+
"signal": 8,
131+
"return-type": "json"
132+
},
127133
"tray": {
128134
"icon-size": 12,
129135
"spacing": 12

config/waybar/style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#bluetooth,
3838
#pulseaudio,
3939
#custom-omarchy,
40+
#custom-screenrecording-indicator,
4041
#custom-update {
4142
min-width: 12px;
4243
margin: 0 7.5px;
@@ -61,3 +62,13 @@ tooltip {
6162
.hidden {
6263
opacity: 0;
6364
}
65+
66+
#custom-screenrecording-indicator {
67+
min-width: 12px;
68+
margin-left: 8.75px;
69+
font-size: 10px;
70+
}
71+
72+
#custom-screenrecording-indicator.active {
73+
color: #a55555;
74+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
if pgrep -x wl-screenrec >/dev/null || pgrep -x wf-recorder >/dev/null; then
4+
echo '{"text": "󰻂", "tooltip": "Stop recording", "class": "active"}'
5+
else
6+
echo '{"text": ""}'
7+
fi

migrations/1755930114.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ echo "Add new Omarchy Menu icon to Waybar"
33
mkdir -p ~/.local/share/fonts
44
cp ~/.local/share/omarchy/config/omarchy.ttf ~/.local/share/fonts/
55
fc-cache
6-
7-
echo
8-
gum confirm "Replace current Waybar config (backup will be made)?" && omarchy-refresh-waybar

migrations/1757511571.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "Add screen recording indicator to Waybar"
2+
3+
gum confirm "Replace current Waybar config (backup will be made)?" && omarchy-refresh-waybar

0 commit comments

Comments
 (0)