Commit | Line | Data |
---|---|---|
d4919479 | 1 | ;;; battery.el --- display battery status information -*- coding: iso-8859-1 -*- |
6b279740 | 2 | |
73b0cd50 | 3 | ;; Copyright (C) 1997-1998, 2000-2011 Free Software Foundation, Inc. |
6b279740 | 4 | |
3b361901 | 5 | ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org> |
d5323ba0 | 6 | ;; Keywords: hardware |
6b279740 | 7 | |
f12b0b96 | 8 | ;; This file is part of GNU Emacs. |
6b279740 | 9 | |
eb3fa2cf | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
6b279740 | 11 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
6b279740 | 14 | |
f12b0b96 | 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
6b279740 RS |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
6b279740 RS |
22 | |
23 | ;;; Commentary: | |
24 | ||
20d4381e JR |
25 | ;; There is at present support for GNU/Linux, OS X and Windows. This |
26 | ;; library supports both the `/proc/apm' file format of Linux version | |
27 | ;; 1.3.58 or newer and the `/proc/acpi/' directory structure of Linux | |
28 | ;; 2.4.20 and 2.6. Darwin (OS X) is supported by using the `pmset' | |
29 | ;; program. Windows is supported by the GetSystemPowerStatus API call. | |
6b279740 RS |
30 | |
31 | ;;; Code: | |
32 | ||
33 | (require 'timer) | |
0f4a15f8 | 34 | (eval-when-compile (require 'cl)) |
6b279740 RS |
35 | |
36 | \f | |
4bef9110 SE |
37 | (defgroup battery nil |
38 | "Display battery status information." | |
39 | :prefix "battery-" | |
40 | :group 'hardware) | |
41 | ||
42 | (defcustom battery-status-function | |
6b279740 RS |
43 | (cond ((and (eq system-type 'gnu/linux) |
44 | (file-readable-p "/proc/apm")) | |
2b3cb60a EZ |
45 | 'battery-linux-proc-apm) |
46 | ((and (eq system-type 'gnu/linux) | |
47 | (file-directory-p "/proc/acpi/battery")) | |
71d21198 | 48 | 'battery-linux-proc-acpi) |
3660b4f5 CY |
49 | ((and (eq system-type 'gnu/linux) |
50 | (file-directory-p "/sys/class/power_supply/") | |
51 | (directory-files "/sys/class/power_supply/" nil "BAT[0-9]$")) | |
52 | 'battery-linux-sysfs) | |
71d21198 | 53 | ((and (eq system-type 'darwin) |
785428c7 RF |
54 | (condition-case nil |
55 | (with-temp-buffer | |
248634e9 LK |
56 | (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) |
57 | (> (buffer-size) 0))) | |
58 | (error nil))) | |
20d4381e JR |
59 | 'battery-pmset) |
60 | ((eq system-type 'windows-nt) | |
61 | 'w32-battery-status)) | |
9201cc28 | 62 | "Function for getting battery status information. |
681e6b4b DL |
63 | The function has to return an alist of conversion definitions. |
64 | Its cons cells are of the form | |
6b279740 RS |
65 | |
66 | (CONVERSION . REPLACEMENT-TEXT) | |
67 | ||
68 | CONVERSION is the character code of a \"conversion specification\" | |
4bef9110 | 69 | introduced by a `%' character in a control string." |
681e6b4b | 70 | :type '(choice (const nil) function) |
4bef9110 | 71 | :group 'battery) |
6b279740 | 72 | |
4bef9110 | 73 | (defcustom battery-echo-area-format |
20d4381e | 74 | (cond ((eq battery-status-function 'battery-linux-proc-acpi) |
71d21198 | 75 | "Power %L, battery %B at %r (%p%% load, remaining time %t)") |
3660b4f5 CY |
76 | ((eq battery-status-function 'battery-linux-sysfs) |
77 | "Power %L, battery %B (%p%% load)") | |
71d21198 | 78 | ((eq battery-status-function 'battery-pmset) |
20d4381e JR |
79 | "%L power, battery %B (%p%% load, remaining time %t)") |
80 | (battery-status-function | |
81 | "Power %L, battery %B (%p%% load, remaining time %t)")) | |
9201cc28 | 82 | "Control string formatting the string to display in the echo area. |
6b279740 RS |
83 | Ordinary characters in the control string are printed as-is, while |
84 | conversion specifications introduced by a `%' character in the control | |
85 | string are substituted as defined by the current value of the variable | |
76815b2a RS |
86 | `battery-status-function'. Here are the ones generally available: |
87 | %c Current capacity (mAh or mWh) | |
88 | %r Current rate of charge or discharge | |
89 | %B Battery status (verbose) | |
90 | %b Battery status: empty means high, `-' means low, | |
91 | `!' means critical, and `+' means charging | |
92 | %d Temperature (in degrees Celsius) | |
93 | %L AC line status (verbose) | |
94 | %p Battery load percentage | |
95 | %m Remaining time (to charge or discharge) in minutes | |
96 | %h Remaining time (to charge or discharge) in hours | |
97 | %t Remaining time (to charge or discharge) in the form `h:min'" | |
4bef9110 SE |
98 | :type '(choice string (const nil)) |
99 | :group 'battery) | |
6b279740 RS |
100 | |
101 | (defvar battery-mode-line-string nil | |
102 | "String to display in the mode line.") | |
f4c4fc74 | 103 | ;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t) |
6b279740 | 104 | |
4bef9110 | 105 | (defcustom battery-mode-line-format |
20d4381e | 106 | (cond ((eq battery-status-function 'battery-linux-proc-acpi) |
71d21198 | 107 |