Clean up handling of global variables
[wmlaptop2.git] / src / main.h
blobf4c6f8acea65d83e1499b8265635e3d343ecb3f6
1 /*
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.
17 #ifndef __MAIN_H__
18 #define __MAIN_H__
20 #include "version.h"
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <unistd.h>
27 #include <time.h>
28 #include <errno.h>
29 #include <dirent.h>
31 #include <X11/Xlib.h>
32 #include <X11/xpm.h>
33 #include <X11/extensions/shape.h>
35 #include <sys/signal.h>
36 #include <sys/wait.h>
38 /* those includes are needed by alarm */
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <linux/kd.h>
45 #define XPM_NAME wmlaptop_xpm
47 typedef unsigned char bool;
49 #ifndef true
50 # define true 1
51 #endif
53 #ifndef false
54 # define false 0
55 #endif
57 #define ERROR 1
58 #define SUCCESS 0
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;
77 /********************
78 * BATTERIES' STUFF *
79 ********************/
81 /*****************************************************************
82 * For every battery present in the system will be allocated a *
83 * structure containing following informations *
84 * *
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 *
102 * (only ACPI) *
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;
108 struct battery_str
110 bool present;
111 bool error;
112 u_int8 counter;
113 char stateFile[52];
114 char infoFile[52];
115 double capacity;
116 u_int32 actualState;
117 u_int16 percentage;
118 bool useLFC;
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;
145 struct power_str
147 u_int8 nBatt;
148 battery * batteryVector;
149 u_int8 percentage;
150 u_int16 remainingTime;
151 bool isCharging;
152 // double rate;
153 void(*updater)();
156 extern double powerrate;
157 extern double capacity;
159 /*******************
160 * CPUS' STUFF *
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 *
169 * events cycle. *
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 *
177 * cpu frequency *
178 * actualFreq: updated at every events cycle, it takes as value *
179 * the actual cpu frequency *
180 * Temp: the CPU temperature *
181 *****************************************************************/
182 struct cpuFreq
184 u_int32 actualFreq;
185 char * setFreqFile;
186 int Temp;
189 extern struct cpuFreq cpuState;
191 /*******************
192 * XLIB' STUFF *
193 *****************************************************************
194 * code taken here and there for creating a dockapp with xlib *
195 *****************************************************************/
197 struct XpmIcon
199 Pixmap pixmap;
200 Pixmap mask;
201 XpmAttributes attributes;
204 /* the X connection */
205 extern Display * display;
206 extern Window Root;
207 extern Window iconwin;
208 extern Window win;
209 extern int screen;
210 extern int x_fd;
211 extern int d_depth;
212 extern XSizeHints mysizehints;
213 extern XWMHints mywmhints;
214 extern GC NormalGC;
215 extern XEvent e;
216 extern struct XpmIcon wmgen;
217 extern Pixmap pixmask;
219 /* the main image */
220 extern char wmlaptop_mask_bits[64 * 64];
221 extern int wmlaptop_mask_width;
222 extern int wmlaptop_mask_height;
224 /*****************/
225 /* Mouse Regions */
226 /*****************/
228 #define MAX_MOUSE_REGION 3
230 #define MREGION_AUTOFREQ 0
231 #define MREGION_MINFREQ 1
232 #define MREGION_MAXFREQ 2
234 struct mouseRegion
236 u_int8 top;
237 u_int8 bottom;
238 u_int8 left;
239 u_int8 right;
242 extern struct mouseRegion mouse_region[MAX_MOUSE_REGION];
245 #include "main.h"
246 #include "init.h"
247 #include "event.h"
248 #include "draw.h"
249 #include "battery.h"
250 #include "cpu.h"
251 #include "autoscript.h"
254 /*******************
255 * alpha and omega *
256 *******************/
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 *);
264 void version();
267 * wmlaptop arguments
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;
290 extern bool quiet;
292 /* use keyboard backlight control on apple laptops */
293 extern int apple;
295 extern int manage_backlight;
296 int get_screen_brightness(void);
298 /* the QUIET macro */
299 #define PRINTQ( output, frm, args... ) \
301 do { \
302 if (quiet == false) \
303 fprintf( output, frm, ##args ); \
304 } while ( 0 )
306 #endif