diff options
| author | Ellington Santos | 2020-05-26 11:37:04 -0300 |
|---|---|---|
| committer | Eli Zaretskii | 2020-06-06 10:56:27 +0300 |
| commit | acd2cb28ef63188bff31fc167ab007a051f99c17 (patch) | |
| tree | ac66f9d122cf47ea8364dfaa7c1ed17136b1978d /lisp | |
| parent | a984f39554cb33b9c2efbc843aabb283c69d503d (diff) | |
| download | emacs-acd2cb28ef63188bff31fc167ab007a051f99c17.tar.gz emacs-acd2cb28ef63188bff31fc167ab007a051f99c17.zip | |
Improve battery status display via GNU/Linux sysfs
* lisp/battery.el (battery-linux-sysfs): Support %b format.
Improve the display of %p. (Bug#41542)
Copyright-paperwork-exempt: yes
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/battery.el | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lisp/battery.el b/lisp/battery.el index 7027b254480..b8855a8ce37 100644 --- a/lisp/battery.el +++ b/lisp/battery.el | |||
| @@ -441,13 +441,15 @@ The following %-sequences are provided: | |||
| 441 | %c Current capacity (mAh or mWh) | 441 | %c Current capacity (mAh or mWh) |
| 442 | %r Current rate | 442 | %r Current rate |
| 443 | %B Battery status (verbose) | 443 | %B Battery status (verbose) |
| 444 | %b Battery status, empty means high, `-' means low, | ||
| 445 | `!' means critical, and `+' means charging | ||
| 444 | %d Temperature (in degrees Celsius) | 446 | %d Temperature (in degrees Celsius) |
| 445 | %p Battery load percentage | 447 | %p Battery load percentage |
| 446 | %L AC line status (verbose) | 448 | %L AC line status (verbose) |
| 447 | %m Remaining time (to charge or discharge) in minutes | 449 | %m Remaining time (to charge or discharge) in minutes |
| 448 | %h Remaining time (to charge or discharge) in hours | 450 | %h Remaining time (to charge or discharge) in hours |
| 449 | %t Remaining time (to charge or discharge) in the form `h:min'" | 451 | %t Remaining time (to charge or discharge) in the form `h:min'" |
| 450 | (let (charging-state temperature hours | 452 | (let (charging-state temperature hours percentage-now |
| 451 | ;; Some batteries report charges and current, other energy and power. | 453 | ;; Some batteries report charges and current, other energy and power. |
| 452 | ;; In order to reliably be able to combine those data, we convert them | 454 | ;; In order to reliably be able to combine those data, we convert them |
| 453 | ;; all to energy/power (since we can't combine different charges if | 455 | ;; all to energy/power (since we can't combine different charges if |
| @@ -515,6 +517,8 @@ The following %-sequences are provided: | |||
| 515 | energy-now | 517 | energy-now |
| 516 | (- energy-full energy-now)))) | 518 | (- energy-full energy-now)))) |
| 517 | (setq hours (/ remaining power-now))))))) | 519 | (setq hours (/ remaining power-now))))))) |
| 520 | (when (and (> energy-full 0) (> energy-now 0)) | ||
| 521 | (setq percentage-now (/ (* 100 energy-now) energy-full))) | ||
| 518 | (list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0)) | 522 | (list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0)) |
| 519 | (number-to-string (/ energy-now voltage-now))) | 523 | (number-to-string (/ energy-now voltage-now))) |
| 520 | (t "N/A"))) | 524 | (t "N/A"))) |
| @@ -528,10 +532,13 @@ The following %-sequences are provided: | |||
| 528 | "N/A")) | 532 | "N/A")) |
| 529 | (cons ?d (or temperature "N/A")) | 533 | (cons ?d (or temperature "N/A")) |
| 530 | (cons ?B (or charging-state "N/A")) | 534 | (cons ?B (or charging-state "N/A")) |
| 531 | (cons ?p (cond ((and (> energy-full 0) (> energy-now 0)) | 535 | (cons ?b (or (and (string= charging-state "Charging") "+") |
| 532 | (format "%.1f" | 536 | (and percentage-now (< percentage-now battery-load-critical) "!") |
| 533 | (/ (* 100 energy-now) energy-full))) | 537 | (and percentage-now (< percentage-now battery-load-low) "-") |
| 534 | (t "N/A"))) | 538 | "")) |
| 539 | (cons ?p (cond | ||
| 540 | ((and percentage-now (format "%.1f" percentage-now))) | ||
| 541 | (t "N/A"))) | ||
| 535 | (cons ?L (cond | 542 | (cons ?L (cond |
| 536 | ((battery-search-for-one-match-in-files | 543 | ((battery-search-for-one-match-in-files |
| 537 | (list "/sys/class/power_supply/AC/online" | 544 | (list "/sys/class/power_supply/AC/online" |