theme-change with banner and manual toggle


#1

对有一些强迫症的人来说一点点小问题就想着折腾。所以折腾了一会 theme-change 把结果 分享下。主要是解决自己的两点小问题:1、自动切换 theme 时也切换 banner,因为有的 banner 图片只适合在一种背景下显示。2、有时候会因为心情等原因想临时切换背景

banner 图片我放在 .doom.d/local/banner 中,自己设置列表中喜欢的文件名。

(use-package! theme-changer
:config

(defvar reverse-day nil
    "whether reverse the day light for theme change")

(setq
theme-group1 '(doom-one-light
                doom-acario-light
                doom-nord-light
                doom-opera-light
                doom-solarized-light
                doom-tomorrow-day)    ; light theme
theme-group2 '(doom-one
                doom-acario-dark
                doom-city-lights
                doom-challenger-deep
                doom-dracula
                doom-gruvbox
                doom-Iosvkem
                doom-vibrant
                doom-molokai
                doom-moonlight
                doom-oceanic-next
                doom-outrun-electric
                doom-peacock
                doom-spacegrey
                doom-snazzy
                doom-wilmersdorf)     ; dark theme
banner-group1 '(
                "KEC_Light_BK_Small.png"
                "ue-green-sm.png"
                "ue-blue-sm.png"
                "ue-orange-sm.png"
                "ue-pink-sm.png"
                "ue-red-sm.png"
                "ue-dark-sm.png"
                )                    ; banner for light theme
banner-group2 '("caffee.png"
                "KEC_Dark_BK_Small.png"
                "ue-blue-sm.png"
                "ue-green-sm.png"
                "ue-pink-sm.png"
                "ue-red-sm.png"
                "ue-light-sm.png"
                "ue-colorful-sm.png"
                )                    ; banner for dark theme
)

(defun my-change-theme ()
    (if reverse-day
        (change-theme theme-group2 theme-group1)
        (change-theme theme-group1 theme-group2)
    ))

(defun my-toggle-theme()
    (interactive)
    (setq reverse-day (not reverse-day))
    (cancel-function-timers #'change-theme)
    (my-change-theme)
    )

;; dashboard banner image
(defun my-set-banner (&rest r)
    (setq fancy-splash-image
    (let* ((banners (if reverse-day banner-group2 banner-group1))
            (banner (elt banners (random (length banners))))
            (banner-file (expand-file-name (concat "local/banner/" banner) doom-private-dir)))
        banner-file))
    )
(advice-add 'change-theme :before #'my-set-banner)

(my-change-theme)
)