summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorAhmed Khanzada <me@enzu.ru>2019-03-13 10:10:19 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2019-03-13 10:10:19 -0400
commit18f55afbbcd4a8bcd96a7349e051ff45b91bc137 (patch)
tree2eabc42c3dcead22f7456f483071b7a4487a6fc4 /lisp
parentc8bf09ed0b3ab0ef3c22c3dcfa9e18f44cb3be1b (diff)
downloademacs-18f55afbbcd4a8bcd96a7349e051ff45b91bc137.tar.gz
emacs-18f55afbbcd4a8bcd96a7349e051ff45b91bc137.tar.bz2
emacs-18f55afbbcd4a8bcd96a7349e051ff45b91bc137.zip
* lisp/battery.el (battery-bsd-apm): Make it work on FreeBSD
Copyright-paperwork-exempt: yes Use flag "t" to get remaining time, and adjust to different output order.
Diffstat (limited to 'lisp')
-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:
%h Remaining battery charge time in hours
%t Remaining battery charge time in the form `h:min'"
(let* ((os-name (car (split-string
- (shell-command-to-string "/usr/bin/uname"))))
- (apm-flag (if (equal os-name "OpenBSD") "P" "s"))
- (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag))
- (apm-output (split-string (shell-command-to-string apm-cmd)))
- ;; Battery status
- (battery-status
- (let ((stat (string-to-number (nth 0 apm-output))))
- (cond ((eq stat 0) '("high" . ""))
- ((eq stat 1) '("low" . "-"))
- ((eq stat 2) '("critical" . "!"))
- ((eq stat 3) '("charging" . "+"))
- ((eq stat 4) '("absent" . nil)))))
- ;; Battery percentage
- (battery-percentage (nth 1 apm-output))
- ;; Battery life
- (battery-life (nth 2 apm-output))
- ;; AC status
- (line-status
- (let ((ac (string-to-number (nth 3 apm-output))))
- (cond ((eq ac 0) "disconnected")
- ((eq ac 1) "connected")
- ((eq ac 2) "backup power"))))
- ;; Advanced power savings mode
- (apm-mode
- (let ((apm (string-to-number (nth 4 apm-output))))
- (if (string= os-name "OpenBSD")
- (cond ((eq apm 0) "manual")
- ((eq apm 1) "automatic")
+ ;; FIXME: Can't we use something like `system-type'?
+ (shell-command-to-string "/usr/bin/uname"))))
+ (apm-flag (pcase os-name
+ ("OpenBSD" "mP")
+ ("FreeBSD" "st")
+ (_ "ms")))
+ (apm-cmd (concat "/usr/sbin/apm -abl" apm-flag))
+ (apm-output (split-string (shell-command-to-string apm-cmd)))
+ (battery-status-index (if (equal os-name "FreeBSD") 1 0))
+ (apm-mode-index (if (equal os-name "FreeBSD") 3 4))
+ (battery-percentage-index (if (equal os-name "FreeBSD") 2 1))
+ (battery-life-index (if (equal os-name "FreeBSD") 4 3))
+ (ac-index (if (equal os-name "FreeBSD") 0 3))
+ ;; Battery status
+ (battery-status
+ (let ((stat (string-to-number (nth battery-status-index apm-output))))
+ (cond ((eq stat 0) '("high" . ""))
+ ((eq stat 1) '("low" . "-"))
+ ((eq stat 2) '("critical" . "!"))
+ ((eq stat 3) '("charging" . "+"))
+ ((eq stat 4) '("absent" . nil)))))
+ ;; Battery percentage
+ (battery-percentage (nth battery-percentage-index apm-output))
+ ;; Battery life
+ (battery-life (nth battery-life-index apm-output))
+ ;; AC status
+ (line-status
+ (let ((ac (string-to-number (nth ac-index apm-output))))
+ (cond ((eq ac 0) "disconnected")
+ ((eq ac 1) "connected")
+ ((eq ac 2) "backup power"))))
+ ;; Advanced power savings mode
+ (apm-mode
+ (let ((apm (string-to-number (nth apm-mode-index apm-output))))
+ (if (string= os-name "OpenBSD")
+ (cond ((eq apm 0) "manual")
+ ((eq apm 1) "automatic")
((eq apm 2) "cool running"))
(if (eq apm 1) "on" "off"))))
seconds minutes hours remaining-time)