From 0be1080c44190eaba6e352d858a7b9fc6186bdc3 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 17 May 2024 10:15:42 +0300 Subject: emacs+sway: Use emacs to set wallpaper on startup --- .config/emacs/init.el | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to '.config/emacs/init.el') diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 7c88626..4d88c34 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -251,7 +251,6 @@ ("b" . "src bash") ("q" . "QUOTE"))) - ;; Export (add-to-list 'org-latex-classes '("article" "\\documentclass[11pt,a4paper]{article} @@ -1237,7 +1236,11 @@ Create a temporary frame to execute BODY, which will then be deleted." ;; Theming -(defvar wallpapers-dir "~/wallpapers/") +(defvar wallpapers-dir "~/wallpapers/" + "Wallpaper directory.") + +(defvar wallpaper-current nil + "Current wallpaper.") (defun thanos/load-theme (&optional theme) "Disable current theme and load a new THEME." @@ -1265,8 +1268,42 @@ Create a temporary frame to execute BODY, which will then be deleted." (defun thanos/wallpaper-select () "Set wallpaper." (interactive) - (let ((wallpaper (completing-read "Choose wallpaper: " (directory-files wallpapers-dir nil "^[^.].*")))) - (thanos/wallpaper-set (format "%s%s" wallpapers-dir wallpaper)))) + (let ((wallpaper (format "%s%s" wallpapers-dir + (completing-read "Choose wallpaper: " + (directory-files wallpapers-dir nil "^[^.].*"))))) + (thanos/wallpaper-set wallpaper) + (setf wallpaper-current wallpaper))) + +(defun thanos/wallpaper-watcher (_symbol new-value _where _environment) + "Watch for wallpaper changes." + (with-temp-buffer (find-file (expand-file-name "wallpaper" user-emacs-directory)) + (erase-buffer) + (setf wallpaper-current new-value) + (insert (pp-to-string wallpaper-current)) + (save-buffer) + (kill-buffer))) + +(defun thanos/load-wallpaper () + "Load saved wallpaper." + (let ((wallpaper-path (expand-file-name "wallpaper" user-emacs-directory))) + (if (file-exists-p wallpaper-path) + (with-temp-buffer + (insert-file-contents wallpaper-path) + (goto-char (point-min)) + (let ((contents (read (current-buffer)))) + (setf wallpaper-current contents))) + (write-region "nil" nil wallpaper-path)))) + +(defun thanos/wallpaper-startup (&optional image) + "Set wallpaper IMAGE on startup." + (thanos/load-wallpaper) + (let ((image (or image wallpaper-current))) + (thanos/wallpaper-set image))) + +(add-variable-watcher 'wallpaper-current #'thanos/wallpaper-watcher) + +;; Set wallpaper +(thanos/wallpaper-startup) (defvar-keymap thanos/applications-map :doc "Thanos commonly used programs" -- cgit v1.2.3