diff --git a/modules/desktop/hyprland/hyprlock.nix b/modules/desktop/hyprland/hyprlock.nix index a7d8df0..3656648 100644 --- a/modules/desktop/hyprland/hyprlock.nix +++ b/modules/desktop/hyprland/hyprlock.nix @@ -12,15 +12,24 @@ let # The hyprlock this module installs, used by the lock keybind below. hyprlock = "${config.home-manager.users.${user}.programs.hyprlock.package}/bin/hyprlock"; + sleepIcon = builtins.fromJSON ''"\udb81\udcb2"''; + sleepOffIcon = builtins.fromJSON ''"\udb81\udcb3"''; + idleLockToggle = pkgs.writeShellScript "lockscreen-idle-inhibit-toggle" '' unit=lockscreen-idle-inhibit.service + refresh_waybar() { + ${pkgs.procps}/bin/pkill -RTMIN+9 waybar >/dev/null 2>&1 || true + } + if ${pkgs.systemd}/bin/systemctl --user is-active --quiet "$unit"; then ${pkgs.systemd}/bin/systemctl --user stop "$unit" + refresh_waybar + ${pkgs.swayosd}/bin/swayosd-client --custom-message "${sleepIcon}" exit 0 fi - ${pkgs.systemd}/bin/systemd-run \ + if ${pkgs.systemd}/bin/systemd-run \ --user \ --collect \ --unit=lockscreen-idle-inhibit \ @@ -29,7 +38,10 @@ let --what=idle \ --who=lockscreen-hotkey \ --why="lock screen disabled by hotkey" \ - ${pkgs.coreutils}/bin/sleep infinity + ${pkgs.coreutils}/bin/sleep infinity >/dev/null; then + refresh_waybar + ${pkgs.swayosd}/bin/swayosd-client --custom-message "${sleepOffIcon}" + fi ''; in { diff --git a/modules/desktop/waybar.nix b/modules/desktop/waybar.nix index 0f5cee7..9dfd721 100644 --- a/modules/desktop/waybar.nix +++ b/modules/desktop/waybar.nix @@ -12,6 +12,7 @@ let # A Nerd Font Private-Use-Area codepoint as a literal character, decoded # through JSON so the glyph survives as bytes rather than an editor paste. g = code: builtins.fromJSON ''"\u${code}"''; + sleepOffIcon = builtins.fromJSON ''"\udb81\udcb3"''; # Renders and toggles mako's do-not-disturb mode. # With no mako daemon answering, the status reads "notifications on", keeping @@ -38,6 +39,14 @@ let printf '{"text":"","class":"idle"}\n' fi ''; + + idleLockStatus = pkgs.writeShellScript "waybar-idle-lock-status" '' + if ${pkgs.systemd}/bin/systemctl --user is-active --quiet lockscreen-idle-inhibit.service; then + printf '{"text":"${sleepOffIcon}","tooltip":"Idle locking inhibited","class":"inhibited"}\n' + else + printf '{"text":"","class":"idle"}\n' + fi + ''; in { options.modules.desktop.waybar.enable = lib.mkEnableOption "the Waybar status bar"; @@ -63,6 +72,7 @@ in modules-center = [ "clock" ]; modules-right = [ "custom/recording" + "custom/idle-lock" "mpris" "wireplumber" "network" @@ -155,6 +165,13 @@ in exec = "${recStatus}"; interval = 1; }; + + "custom/idle-lock" = { + return-type = "json"; + exec = "${idleLockStatus}"; + interval = "once"; + signal = 9; + }; }; }; };