From 8923862edcc5624dffbcbd4927c5c1c1c771176d Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sat, 8 Nov 2025 21:49:03 +0100 Subject: [PATCH] [waybar] Rework nightlight --- nixos/modules/desktop/waybar/default.nix | 2 + scripts/sunset.sh | 15 ------ scripts/toggle-nightlight.sh | 44 ++++++++++++++++++ stow/waybar/.config/waybar/config.jsonc | 1 + stow/waybar/.config/waybar/modules.json | 59 ++++++++++++++++++++++-- stow/waybar/.config/waybar/style.css | 7 +-- 6 files changed, 105 insertions(+), 23 deletions(-) delete mode 100755 scripts/sunset.sh create mode 100755 scripts/toggle-nightlight.sh diff --git a/nixos/modules/desktop/waybar/default.nix b/nixos/modules/desktop/waybar/default.nix index 273e4ce..d893470 100644 --- a/nixos/modules/desktop/waybar/default.nix +++ b/nixos/modules/desktop/waybar/default.nix @@ -14,5 +14,7 @@ in { ]; programs.waybar.enable = true; + + services.atd.enable = true; # Command scheduler }; } diff --git a/scripts/sunset.sh b/scripts/sunset.sh deleted file mode 100755 index f185115..0000000 --- a/scripts/sunset.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Script to disable for an hour or immediately continue wlsunset. 'Toggle' - -# Check if wlsunset is still running -pid=$(pgrep wlsunset) - -if [[ -z ${pid} ]] ; then - # Start wlsunset right away. - wlsunset -l 50.50 -L 4.00 -t 3000 -T 6500 & -else - # Currently stop wlsunset but restart in an hour. - kill ${pid} - notify-send 'Stopping sunset' 'Restarting in an hour' - at now +1 hours -f "${0}" -fi diff --git a/scripts/toggle-nightlight.sh b/scripts/toggle-nightlight.sh new file mode 100755 index 0000000..bf3ea2d --- /dev/null +++ b/scripts/toggle-nightlight.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Script to disable for an hour or immediately continue wlsunset. 'Toggle' + +# Get current state +pid=$(pgrep wlsunset) + +while getopts ":g" option; do + case "${option}" in + g) + if [[ -z "${pid}" ]]; then + state='active' + tooltip='Turn off nightlight' + class='activated' + else + state='inactive' + tooltip='Turn on nightlight' + class='none' + fi +printf '{"alt": "%s", "tooltip": "%s", "class": "%s" }' \ + "${state}" "${tooltip}" "${class}" + exit 0 + ;; + *) + echo 'Invalid option' + exit 1 + ;; + esac +done + +# Toggle +if [[ -z ${pid} ]] ; then + if [ "$( command -v wlsunset )" ]; then + notify-send 'Starting nightlight' --app-name='twm' + wlsunset -l 50.50 -L 4.00 -t 3000 -T 6500 & + else + notify-send 'Nightlight is not available' + exit 1 + fi +else + # Currently stop wlsunset but restart in an hour. + kill ${pid} + notify-send 'Stopping sunset' 'Restarting in an hour' + at now +1 hours -f "${0}" +fi diff --git a/stow/waybar/.config/waybar/config.jsonc b/stow/waybar/.config/waybar/config.jsonc index ff861e3..a83d47c 100644 --- a/stow/waybar/.config/waybar/config.jsonc +++ b/stow/waybar/.config/waybar/config.jsonc @@ -51,6 +51,7 @@ "privacy", "tray", "group/control-center", + "group/display", "group/network", "pulseaudio", "group/power", diff --git a/stow/waybar/.config/waybar/modules.json b/stow/waybar/.config/waybar/modules.json index 6cec15d..683d70b 100644 --- a/stow/waybar/.config/waybar/modules.json +++ b/stow/waybar/.config/waybar/modules.json @@ -1,4 +1,15 @@ { + "backlight": { + "device": "intel_backlight", + "format": "{percent}% {icon}", + "format-icons": [ + "\uf111", /*  */ + "\uf185" /*  */ + ], + "on-click": "brightnessctl -sq set 0", + "on-click-right": "wl-mirror $(hyprctl monitors -j | jq --raw-output '.[] | select(.focused) | .name')" + }, + "battery": { "format": "{capacity}% {icon}", "format-alt": "{time} {icon}", @@ -71,6 +82,12 @@ "tooltip": false }, + "custom/display": { + "format": "\ue163", /*  */ + "tooltip": false, + "on-click": "wdisplays" + }, + "custom/meta": { "format": "\uf17c", /*  */ "tooltip": false, @@ -134,6 +151,19 @@ "tooltip": true }, + "custom/toggle-nightlight": { + "exec": "bash ${SCRIPT_DIR}/toggle-nightlight.sh -g", + "interval": 60, + "return-type": "json", + "on-click": "bash ${SCRIPT_DIR}/toggle-nightlight.sh", + "format": "{icon}", + "format-icons": { + "active": "\uf186", /*  */ + "inactive": "\uf0eb" /*  */ + }, + "tooltip": true + }, + "custom/toggle-notifications": { "exec": "bash ${SCRIPT_DIR}/toggle-notifications.sh -g", "interval": 60, @@ -163,12 +193,31 @@ "group/control-center": { "orientation": "inherit", "modules": [ + /* Preview */ "custom/control-center", + /* Left-most */ "group/language", - /* "hyprland/language", "sway/language", */ - "custom/toggle-notifications", + "custom/toggle-notifications" + /* Right-most */ + ], + "drawer": { + "transition-duration": 500, + "transition-left-to-right": false, + "children-class": "drawer-child" + } + }, + + "group/display": { + "orientation": "inherit", + "modules": [ + /* Preview */ + "custom/display", + /* Most-left */ + "idle_inhibitor", + "custom/toggle-nightlight", "custom/toggle-light-dark", - "bluetooth" + "backlight" + /* Most-right */ ], "drawer": { "transition-duration": 500, @@ -199,6 +248,7 @@ /* Preview */ "network", /* Most-left */ + "bluetooth", "custom/toggle-tailscale" /* Most-right */ ], @@ -220,8 +270,7 @@ "custom/system-hibernate", "custom/system-sleep", "custom/system-lock", - "power-profiles-daemon", - "idle_inhibitor" + "power-profiles-daemon" /* Most-right */ ], "drawer": { diff --git a/stow/waybar/.config/waybar/style.css b/stow/waybar/.config/waybar/style.css index ecc08fc..39880dd 100644 --- a/stow/waybar/.config/waybar/style.css +++ b/stow/waybar/.config/waybar/style.css @@ -82,12 +82,13 @@ window#waybar { #privacy, #privacy-item, #privacy-item.screenshare, -#privacy-item.audio-in { +#privacy-item.audio-in, +#privacy-item.audio-out { background-color: @safety; } -#privacy-item.screenshare { - background-color: #000000; +#privacy-item { + padding: 0; } #pulseaudio.muted {