feat(nightlight): menu + Waybar on/off toggle
Add a runtime toggle for the scheduled blue-light filter, the remaining optional item on the night-light roadmap entry. nomarchy-nightlight (nightlight.nix, always on PATH) starts/stops the hyprsunset *service* rather than poking its runtime gamma: `systemctl --user is-active` is the single source of truth, the screen restores to true colours when stopped, and it lets you force the filter off for colour-sensitive work (even at night) and back on without touching config. It self-gates — `status` prints nothing when the unit is absent — so the indicator hides itself when night-light isn't enabled. - Menu: `nomarchy-menu nightlight` toggles it; a self-gated row in the System submenu (shown only when the hyprsunset unit exists). - Waybar: a self-gating `custom/nightlight` indicator (moon = on, sun = off), in the generated bar and both summer whole-swap themes for parity. Verified: home generation builds, generated waybar config carries custom/nightlight, the menu has the dispatcher case + System row, both scripts pass bash -n, and status self-gates to empty with no unit. Pending an on-machine check that stopping hyprsunset cleanly restores the gamma. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,14 +5,51 @@
|
||||
#
|
||||
# The hyprsunset HM service module is provided by home-manager; this only
|
||||
# configures it. Override anything with plain services.hyprsunset.* options.
|
||||
{ config, lib, ... }:
|
||||
#
|
||||
# nomarchy-nightlight is the menu/Waybar toggle: it starts/stops the hyprsunset
|
||||
# *service* (so `systemctl --user is-active` is the single source of truth and
|
||||
# the screen restores to true colours when stopped), letting you force the
|
||||
# filter off for colour-sensitive work and back on without touching the config.
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.nomarchy.nightlight;
|
||||
|
||||
# Toggle/status helper, on PATH so the menu and both the generated and
|
||||
# whole-swap Waybars can drive it by name. Self-gates: when the unit doesn't
|
||||
# exist (night-light not enabled) `status` prints nothing, so the Waybar
|
||||
# module hides itself — same pattern as the power-profile indicator.
|
||||
nomarchy-nightlight = pkgs.writeShellScriptBin "nomarchy-nightlight" ''
|
||||
unit=hyprsunset.service
|
||||
if ! systemctl --user cat "$unit" >/dev/null 2>&1; then
|
||||
[ "''${1:-}" = status ] && exit 0
|
||||
notify-send "Night light" "Not enabled — set nomarchy.nightlight.enable."
|
||||
exit 0
|
||||
fi
|
||||
case "''${1:-toggle}" in
|
||||
status)
|
||||
if systemctl --user is-active --quiet "$unit"; then
|
||||
printf '{"text":"","tooltip":"Night light on — warm on schedule (click to disable)","class":"on"}\n'
|
||||
else
|
||||
printf '{"text":"","tooltip":"Night light off (click to enable)","class":"off"}\n'
|
||||
fi ;;
|
||||
on) systemctl --user start "$unit" ;;
|
||||
off) systemctl --user stop "$unit" ;;
|
||||
toggle)
|
||||
if systemctl --user is-active --quiet "$unit"; then
|
||||
systemctl --user stop "$unit"
|
||||
notify-send "Night light off" "Screen back to true colours."
|
||||
else
|
||||
systemctl --user start "$unit"
|
||||
notify-send "Night light on" "Warm filter follows your schedule."
|
||||
fi ;;
|
||||
*) echo "usage: nomarchy-nightlight [toggle|status|on|off]" >&2; exit 64 ;;
|
||||
esac
|
||||
'';
|
||||
in
|
||||
{
|
||||
config = lib.mkIf cfg.enable {
|
||||
services.hyprsunset = {
|
||||
config = {
|
||||
services.hyprsunset = lib.mkIf cfg.enable {
|
||||
enable = true;
|
||||
settings.profile = [
|
||||
# Daytime: identity = no colour change.
|
||||
@@ -21,5 +58,9 @@ in
|
||||
{ time = cfg.sunset; temperature = cfg.temperature; }
|
||||
];
|
||||
};
|
||||
|
||||
# Always on PATH (it self-gates at runtime), so a static whole-swap Waybar
|
||||
# can exec it even when night-light is off without the call failing.
|
||||
home.packages = [ nomarchy-nightlight ];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user