Add an indicator to FreeBSD for when recording is active.

This commit is contained in:
Tom Alexander 2022-11-29 00:15:48 -05:00
parent 019b4184ce
commit 8ea4ca15d8
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 70 additions and 1 deletions

View File

@ -65,6 +65,7 @@ tooltip {
#custom-clock,
#custom-sound,
#custom-temperature,
#custom-recording_indicator,
#idle_inhibitor,
#memory,
#mode,
@ -204,3 +205,7 @@ tooltip {
border-color: #c9545d;
color: #c9545d;
}
#custom-recording_indicator {
color: red;
}

View File

@ -1,6 +1,6 @@
{
// "height": 10, // Waybar height (to be removed for auto height)
"modules-left": ["sway/workspaces", "sway/mode"],
"modules-left": ["sway/workspaces", "sway/mode", "custom/recording_indicator"],
"modules-right": ["custom/temperature", "custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"],
"sway/workspaces": {
"disable-scroll": true
@ -43,5 +43,10 @@
"exec": "waybar_custom_temperature",
"return-type": "json",
"restart-interval": 30
},
"custom/recording_indicator": {
"exec": "waybar_custom_recording_indicator",
"return-type": "json",
"restart-interval": 30
}
}

View File

@ -0,0 +1,57 @@
#!/usr/bin/env bash
#
# Report screen recording status in FreeBSD
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SLEEP_INTERVAL=${SLEEP_INTERVAL:-10}
function main {
local previous_reported="-1"
stream_key_binding_activations | while read -t "$SLEEP_INTERVAL" event; do
if pgrep -q wf-recorder; then
local is_running=1
else
local is_running=0
fi
if [ "$is_running" -ne "$previous_reported" ]; then
previous_reported="$is_running"
report "$is_running"
fi
done
while true; do
sleep $SLEEP_INTERVAL
done
}
function stream_key_binding_activations {
swaymsg --raw --monitor --type subscribe '[ "binding" ]'
}
function report {
is_running="$1"
if [ "$is_running" -eq 0 ]; then
jq --unbuffered --compact-output <<EOF
{
"text":"",
"tooltip":"Not recording",
"percentage":0,
"class":"hidden"
}
EOF
else
jq --unbuffered --compact-output <<EOF
{
"text":"⏺",
"tooltip":"Recording",
"percentage":100,
"class":"visible"
}
EOF
fi
}
main "${@}"

View File

@ -20,3 +20,5 @@
dest: /usr/local/bin/waybar_custom_sound
- src: waybar_temperature_freebsd.bash
dest: /usr/local/bin/waybar_custom_temperature
- src: waybar_recording_indicator_freebsd.bash
dest: /usr/local/bin/waybar_custom_recording_indicator