summary refs log tree commit diff stats
path: root/user/settings
diff options
context:
space:
mode:
authorAlan Pearce2023-04-02 20:27:53 +0200
committerAlan Pearce2023-04-02 20:27:53 +0200
commitc6440f3e932e936ce603a977c725f554c9ce44bf (patch)
tree7c363282d8fdd11d1c5f8d98f6743594cf717282 /user/settings
parent14e573db264debf99046142ce9a72f41ccdf3baa (diff)
downloadnixfiles-c6440f3e932e936ce603a977c725f554c9ce44bf.tar.lz
nixfiles-c6440f3e932e936ce603a977c725f554c9ce44bf.tar.zst
nixfiles-c6440f3e932e936ce603a977c725f554c9ce44bf.zip
emacs: re-implement auto dark/light mode switching on macOS
Since I'm not using EmacsMacPort any more, the function
`(mac-application-state)` isn't defined.  However, we can use launchd
to tell us when the system preferences change and then ask whether
light or dark mode is active
Diffstat (limited to 'user/settings')
-rw-r--r--user/settings/darwin.nix33
1 files changed, 33 insertions, 0 deletions
diff --git a/user/settings/darwin.nix b/user/settings/darwin.nix
index 2ca4ddf6..75df5271 100644
--- a/user/settings/darwin.nix
+++ b/user/settings/darwin.nix
@@ -78,6 +78,39 @@
         StandardOutputPath = "/dev/null";
       };
     };
+    dark-light-mode = {
+      enable = true;
+      config = {
+        WatchPaths = [ "${config.home.homeDirectory}/Library/Preferences/.GlobalPreferences.plist" ];
+        ProgramArguments = [
+          "/bin/sh"
+          (
+            toString
+              (
+                pkgs.writeShellScript
+                  "toggle-dark-light-mode"
+                  ''
+                    if defaults read -g AppleInterfaceStyle &>/dev/null ; then
+                      MODE="dark"
+                    else
+                      MODE="light"
+                    fi
+                    emacsSwitchTheme () {
+                      if pgrep -q Emacs; then
+                        if [[  $MODE == "dark"  ]]; then
+                            emacsclient --eval "(modus-themes-load-theme (cadr modus-themes-to-toggle))"
+                        elif [[  $MODE == "light"  ]]; then
+                            emacsclient --eval "(modus-themes-load-theme (car modus-themes-to-toggle))"
+                        fi
+                      fi
+                    }
+                    emacsSwitchTheme $@
+                  ''
+              )
+          )
+        ];
+      };
+    };
   };
 
   programs.zsh.shellAliases = {