diff --git a/modules/ui/doom-modeline/autoload.el b/modules/ui/doom-modeline/autoload.el index ddebf6a9b..7af38a44e 100644 --- a/modules/ui/doom-modeline/autoload.el +++ b/modules/ui/doom-modeline/autoload.el @@ -1,17 +1,16 @@ ;;; ui/doom-modeline/autoload.el -*- lexical-binding: t; -*- -(defvar +doom-modeline--old-height nil) - ;;;###autoload (defun +doom-modeline|resize-for-big-font () "Adjust the modeline's height when `doom-big-font-mode' is enabled. This was made to be added to `doom-big-font-mode-hook'." - (if doom-big-font-mode - (let* ((font-size (font-get doom-font :size)) - (big-size (font-get doom-big-font :size)) - (ratio (/ (float big-size) font-size))) - (setq +doom-modeline--old-height +doom-modeline-height - +doom-modeline-height (ceiling (* +doom-modeline--old-height ratio)))) - (setq +doom-modeline-height +doom-modeline--old-height)) - (+doom-modeline|init)) + (let ((default-height (default-value '+doom-modeline-height))) + (if doom-big-font-mode + (let* ((font-size (font-get doom-font :size)) + (big-size (font-get doom-big-font :size)) + (ratio (/ (float big-size) font-size))) + (setq +doom-modeline-height (ceiling (* default-height ratio)))) + (setq +doom-modeline-height default-height)) + ;; already has a variable watcher in Emacs 26+ + (unless EMACS26+ (+doom-modeline|refresh-bars)))) diff --git a/modules/ui/doom-modeline/config.el b/modules/ui/doom-modeline/config.el index b8fe7a2c4..321aed44c 100644 --- a/modules/ui/doom-modeline/config.el +++ b/modules/ui/doom-modeline/config.el @@ -178,12 +178,11 @@ active." (eq (selected-window) +doom-modeline-current-window)) ;; Inspired from `powerline's `pl/make-xpm'. -(defun +doom-modeline--make-xpm (face &optional height width) +(defun +doom-modeline--make-xpm (face width height) "Create an XPM bitmap." (propertize " " 'display - (let ((data (make-list (or height +doom-modeline-height) - (make-list (or width +doom-modeline-bar-width) 1))) + (let ((data (make-list height (make-list width 1))) (color (or (face-background face nil t) "None"))) (ignore-errors (create-image @@ -617,6 +616,21 @@ Returns \"\" to not break --no-window-system." +doom-modeline--bar-inactive) "")) +(when EMACS26+ + (add-variable-watcher + '+doom-modeline-height + (lambda (_sym val op _where) + (when (and (eq op 'set) (integerp val)) + (+doom-modeline|refresh-bars +doom-modeline-bar-width val)))) + + (add-variable-watcher + '+doom-modeline-bar-width + (lambda (_sym val op _where) + (when (and (eq op 'set) (integerp val)) + (+doom-modeline|refresh-bars val +doom-modeline-height)))) + + (add-hook 'doom-big-font-mode-hook #'+doom-modeline|resize-for-big-font)) + ;; ;; Mode lines @@ -647,11 +661,19 @@ Returns \"\" to not break --no-window-system." ;; Hooks ;; +(defun +doom-modeline|refresh-bars (&optional width height) + (setq +doom-modeline--bar-active + (+doom-modeline--make-xpm 'doom-modeline-bar + (or width +doom-modeline-bar-width) + (or height +doom-modeline-height)) + +doom-modeline--bar-inactive + (+doom-modeline--make-xpm 'doom-modeline-inactive-bar + (or width +doom-modeline-bar-width) + (or height +doom-modeline-height)))) + (defun +doom-modeline|init () ;; Create bars - (setq +doom-modeline--bar-active (+doom-modeline--make-xpm 'doom-modeline-bar) - +doom-modeline--bar-inactive (+doom-modeline--make-xpm 'doom-modeline-inactive-bar)) - + (+doom-modeline|refresh-bars) (unless after-init-time ;; These buffers are already created and don't get modelines. For the love ;; of Emacs, someone give the man a modeline! @@ -695,6 +717,3 @@ Returns \"\" to not break --no-window-system." (add-hook 'focus-in-hook #'+doom-modeline|focus) (add-hook 'focus-out-hook #'+doom-modeline|unfocus) - -;; -;; (add-hook 'doom-big-font-mode-hook #'+doom-modeline|resize-for-big-font)