File: fdpowermon.1

package info (click to toggle)
fdpowermon 1.19
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 148 kB
  • sloc: perl: 297; makefile: 6
file content (372 lines) | stat: -rw-r--r-- 14,209 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "FDPOWERMON 1"
.TH FDPOWERMON 1 "2016-06-27" "perl v5.22.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
fdpowermon \- add a battery level icon to a freedesktop.org\-compliant system tray
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
fdpowermon
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This program allows one to display a \*(L"battery level\*(R" icon in any
freedesktop.org\-compliant status area. It can be themed through either a
plain-text configuration file (\fI/etc/fdpowermon/theme.cfg\fR or
\&\fI\f(CI$XDG_CONFIG_DIR\fI/fdpowermon/theme.cfg\fR), or through a short perl script
(\fI/etc/fdpowermon/theme.pl\fR or \fI\f(CI$XDG_CONFIG_DIR\fI/fdpowermon/theme.pl\fR).
If \f(CW$XDG_CONFIG_DIR\fR is not set, \f(CW$HOME\fR/.config is used as a default.
.PP
The former is easier, as it doesn't require any scripting; and indeed
the default configuration is an example of such a plain-text theme.
However, the latter allows for more flexibility, as one can define
callbacks that should be run when the battery level reaches a certain
threshold.
.PP
Themes, whether perl themes or plain-text themes, are built through
\&'steps', which are defined in a single line. In a plain-text config
file, such a line looks like this:
.PP
.Vb 1
\& discharging = 2:missing.png:low.png, 10:low.png, 100:full.png
.Ve
.PP
This defines three steps. The highest step shows \*(L"full.png\*(R" when the
battery level is between 11% and 100% (inclusive); the second step shows
\&\*(L"low.png\*(R" when the battery level is between 3% and 10% (inclusive); and
the third step will alternate between \*(L"missing.png\*(R" and \*(L"low.png\*(R" on
three-second intervals, when the battery is between 0% and 2%.
.PP
Since the line starts with \*(L"discharging\*(R", these steps are used when the
system is running on battery power. A similar line of steps could be
defined for when the battery is charging:
.PP
.Vb 1
\& charging = 0:empty\-charging.png, 10:low\-charging.png, 100: full\-charging.png
.Ve
.PP
this will show \*(L"empty\-charging.png\*(R" when the battery is at 0% (exactly),
\&\*(L"low\-charging.png\*(R" between 1% and 10% (inclusive), and \*(L"full\-charging.png\*(R"
at 11% and above.
.PP
Note that ordering is significant: steps should be defined from low to
high.
.PP
To complete the theme configuration, we must add a few more items:
.PP
.Vb 5
\& [mytheme]
\& steps = 3
\& dir = /home/wouter/.fdpowermon/mytheme\-icons
\& charging = 0:empty\-charging.png, 10:low\-charging.png, 100: full\-charging.png
\& discharging = 2:missing.png:low.png, 10:low.png, 100:full.png
.Ve
.PP
This defines a theme called \*(L"mytheme\*(R" which has three steps, and will
look for images in the directory
\&\*(L"/home/wouter/.fdpowermon/mytheme\-icons\*(R". It is not possible to define a theme
which has a different number of steps for the charging phase than it does for
the discharging phase; if you want that, just define (an) extra step(s) for the
phase that you would like to have less steps, which has the same icon as the
step above or below.
.PP
Note that ordering is significant here, too; the \*(L"steps\*(R" line should
appear before any \*(L"charging\*(R" or \*(L"discharging\*(R" lines (this was not the
case in fdpowermon 1.7 or below).
.PP
If more than one theme is configured, fdpowermon will, by default, use
the last theme defined in the per-user configuration, or (if no per-user
configuration file exists) the last theme defined in the system-wide
configuration.
.PP
Perl theme config files can use fdpowermon::theme::make_default to
change the default theme.
.SH "PERL API"
.IX Header "PERL API"
.ie n .SS "@warnings"
.el .SS "\f(CW@warnings\fP"
.IX Subsection "@warnings"
The \f(CW@fdpowermon::theme::warnings\fR array can be used to specify at which levels
fdpowermon should issue a standard warning. The default is (10, 5, 1), which
means to issue a warning at a level of 10%, 5%, and 1%. Note that if the
battery runs flat at a particularly fast pace, the level may have reduced even
further than that before the warning is issued; also, fdpowermon will issue a
warning immediately when power is removed from the machine and the power is
below the first level.
.PP
To make fdpowermon always issue a warning when power is removed, set
this to something like (100, 10, 5, 1). To make fdpowermon issue
warnings at 20%, 10%, and 5%, set this to (20, 10, 5).
.PP
Note that it is not possible to change the text of the warning. If you
want that, see the fdpowermon::theme::warning sub, and use an event.
.ie n .SS "$use_notify"
.el .SS "\f(CW$use_notify\fP"
.IX Subsection "$use_notify"
The variable \f(CW$fdpowermon::theme::use_notify\fR can be used to decide whether
to use a libnotify message (if set to a nonzero value), or a dialog
window (if set to a value which evaluates to zero).
.PP
The default is to use libnotify if the libnotify Glib introspection data
is installed, or a dialog box if not. Because dialog boxes can steal the
focus and therefore wreak havoc with the user's work, using libnotify is
strongly recommended by the author.
.PP
Note that if you set the variable to nonzero explicitly, then the test
whether or not the Glib introspection data is installed will be ignored.
Make sure it's available in that case!
.SS "new"
.IX Subsection "new"
Create a new fdpowermon theme. Returns a blessed reference; e.g.,
.PP
.Vb 1
\& my $theme = new fdpowermon::theme;
.Ve
.ie n .SS "$theme\->set_stepcount($count)"
.el .SS "\f(CW$theme\fP\->set_stepcount($count)"
.IX Subsection "$theme->set_stepcount($count)"
Set the number of steps in the theme. Note that an fdpowermon theme must
have an equal number of steps in both the \*(L"charging\*(R" and the
\&\*(L"discharging\*(R" direction.
.PP
Should be called before calling set_charging, set_discharging, or
parse_step.
.ie n .SS "$theme\->set_dir($dir)"
.el .SS "\f(CW$theme\fP\->set_dir($dir)"
.IX Subsection "$theme->set_dir($dir)"
Set the base directory used for icon file names.
.ie n .SS "$theme\->set_charging(\e@elements)"
.el .SS "\f(CW$theme\fP\->set_charging(\e@elements)"
.IX Subsection "$theme->set_charging(@elements)"
Set the icons that should be shown when the battery is charging. The
argument should be created by way of the parse_step method.
.ie n .SS "$theme\->set_discharging(\e@elements)"
.el .SS "\f(CW$theme\fP\->set_discharging(\e@elements)"
.IX Subsection "$theme->set_discharging(@elements)"
Set the icons that should be shown when the battery is discharging. The
argument should be created by way of the parse_step method.
.ie n .SS "$theme\->parse_step($defs)"
.el .SS "\f(CW$theme\fP\->parse_step($defs)"
.IX Subsection "$theme->parse_step($defs)"
Parses the given string into something that can be passed on to
set_charging or set_discharging. The definitions should be in the steps
format, described above, without the leading \f(CW\*(C` charging = \*(C'\fR or
\&\f(CW\*(C` discharging = \*(C'\fR.
.PP
While this method returns an arrayref that can be inspected and
(probably) modified, themes that want to be forward-compatible should
treat it as an opaque data structure.
.ie n .SS "$theme\->set_event($step, \e&callback, 'd')"
.el .SS "\f(CW$theme\fP\->set_event($step, \e&callback, 'd')"
.IX Subsection "$theme->set_event($step, &callback, 'd')"
Update the theme so the sub 'callback' is executed when we're discharging
and we reach \f(CW$step\fR for the first time. To set an event when charging
instead, pass a 'c' as the third argument.
.PP
Note that the steps are arrays, and are therefore 0\-based; the lowest-numbered
items are the lowest-level steps.
.PP
When the event triggers, the callback routine will be passed two
arguments: the first is the current battery level (in percent); the
second is a number denoting whether the battery is currently charging
(1) or discharging (0). In case the parsing of the \s-1ACPI\s0 command fails,
however, the second argument may be undef; you should prepare for this
possibility. Note that fdpowermon itself handles that case by assuming
the battery is charging; you may or may not wish to do the same.
.ie n .SS "$theme\->register($name)"
.el .SS "\f(CW$theme\fP\->register($name)"
.IX Subsection "$theme->register($name)"
Registers a theme under a given name. If a theme already exists under
that name, it is replaced.
.SS "make_default($name)"
.IX Subsection "make_default($name)"
Makes a theme with a given name be the default theme.
.SS "get_theme($name)"
.IX Subsection "get_theme($name)"
Looks up a theme with the given name; e.g.,
.PP
.Vb 1
\& my $theme = fdpowermon::theme::get_theme("default");
.Ve
.SS "warning($message)"
.IX Subsection "warning($message)"
Produce a warning, either using libnotify, or using a dialog box:
.PP
.Vb 1
\& fdpowermon::theme::warning($message);
.Ve
.PP
See the documentation on \f(CW$fdpowermon::theme::use_notify\fR above for
details on which implementation is chosen.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
For a full .cfg theme example, look above.
.PP
To construct the same theme fully from perl, you'd do something like this:
.PP
.Vb 5
\& my $theme = new fdpowermon::theme;
\& $theme\->set_stepcount(3);
\& $theme\->set_dir("/home/wouter/.fdpowermon/mytheme\-icons");
\& $theme\->set_charging($theme\->parse_step("0:empty\-charging.png, 10:low\-charging.png, 100: full\-charging.png"));
\& $theme\->set_discharging($theme\->parse_step("2:missing.png:low.png, 10:low.png, 100:full.png"));
.Ve
.PP
(note, as a perl theme, this would go in theme.pl, not theme.cfg; see
above for possible locations for perl themes)
.PP
However, unless you want to build the theme dynamically, doing it this
way is not recommended. Instead, you would build the theme from a .cfg
file, and possibly modify it from perl. Let's say you wish to add an
event to suspend the system when the power gets low; in that case, you'd
do something like this:
.PP
.Vb 3
\& sub suspend {
\&        system("sudo pm\-suspend");
\& }
\&
\& my $theme = fdpowermon::theme::get_theme("mytheme");
\& $theme\->set_event(0, \e&suspend, \*(Aqd\*(Aq);
.Ve
.PP
This would call the 'suspend' sub when the battery is discharging and we
reach the lowest step (in the above example, that would be when the
battery reaches 10%; you might want to do that somewhat later). This
\&'suspend' sub simply calls the \*(L"pm-suspend\*(R" program, with sudo, to
suspend the system.