mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 19:19:50 +00:00
[Optimize] Calculate font height.
Not use font-info which is slow and may hang. Only create xpm images if available on GUI. Close #176.
This commit is contained in:
parent
839f94e889
commit
b2b7e60798
2 changed files with 35 additions and 41 deletions
|
@ -485,14 +485,6 @@ If the actual char height is larger, it respects the actual char height.")
|
||||||
"Whether is an active window."
|
"Whether is an active window."
|
||||||
(eq (selected-window) doom-modeline-current-window))
|
(eq (selected-window) doom-modeline-current-window))
|
||||||
|
|
||||||
(defun doom-modeline--char-height ()
|
|
||||||
"Calculate the actual char height of the mode-line."
|
|
||||||
(or
|
|
||||||
(let ((font (face-font 'mode-line)))
|
|
||||||
(when (and font (fboundp 'font-info))
|
|
||||||
(* 2 (aref (font-info font) 2))))
|
|
||||||
(round (* 1.3 (frame-char-height)))))
|
|
||||||
|
|
||||||
(defsubst doom-modeline-vspc ()
|
(defsubst doom-modeline-vspc ()
|
||||||
"Text style with icons in mode-line."
|
"Text style with icons in mode-line."
|
||||||
(propertize " " 'face (if (doom-modeline--active)
|
(propertize " " 'face (if (doom-modeline--active)
|
||||||
|
@ -505,6 +497,10 @@ If the actual char height is larger, it respects the actual char height.")
|
||||||
'mode-line
|
'mode-line
|
||||||
'mode-line-inactive)))
|
'mode-line-inactive)))
|
||||||
|
|
||||||
|
(defsubst doom-modeline--char-height ()
|
||||||
|
"Calculate the actual char height of the mode-line."
|
||||||
|
(ceiling (* 1.68 (frame-char-height))))
|
||||||
|
|
||||||
(defun doom-modeline-icon-octicon (&rest args)
|
(defun doom-modeline-icon-octicon (&rest args)
|
||||||
"Display octicon via ARGS."
|
"Display octicon via ARGS."
|
||||||
(when doom-modeline-icon
|
(when doom-modeline-icon
|
||||||
|
@ -558,6 +554,8 @@ If the actual char height is larger, it respects the actual char height.")
|
||||||
|
|
||||||
(defun doom-modeline--make-xpm (face width height)
|
(defun doom-modeline--make-xpm (face width height)
|
||||||
"Create an XPM bitmap via FACE, WIDTH and HEIGHT. Inspired by `powerline''s `pl/make-xpm'."
|
"Create an XPM bitmap via FACE, WIDTH and HEIGHT. Inspired by `powerline''s `pl/make-xpm'."
|
||||||
|
(when (and (display-graphic-p)
|
||||||
|
(image-type-available-p 'xpm))
|
||||||
(propertize
|
(propertize
|
||||||
" " 'display
|
" " 'display
|
||||||
(let ((data (make-list height (make-list width 1)))
|
(let ((data (make-list height (make-list width 1)))
|
||||||
|
@ -565,23 +563,22 @@ If the actual char height is larger, it respects the actual char height.")
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(create-image
|
(create-image
|
||||||
(concat
|
(concat
|
||||||
(format "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\","
|
(format
|
||||||
(length (car data))
|
"/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\","
|
||||||
(length data)
|
(length (car data)) (length data) color color)
|
||||||
color
|
|
||||||
color)
|
|
||||||
(apply #'concat
|
(apply #'concat
|
||||||
(cl-loop with idx = 0
|
(cl-loop with idx = 0
|
||||||
with len = (length data)
|
with len = (length data)
|
||||||
for dl in data
|
for dl in data
|
||||||
do (cl-incf idx)
|
do (cl-incf idx)
|
||||||
collect
|
collect
|
||||||
(concat "\""
|
(concat
|
||||||
|
"\""
|
||||||
(cl-loop for d in dl
|
(cl-loop for d in dl
|
||||||
if (= d 0) collect (string-to-char " ")
|
if (= d 0) collect (string-to-char " ")
|
||||||
else collect (string-to-char "."))
|
else collect (string-to-char "."))
|
||||||
(if (eq idx len) "\"};" "\",\n")))))
|
(if (eq idx len) "\"};" "\",\n")))))
|
||||||
'xpm t :ascent 'center)))))
|
'xpm t :ascent 'center))))))
|
||||||
|
|
||||||
;; Fix: invalid-regexp "Trailing backslash" while handling $HOME on Windows
|
;; Fix: invalid-regexp "Trailing backslash" while handling $HOME on Windows
|
||||||
(defun doom-modeline-shrink-path--dirs-internal (full-path &optional truncate-all)
|
(defun doom-modeline-shrink-path--dirs-internal (full-path &optional truncate-all)
|
||||||
|
|
|
@ -1212,13 +1212,10 @@ of active `multiple-cursors'."
|
||||||
(defvar doom-modeline--bar-active nil)
|
(defvar doom-modeline--bar-active nil)
|
||||||
(defvar doom-modeline--bar-inactive nil)
|
(defvar doom-modeline--bar-inactive nil)
|
||||||
(doom-modeline-def-segment bar
|
(doom-modeline-def-segment bar
|
||||||
"The bar regulates the height of the mode-line in GUI Emacs.
|
"The bar regulates the height of the mode-line in GUI."
|
||||||
Returns \"\" to not break --no-window-system."
|
|
||||||
(if (display-graphic-p)
|
|
||||||
(if (doom-modeline--active)
|
(if (doom-modeline--active)
|
||||||
doom-modeline--bar-active
|
doom-modeline--bar-active
|
||||||
doom-modeline--bar-inactive)
|
doom-modeline--bar-inactive))
|
||||||
""))
|
|
||||||
|
|
||||||
(defun doom-modeline-refresh-bars (&optional width height)
|
(defun doom-modeline-refresh-bars (&optional width height)
|
||||||
"Refresh mode-line bars with `WIDTH' and `HEIGHT'."
|
"Refresh mode-line bars with `WIDTH' and `HEIGHT'."
|
||||||
|
@ -1226,12 +1223,12 @@ Returns \"\" to not break --no-window-system."
|
||||||
(doom-modeline--make-xpm 'doom-modeline-bar
|
(doom-modeline--make-xpm 'doom-modeline-bar
|
||||||
(or width doom-modeline-bar-width)
|
(or width doom-modeline-bar-width)
|
||||||
(max (or height doom-modeline-height)
|
(max (or height doom-modeline-height)
|
||||||
(doom-modeline--char-height)))
|
(doom-modeline--font-height)))
|
||||||
doom-modeline--bar-inactive
|
doom-modeline--bar-inactive
|
||||||
(doom-modeline--make-xpm 'doom-modeline-inactive-bar
|
(doom-modeline--make-xpm 'doom-modeline-inactive-bar
|
||||||
(or width doom-modeline-bar-width)
|
(or width doom-modeline-bar-width)
|
||||||
(max (or height doom-modeline-height)
|
(max (or height doom-modeline-height)
|
||||||
(doom-modeline--char-height)))))
|
(doom-modeline--font-height)))))
|
||||||
|
|
||||||
(when (>= emacs-major-version 26)
|
(when (>= emacs-major-version 26)
|
||||||
(add-variable-watcher
|
(add-variable-watcher
|
||||||
|
|
Loading…
Reference in a new issue