summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--user/emacs/init.el17
-rw-r--r--user/settings/darwin.nix33
2 files changed, 35 insertions, 15 deletions
diff --git a/user/emacs/init.el b/user/emacs/init.el
index b6162b76..ae17d7c5 100644
--- a/user/emacs/init.el
+++ b/user/emacs/init.el
@@ -80,22 +80,9 @@
                       modus-themes-to-toggle `(,light-mode-theme ,dark-mode-theme))
                 (load-theme light-mode-theme :noconfirm :noenable)
                 (load-theme dark-mode-theme :noconfirm :noenable)
-                (defun my/set-dark-or-light-theme ()
-                  (interactive)
-                  (let ((appearance (plist-get (mac-application-state) :appearance)))
-                    (mapc #'disable-theme custom-enabled-themes)
-                    (cond ((equal appearance "NSAppearanceNameAqua")
-                           (enable-theme light-mode-theme))
-                          ((equal appearance "NSAppearanceNameDarkAqua")
-                           (enable-theme dark-mode-theme)))))
-                (add-hook 'mac-effective-appearance-change-hook #'my/set-dark-or-light-theme)
-                (if (fboundp #'mac-application-state)
-                    (my/set-dark-or-light-theme)
-                  (enable-theme light-mode-theme)))))
+                (enable-theme light-mode-theme))))
   (if (eq window-system 'x)
-      (setq-default line-spacing 0.2))
-  (setq frame-background-mode 'light)
-  (mapc 'frame-set-background-mode (frame-list)))
+      (setq-default line-spacing 0.2)))
 
 (setq font-lock-maximum-decoration '((t . 1)))
 
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 = {