aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/battery.el65
1 files changed, 37 insertions, 28 deletions
diff --git a/lisp/battery.el b/lisp/battery.el
index efd2a2181af..64661fd5b96 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -617,34 +617,43 @@ The following %-sequences are provided:
617%h Remaining battery charge time in hours 617%h Remaining battery charge time in hours
618%t Remaining battery charge time in the form `h:min'" 618%t Remaining battery charge time in the form `h:min'"
619 (let* ((os-name (car (split-string 619 (let* ((os-name (car (split-string
620 (shell-command-to-string "/usr/bin/uname")))) 620 ;; FIXME: Can't we use something like `system-type'?
621 (apm-flag (if (equal os-name "OpenBSD") "P" "s")) 621 (shell-command-to-string "/usr/bin/uname"))))
622 (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag)) 622 (apm-flag (pcase os-name
623 (apm-output (split-string (shell-command-to-string apm-cmd))) 623 ("OpenBSD" "mP")
624 ;; Battery status 624 ("FreeBSD" "st")
625 (battery-status 625 (_ "ms")))
626 (let ((stat (string-to-number (nth 0 apm-output)))) 626 (apm-cmd (concat "/usr/sbin/apm -abl" apm-flag))
627 (cond ((eq stat 0) '("high" . "")) 627 (apm-output (split-string (shell-command-to-string apm-cmd)))
628 ((eq stat 1) '("low" . "-")) 628 (battery-status-index (if (equal os-name "FreeBSD") 1 0))
629 ((eq stat 2) '("critical" . "!")) 629 (apm-mode-index (if (equal os-name "FreeBSD") 3 4))
630 ((eq stat 3) '("charging" . "+")) 630 (battery-percentage-index (if (equal os-name "FreeBSD") 2 1))
631 ((eq stat 4) '("absent" . nil))))) 631 (battery-life-index (if (equal os-name "FreeBSD") 4 3))
632 ;; Battery percentage 632 (ac-index (if (equal os-name "FreeBSD") 0 3))
633 (battery-percentage (nth 1 apm-output)) 633 ;; Battery status
634 ;; Battery life 634 (battery-status
635 (battery-life (nth 2 apm-output)) 635 (let ((stat (string-to-number (nth battery-status-index apm-output))))
636 ;; AC status 636 (cond ((eq stat 0) '("high" . ""))
637 (line-status 637 ((eq stat 1) '("low" . "-"))
638 (let ((ac (string-to-number (nth 3 apm-output)))) 638 ((eq stat 2) '("critical" . "!"))
639 (cond ((eq ac 0) "disconnected") 639 ((eq stat 3) '("charging" . "+"))
640 ((eq ac 1) "connected") 640 ((eq stat 4) '("absent" . nil)))))
641 ((eq ac 2) "backup power")))) 641 ;; Battery percentage
642 ;; Advanced power savings mode 642 (battery-percentage (nth battery-percentage-index apm-output))
643 (apm-mode 643 ;; Battery life
644 (let ((apm (string-to-number (nth 4 apm-output)))) 644 (battery-life (nth battery-life-index apm-output))
645 (if (string= os-name "OpenBSD") 645 ;; AC status
646 (cond ((eq apm 0) "manual") 646 (line-status
647 ((eq apm 1) "automatic") 647 (let ((ac (string-to-number (nth ac-index apm-output))))
648 (cond ((eq ac 0) "disconnected")
649 ((eq ac 1) "connected")
650 ((eq ac 2) "backup power"))))
651 ;; Advanced power savings mode
652 (apm-mode
653 (let ((apm (string-to-number (nth apm-mode-index apm-output))))
654 (if (string= os-name "OpenBSD")
655 (cond ((eq apm 0) "manual")
656 ((eq apm 1) "automatic")
648 ((eq apm 2) "cool running")) 657 ((eq apm 2) "cool running"))
649 (if (eq apm 1) "on" "off")))) 658 (if (eq apm 1) "on" "off"))))
650 seconds minutes hours remaining-time) 659 seconds minutes hours remaining-time)