Commit 509137bba542

Vincent Demeester <vincent@sbr.pm>
2026-05-13 09:51:01
fix(desktop): fix theme and kanshi after idle
Swayidle resume now re-enables all outputs then restarts kanshi so the correct profile is applied (e.g. laptop screen stays off when docked). Removed Persistent=true from color-scheme timers to prevent stale catch-up triggers and added a boot-time init service that sets the correct theme based on current time. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent f834359
Changed files (2)
home
common
home/common/desktop/sway/swayidle.nix
@@ -23,10 +23,12 @@ let
     fi
   '';
   niriPowerOnScript = pkgs.writeShellScript "niri-power-on-monitors" ''
-    edp=$(${pkgs.niri}/bin/niri msg outputs | ${pkgs.gnugrep}/bin/grep -oP 'eDP-\d+')
-    if [ -n "$edp" ]; then
-      ${pkgs.niri}/bin/niri msg output "$edp" on
-    fi
+    # Re-enable all outputs first, then let kanshi apply the correct profile
+    # (e.g. disabling eDP when docked)
+    for output in $(${pkgs.niri}/bin/niri msg outputs | ${pkgs.gnugrep}/bin/grep '^Output' | ${pkgs.gnugrep}/bin/grep -oP '\(\K[^)]+(?=\))'); do
+      ${pkgs.niri}/bin/niri msg output "$output" on
+    done
+    ${pkgs.systemd}/bin/systemctl --user restart kanshi
   '';
   powerOnCmd =
     if desktop == "niri" then
home/common/services/color-scheme-timer.nix
@@ -66,7 +66,6 @@ in
       };
       Timer = {
         OnCalendar = cfg.lightTime;
-        Persistent = true;
       };
       Install = {
         WantedBy = [ "timers.target" ];
@@ -79,11 +78,38 @@ in
       };
       Timer = {
         OnCalendar = cfg.darkTime;
-        Persistent = true;
       };
       Install = {
         WantedBy = [ "timers.target" ];
       };
     };
+
+    # Boot-time check: set correct scheme based on current time
+    systemd.user.services.color-scheme-init = {
+      Unit = {
+        Description = "Set color scheme based on current time";
+        After = [ "graphical-session.target" ];
+      };
+      Service = {
+        Type = "oneshot";
+        ExecStart =
+          let
+            initScript = pkgs.writeShellScript "color-scheme-init" ''
+              hour=$(date +%H)
+              light_hour=$(echo ${cfg.lightTime} | cut -d: -f1)
+              dark_hour=$(echo ${cfg.darkTime} | cut -d: -f1)
+              if [ "$hour" -ge "$light_hour" ] && [ "$hour" -lt "$dark_hour" ]; then
+                ${pkgs.toggle-color-scheme}/bin/toggle-color-scheme light
+              else
+                ${pkgs.toggle-color-scheme}/bin/toggle-color-scheme dark
+              fi
+            '';
+          in
+          "${initScript}";
+      };
+      Install = {
+        WantedBy = [ "graphical-session.target" ];
+      };
+    };
   };
 }