mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 19:19:50 +00:00
[Optimize] Improve the performance of fancy-battery segment.
This commit is contained in:
parent
3b704ee080
commit
748824e692
2 changed files with 73 additions and 65 deletions
|
@ -1952,11 +1952,13 @@ we don't want to remove that so we just return the original."
|
|||
;; fancy battery
|
||||
;;
|
||||
|
||||
(doom-modeline-def-segment fancy-battery
|
||||
(when (and (doom-modeline--active)
|
||||
(bound-and-true-p fancy-battery-mode))
|
||||
(let* ((charging? (string-equal "AC" (cdr (assoc ?L fancy-battery-last-status))))
|
||||
(percentage (cdr (assq ?p fancy-battery-last-status)))
|
||||
(defvar-local doom-modeline--battery-status nil)
|
||||
(defun doom-modeline-update-battery-status (&optional status)
|
||||
"Update battery STATUS."
|
||||
(setq doom-modeline--battery-status
|
||||
(let* ((status (or status fancy-battery-last-status))
|
||||
(charging? (string-equal "AC" (cdr (assoc ?L status))))
|
||||
(percentage (cdr (assq ?p status)))
|
||||
(percentage-number (string-to-number percentage))
|
||||
(face (cond
|
||||
(charging? 'fancy-battery-charging)
|
||||
|
@ -1989,13 +1991,13 @@ we don't want to remove that so we just return the original."
|
|||
(if doom-modeline-icon
|
||||
(doom-modeline-icon-faicon "battery-empty" :v-adjust -0.0575)
|
||||
(propertize "!" 'face face)))))
|
||||
(status (and percentage (concat percentage "%%")))
|
||||
(percent-str (and percentage (concat percentage "%%")))
|
||||
(help-echo (if battery-echo-area-format
|
||||
(battery-format battery-echo-area-format fancy-battery-last-status)
|
||||
(battery-format battery-echo-area-format status)
|
||||
"Battery status not available")))
|
||||
(concat
|
||||
" "
|
||||
(if status
|
||||
(if percent-str
|
||||
(concat
|
||||
(propertize icon
|
||||
'face (if doom-modeline-icon
|
||||
|
@ -2008,7 +2010,7 @@ we don't want to remove that so we just return the original."
|
|||
'help-echo help-echo)
|
||||
(if doom-modeline-icon
|
||||
(propertize doom-modeline-vspc 'help-echo help-echo))
|
||||
(propertize status
|
||||
(propertize percent-str
|
||||
'face face
|
||||
'help-echo help-echo))
|
||||
;; Battery status is not available
|
||||
|
@ -2019,6 +2021,12 @@ we don't want to remove that so we just return the original."
|
|||
:face 'error)
|
||||
(propertize "N/A" 'face 'error)))
|
||||
" "))))
|
||||
(add-hook 'fancy-battery-status-update-functions #'doom-modeline-update-battery-status)
|
||||
|
||||
(doom-modeline-def-segment fancy-battery
|
||||
(when (and (doom-modeline--active)
|
||||
(bound-and-true-p fancy-battery-mode))
|
||||
(or doom-modeline--battery-status (doom-modeline-update-battery-status))))
|
||||
|
||||
(defun doom-modeline-override-fancy-battery-modeline ()
|
||||
"Override `fancy-battery' mode-line."
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
;; Author: Vincent Zhang <seagle0128@gmail.com>
|
||||
;; Homepage: https://github.com/seagle0128/doom-modeline
|
||||
;; Version: 1.9.4
|
||||
;; Version: 1.9.5
|
||||
;; Package-Requires: ((emacs "25.1") (all-the-icons "1.0.0") (shrink-path "0.2.0") (eldoc-eval "0.1") (dash "2.11.0"))
|
||||
;; Keywords: faces mode-line
|
||||
|
||||
|
|
Loading…
Reference in a new issue