2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <X11/extensions/shape.h>
35 #include <sys/signal.h>
38 /* those includes are needed by alarm */
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
45 #define XPM_NAME wmlaptop_xpm
47 typedef unsigned char bool;
61 typedef unsigned char u_int8
;
62 typedef unsigned short u_int16
;
63 typedef unsigned int u_int32
;
66 /****************************************
67 * Every global variable of the program *
68 * is declared in main.c, but here is *
69 * is declared as 'extern' *
70 ****************************************/
71 extern char **wmlaptop_xpm
;
73 /* it keeps track of passing time:
74 * updated with time(NULL) at every cycle */
75 extern time_t secondsCounter
;
81 /*****************************************************************
82 * For every battery present in the system will be allocated a *
83 * structure containing following informations *
85 * present: true if battery is present, false otherwise *
86 * error: true if reading the info's file report an error: *
87 * this battery wont be used until present will *
88 * become false (only ACPI) *
89 * counter: the counter for the battery (each battery has *
90 * unique number ) (only ACPI) *
91 * stateFile: file path where to read information about actual *
92 * state of the battery (only ACPI) *
93 * infoFile: file path where to read general informations *
94 * about the battery (only ACPI ) *
95 * capacity: battery capacity (only ACPI) *
96 * actualState: remaining battery capacity (only ACPI) *
97 * percentage: remaining battery percentage (calculated with *
98 * actualState divided by capacity with ACPI *
99 * reading /proc/apm con APM) *
100 * useLFC: use 'last full capacity' tag instead of 'design *
101 * capacity' reading the information from info file *
103 * filler: pointer to the function that will fill the *
104 * fields (different if you're using APM or ACPI) *
105 *****************************************************************/
106 typedef struct battery_str
* battery
;
119 bool(*filler
)(battery
);
122 /*****************************************************************
123 * this structure is used for keeping track of all batteries and *
124 * it calculate estimated remaining time *
126 * nBatt: it shows the number of elements of *
127 * BatteryVector; it is also the number of *
128 * installed batteries, in case you're using ACPI *
129 * batteryVector: vector containing all single battery *
130 * informations (ACPI) or all batteries (APM) *
131 * percentage: average of all batteries (nBatt) presents in *
132 * in batteryVector. it's the value that will be *
133 * showed in the dockapp *
134 * remainingTime: remaining battery time, estimated calculating *
135 * how much has power the laptop has used in the *
136 * last ten minutes (this value could be modified)*
137 * isCharging: true if battery charger is plugged in. *
138 * updater: pointer to function that is called *
139 * (periodically) to update battery status. *
140 * function that points is different if you're *
141 * using ACPI or APM *
142 *****************************************************************/
143 extern struct power_str powerState
;
148 battery
* batteryVector
;
150 u_int16 remainingTime
;
156 extern double powerrate
;
157 extern double capacity
;
161 *****************************************************************
162 * wmlaptop let the user to change cpu frequency on the fly, by *
163 * clicking on two arrows, but it can also handle by itself this *
164 * responibility according with cpu load. it can decrease or *
165 * decrease cpu frequency when we're not doing an heavy use of it*
166 * or increase it at its maximum when cpu load is at 100%. *
167 * in every case wmlaptop shows on its display the actual cpu *
168 * load, read and stored in the global variable cpuLoad at every *
170 *****************************************************************/
171 extern u_int8 cpuLoad
;
173 /*****************************************************************
174 * global variable cpuState is a structure of this type, it *
175 * stores cpu status. here are the fields explained: *
176 * setFreqFile:pointer to the path to use for writing/reading *
178 * actualFreq: updated at every events cycle, it takes as value *
179 * the actual cpu frequency *
180 * Temp: the CPU temperature *
181 *****************************************************************/
189 extern struct cpuFreq cpuState
;
193 *****************************************************************
194 * code taken here and there for creating a dockapp with xlib *
195 *****************************************************************/
201 XpmAttributes attributes
;
204 /* the X connection */
205 extern Display
* display
;
207 extern Window iconwin
;
212 extern XSizeHints mysizehints
;
213 extern XWMHints mywmhints
;
216 extern struct XpmIcon wmgen
;
217 extern Pixmap pixmask
;
220 extern char wmlaptop_mask_bits
[64 * 64];
221 extern int wmlaptop_mask_width
;
222 extern int wmlaptop_mask_height
;
228 #define MAX_MOUSE_REGION 3
230 #define MREGION_AUTOFREQ 0
231 #define MREGION_MINFREQ 1
232 #define MREGION_MAXFREQ 2
242 extern struct mouseRegion mouse_region
[MAX_MOUSE_REGION
];
251 #include "autoscript.h"
257 int main(int, char **);
259 /* this one takes as argument the exit's code, but
260 * before exiting, it frees any allocated memory */
261 void free_and_exit(int);
263 void usage(char *, char *);
269 void setArgs(int, char **);
271 /* this shows the default compiled settings and exit */
272 void defaultSettings(void);
274 #define ARGSDEF_LEAVE 0
276 extern int cpu_update
;
277 extern int battery_update
;
278 extern int power_update
;
279 extern int temp_update
;
280 extern int session_idle
;
282 float get_session_idle_time(Display
*display
);
284 extern char *XDisplay
;
286 extern char auto_shutdown
;
287 extern short shutdown_delay
;
288 extern char auto_alarm
;
289 extern bool dontBlink100
;
292 /* use keyboard backlight control on apple laptops */
295 extern int manage_backlight
;
296 int get_screen_brightness(void);
298 /* the QUIET macro */
299 #define PRINTQ( output, frm, args... ) \
302 if (quiet == false) \
303 fprintf( output, frm, ##args ); \