From 4df06b6d77e13c38825879b5f7e1b4de89b5af2f Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 18 Sep 2025 11:13:53 +0200 Subject: [PATCH] feat(waybar): improve screen recorder module --- .config/sway/scripts/screen-recorder.sh | 10 +++++++++- .config/waybar/config.jsonc | 18 ++++++++++-------- .config/waybar/hyprland.jsonc | 18 ++++++++++-------- .../waybar/scripts/check-screen-recorder.sh | 15 +++++++++++++++ .config/waybar/style.css | 15 +++++++++++---- 5 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 .config/waybar/scripts/check-screen-recorder.sh diff --git a/.config/sway/scripts/screen-recorder.sh b/.config/sway/scripts/screen-recorder.sh index 0dbea51..9ec214f 100755 --- a/.config/sway/scripts/screen-recorder.sh +++ b/.config/sway/scripts/screen-recorder.sh @@ -1,5 +1,9 @@ #! /usr/bin/env bash +toggle_screenrecording() { + pkill -RTMIN+8 waybar +} + main() { pid="$(pgrep "wf-recorder" || pgrep "slurp")" status=$? @@ -17,10 +21,14 @@ main() { fi filename="$output_dir/$(date +'recording_%Y-%m-%d-%H%M%S.mp4')" + region="$(slurp)" - region="$(slurp)" && wf-recorder -g "$region" -f "$filename" + wf-recorder -g "$region" -f "$filename" & + + toggle_screenrecording else pkill --signal SIGINT wf-recorder + toggle_screenrecording fi } diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index 1278954..9d51c9b 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -9,7 +9,6 @@ "modules-center": ["clock"], "modules-right": [ "custom/pacman", - "custom/recorder", "privacy", "group/system", "group/misc", @@ -21,7 +20,13 @@ }, "group/misc": { "orientation": "inherit", - "modules": ["pulseaudio", "pulseaudio#microphone", "backlight", "battery"] + "modules": [ + "pulseaudio", + "pulseaudio#microphone", + "backlight", + "battery", + "custom/recorder" + ] }, "group/connections": { "orientation": "inherit", @@ -89,13 +94,10 @@ "signal": 1 }, "custom/recorder": { - "interval": 1, - "tooltip": true, - "format": "", "return-type": "json", - "exec": "echo '{\"class\": \"recording\"}'", - "exec-if": "pgrep wf-recorder", - "on-click": "$HOME/.config/sway/scripts/screen-recorder.sh" + "exec": "$HOME/.config/waybar/scripts/check-screen-recorder.sh", + "on-click": "$HOME/.config/sway/scripts/screen-recorder.sh", + "signal": 8 }, "privacy": { "icon-spacing": 4, diff --git a/.config/waybar/hyprland.jsonc b/.config/waybar/hyprland.jsonc index 355a99b..dd8f2e9 100644 --- a/.config/waybar/hyprland.jsonc +++ b/.config/waybar/hyprland.jsonc @@ -9,7 +9,6 @@ "modules-center": ["clock"], "modules-right": [ "custom/pacman", - "custom/recorder", "privacy", "group/system", "group/misc", @@ -21,7 +20,13 @@ }, "group/misc": { "orientation": "inherit", - "modules": ["pulseaudio", "pulseaudio#microphone", "backlight", "battery"] + "modules": [ + "pulseaudio", + "pulseaudio#microphone", + "backlight", + "battery", + "custom/recorder" + ] }, "group/connections": { "orientation": "inherit", @@ -83,13 +88,10 @@ "signal": 1 }, "custom/recorder": { - "interval": 1, - "tooltip": true, - "format": "", "return-type": "json", - "exec": "echo '{\"class\": \"recording\"}'", - "exec-if": "pgrep wf-recorder", - "on-click": "$HOME/.config/sway/scripts/screen-recorder.sh" + "exec": "$HOME/.config/waybar/scripts/check-screen-recorder.sh", + "on-click": "$HOME/.config/sway/scripts/screen-recorder.sh", + "signal": 8 }, "privacy": { "icon-spacing": 4, diff --git a/.config/waybar/scripts/check-screen-recorder.sh b/.config/waybar/scripts/check-screen-recorder.sh new file mode 100644 index 0000000..6ba4fc3 --- /dev/null +++ b/.config/waybar/scripts/check-screen-recorder.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env bash + +main() { + local data="" + + if pgrep -x wf-recorder > /dev/null 2>&1; then + data='{"text": "󰻂", "tooltip": "Stop recording", "class": "active"}' + else + data='{"text": "󰻂", "tooltip": "Start recording", "class": "idle"}' + fi + + echo $data | jq --unbuffered --compact-output +} + +main $@ diff --git a/.config/waybar/style.css b/.config/waybar/style.css index ce2c982..e11b558 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -46,7 +46,6 @@ tooltip label { #mode, #clock, #workspaces, -#custom-recorder, #custom-power, #mpris, #mpris.paused, @@ -56,7 +55,7 @@ tooltip label { color: #ffffff; } -#custom-recorder, #custom-pacman { +#custom-pacman { background-color: #32e47c; color: #383c4a; } @@ -103,7 +102,6 @@ tooltip label { } #custom-pacman, -#custom-recorder, #mode, #mpris, #custom-power, @@ -112,7 +110,6 @@ tooltip label { } #custom-pacman, -#custom-recorder, #mode, #clock, #privacy, @@ -164,3 +161,13 @@ tooltip label { #idle_inhibitor.activated { background-color: #26a65b; } + +#custom-recorder { + padding-top: 4px; + padding-bottom: 4px; + padding-left: 8px; +} + +#custom-recorder.active { + color: #e63946; +}