ui/doom-modeline: adjust bars when height/width is changed

Also when doom-big-font-mode is toggled.
This commit is contained in:
Henrik Lissner 2018-05-04 10:32:46 +02:00
parent e6c7c8a8cd
commit 85e5ac4514
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 37 additions and 19 deletions

View file

@ -1,17 +1,16 @@
;;; ui/doom-modeline/autoload.el -*- lexical-binding: t; -*- ;;; ui/doom-modeline/autoload.el -*- lexical-binding: t; -*-
(defvar +doom-modeline--old-height nil)
;;;###autoload ;;;###autoload
(defun +doom-modeline|resize-for-big-font () (defun +doom-modeline|resize-for-big-font ()
"Adjust the modeline's height when `doom-big-font-mode' is enabled. This was "Adjust the modeline's height when `doom-big-font-mode' is enabled. This was
made to be added to `doom-big-font-mode-hook'." made to be added to `doom-big-font-mode-hook'."
(let ((default-height (default-value '+doom-modeline-height)))
(if doom-big-font-mode (if doom-big-font-mode
(let* ((font-size (font-get doom-font :size)) (let* ((font-size (font-get doom-font :size))
(big-size (font-get doom-big-font :size)) (big-size (font-get doom-big-font :size))
(ratio (/ (float big-size) font-size))) (ratio (/ (float big-size) font-size)))
(setq +doom-modeline--old-height +doom-modeline-height (setq +doom-modeline-height (ceiling (* default-height ratio))))
+doom-modeline-height (ceiling (* +doom-modeline--old-height ratio)))) (setq +doom-modeline-height default-height))
(setq +doom-modeline-height +doom-modeline--old-height)) ;; already has a variable watcher in Emacs 26+
(+doom-modeline|init)) (unless EMACS26+ (+doom-modeline|refresh-bars))))

View file

@ -178,12 +178,11 @@ active."
(eq (selected-window) +doom-modeline-current-window)) (eq (selected-window) +doom-modeline-current-window))
;; Inspired from `powerline's `pl/make-xpm'. ;; 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." "Create an XPM bitmap."
(propertize (propertize
" " 'display " " 'display
(let ((data (make-list (or height +doom-modeline-height) (let ((data (make-list height (make-list width 1)))
(make-list (or width +doom-modeline-bar-width) 1)))
(color (or (face-background face nil t) "None"))) (color (or (face-background face nil t) "None")))
(ignore-errors (ignore-errors
(create-image (create-image
@ -617,6 +616,21 @@ Returns \"\" to not break --no-window-system."
+doom-modeline--bar-inactive) +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 ;; Mode lines
@ -647,11 +661,19 @@ Returns \"\" to not break --no-window-system."
;; Hooks ;; 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 () (defun +doom-modeline|init ()
;; Create bars ;; Create bars
(setq +doom-modeline--bar-active (+doom-modeline--make-xpm 'doom-modeline-bar) (+doom-modeline|refresh-bars)
+doom-modeline--bar-inactive (+doom-modeline--make-xpm 'doom-modeline-inactive-bar))
(unless after-init-time (unless after-init-time
;; These buffers are already created and don't get modelines. For the love ;; These buffers are already created and don't get modelines. For the love
;; of Emacs, someone give the man a modeline! ;; 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-in-hook #'+doom-modeline|focus)
(add-hook 'focus-out-hook #'+doom-modeline|unfocus) (add-hook 'focus-out-hook #'+doom-modeline|unfocus)
;;
;; (add-hook 'doom-big-font-mode-hook #'+doom-modeline|resize-for-big-font)