aboutsummaryrefslogtreecommitdiff
path: root/xbattext.ms
blob: 34b5f620003a1d434bdfd5ee4cc8807cf87ff327 (plain)
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
.so /home/john/prj/re/re.tmac
.nr St 6n
.TL
.BI xbattext ,
an X11 battery monitor for NetBSD
.AU
John Ankarström
.AB
.LP
.I xbattext
is a simple X11 program that displays, in text,
the current battery level.
Its source code serves as a good introduction to X11 programnming.
It is short, simple and easy to follow,
as it accounts only for a single system \(en NetBSD.
It makes use of both Xt (X toolkit intrinsics) and Xm (Motif),
two of the most popular X libraries.
It demonstrates how to access resources from
.I ~/.Xdefaults ,
how to display text in various colors and fonts and
how to set timers outside of the main event loop
to perform asynchronous tasks that are not triggered by user interaction.
.PP
This document is a commented version of the
.I xbattext
source code.
It is generated with
.I re ,
a reference-based literate programming system available at the address
http://git.\:ankarstrom.se/re/.
.AE
.Re xbattext.c:/^#include/
.LP
.I Xm/Label.h
contains the definitions for Motif's label widget,
which is used to display the text.
That headerf file, in turn, includes
.I X11/Xlib.h
for us.
.PP
.I machine/apmvar.h
is needed in order to inspect the battery status on NetBSD.
.Re xbattext.c:/^struct _res/
.LP
Two structures are created to access the application's resources:
.I res ,
which will hold the values of the resources, and
.I res_opts ,
which defines how those resources should be accessed.
.PP
The
.I res
structure is going to be filled by the function
.I XtGetApplicationResources
using the information defined in
.I res_opts .\**
.FS
For more information about resource management and the structure of the
.I XtResource
type, see
.nh
http://lesstif.sourceforge.net/doc/super-ux/g1ae03e/part1/chap9.html.
.hy
.FE
.Re xbattext.c:/"alertFontList"/
\&
.Re xbattext.c:/"chargeForeground"/
.LP
.I wargs
is used by
.I XtSetArg ,
which stores arguments in it, and
.I XtSetValues ,
which sets new values for a widget
according to the arguments stored in it.
.PP
.I alert
and
.I charge
are boolean variables that are set to true
whenever
.I xbattext
detects that the battery is low or
that the AC adapter is plugged in.
.PP
.I timer
contains the identifier for the current timer.
.Re xbattext.c:/^main/