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