fixed gentoo bug# 113219
[monky] / src / conky.h
1 /*
2  * Conky, a system monitor, based on torsmo
3  *
4  * This program is licensed under BSD license, read COPYING
5  *
6  *  $Id$
7  */
8
9 #ifndef _conky_h_
10 #define _conky_h_
11
12 #if defined(HAS_MCHECK_H)
13 #include <mcheck.h>
14 #endif /* HAS_MCHECK_H */
15 #include "config.h"
16 #include <sys/utsname.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <locale.h>
20 #include <langinfo.h>
21 #include <wchar.h>
22 #if defined(__FreeBSD__)
23 #include <sys/param.h>
24 #include <sys/mount.h>
25 #include <sys/ucred.h>
26 #endif /* __FreeBSD__ */
27
28 #ifdef X11
29 #if defined(HAVE_CAIRO_H) && defined(HAVE_CAIRO_XLIB_H) && defined(WANT_CAIRO)
30 #define CAIRO
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33 #include <cairo.h>
34 #include <cairo-xlib.h>
35 #endif
36 #endif /* X11 */
37
38 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
39 #include <machine/apm_bios.h>
40 #endif /* __FreeBSD__ */
41
42 #define TOP_CPU 1
43 #define TOP_NAME 2
44 #define TOP_PID 3
45 #define TOP_MEM 4
46
47 #define TEXT_BUFFER_SIZE 1024
48
49 #include <sys/socket.h>
50
51 #define ERR(s, varargs...) \
52 fprintf(stderr, "Conky: " s "\n", ##varargs)
53
54 /* critical error */
55 #define CRIT_ERR(s, varargs...) \
56 { fprintf(stderr, "Conky: " s "\n", ##varargs);  exit(EXIT_FAILURE); }
57
58 struct i8k_struct {
59         char *version;
60         char *bios;
61         char *serial;
62         char *cpu_temp;
63         char *left_fan_status;
64         char *right_fan_status;
65         char *left_fan_rpm;
66         char *right_fan_rpm;
67         char *ac_status;
68         char *buttons_status;
69 };
70
71 struct i8k_struct i8k;
72
73 struct net_stat {
74         const char *dev;
75         int up;
76         long long last_read_recv, last_read_trans;
77         long long recv, trans;
78         double recv_speed, trans_speed;
79         struct sockaddr addr;
80         int linkstatus;
81         double net_rec[15], net_trans[15];
82 };
83
84 unsigned int diskio_value;
85
86 struct fs_stat {
87         char *path;
88         long long size;
89         long long avail;
90 };
91
92 /*struct cpu_stat {
93         unsigned int user, nice, system, idle, iowait, irq, softirq;
94         int cpu_avg_samples;
95 };*/
96
97 #ifdef MPD
98 struct mpd_s {
99         char *title;
100         char *artist;
101         char *album;
102         char *status;
103         char *random;
104         char *repeat;
105         char *track;
106         int volume;
107         unsigned int port;
108         char host[128];
109         float progress;
110         int bitrate;
111         int length;
112         int elapsed;
113 };
114 #endif
115
116 #ifdef TCP_PORT_MONITOR
117 #include "libtcp-portmon.h"
118 #define MIN_PORT_MONITORS_DEFAULT 16
119 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
120 #endif
121
122 enum {
123         INFO_CPU = 0,
124         INFO_MAIL = 1,
125         INFO_MEM = 2,
126         INFO_NET = 3,
127 #ifdef SETI
128         INFO_SETI = 4,
129 #endif
130         INFO_PROCS = 5,
131         INFO_RUN_PROCS = 6,
132         INFO_UPTIME = 7,
133         INFO_BUFFERS = 8,
134         INFO_FS = 9,
135         INFO_I2C = 10,
136         INFO_MIXER = 11,
137         INFO_LOADAVG = 12,
138         INFO_UNAME = 13,
139         INFO_FREQ = 14,
140 #ifdef MPD
141         INFO_MPD = 15,
142 #endif
143         INFO_TOP = 16,
144 #ifdef MLDONKEY
145         INFO_MLDONKEY = 18,
146 #endif
147         INFO_WIFI = 19,
148         INFO_DISKIO = 20,
149         INFO_I8K = 21,
150 #ifdef TCP_PORT_MONITOR
151         INFO_TCP_PORT_MONITOR = 22,
152 #endif
153 };
154
155
156 #ifdef MPD
157 #include "libmpdclient.h"
158 #endif
159
160 volatile int g_signal_pending;
161
162 struct information {
163         unsigned int mask;
164
165         struct utsname uname_s;
166
167         char freq[10];
168
169         double uptime;
170
171         /* memory information in kilobytes */
172         unsigned long mem, memmax, swap, swapmax;
173         unsigned long bufmem, buffers, cached;
174
175         unsigned int procs;
176         unsigned int run_procs;
177
178         float *cpu_usage;
179         /*      struct cpu_stat cpu_summed; what the hell is this? */
180         unsigned int cpu_count;
181         unsigned int cpu_avg_samples;
182
183         unsigned int net_avg_samples;
184
185         float loadavg[3];
186
187         int new_mail_count, mail_count;
188 #ifdef SETI
189         float seti_prog;
190         float seti_credit;
191 #endif
192 #ifdef MPD
193         struct mpd_s mpd;
194         mpd_Connection *conn;
195 #endif
196         struct process *cpu[10];
197         struct process *memu[10];
198         struct process *first_process;
199         unsigned long looped;
200 #ifdef TCP_PORT_MONITOR
201         tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
202 #endif
203 };
204
205 int out_to_console;
206
207 int top_cpu;
208 int top_mem;
209
210 int use_spacer;
211
212 char tmpstring1[TEXT_BUFFER_SIZE];
213 char tmpstring2[TEXT_BUFFER_SIZE];
214
215 #ifdef X11
216 /* in x11.c */
217
218 #include <X11/Xlib.h>
219 #include <X11/Xlib.h>
220 #include <X11/Xatom.h>
221
222 #ifdef XFT
223 #include <X11/Xft/Xft.h>
224 #endif
225
226 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
227 #define XDBE
228 #include <X11/extensions/Xdbe.h>
229 #endif
230
231 #define ATOM(a) XInternAtom(display, #a, False)
232
233 struct conky_window {
234         Window window;
235         Drawable drawable;
236         GC gc;
237 #ifdef XDBE
238         XdbeBackBuffer back_buffer;
239 #endif
240 #ifdef XFT
241         XftDraw *xftdraw;
242 #endif
243
244         int width;
245         int height;
246 #ifdef OWN_WINDOW
247         int x;
248         int y;
249 #endif
250 };
251
252 #ifdef XDBE
253 extern int use_xdbe;
254 #endif
255
256
257 #ifdef XFT
258 extern int use_xft;
259 #endif
260
261 extern Display *display;
262 extern int display_width;
263 extern int display_height;
264 extern int screen;
265
266 extern int workarea[4];
267
268 extern struct conky_window window;
269
270 void init_X11();
271 #if defined OWN_WINDOW
272 void init_window(int use_own_window, char* wm_class_name, int width, int height, int on_bottom, int fixed_pos, int set_trans, int back_colour, char * nodename);
273 #else
274 void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour, char * nodename);
275 #endif
276 void create_gc();
277 void set_transparent_background(Window win);
278 long get_x11_color(const char *);
279
280 #endif /* X11 */
281
282 /* in common.c */
283
284 /* struct that has all info */
285 struct information info;
286
287 void signal_handler(int);
288 void reload_config(void);
289 void clean_up(void);
290
291 void update_uname();
292 double get_time(void);
293 FILE *open_file(const char *file, int *reported);
294 void variable_substitute(const char *s, char *dest, unsigned int n);
295 void format_seconds(char *buf, unsigned int n, long t);
296 void format_seconds_short(char *buf, unsigned int n, long t);
297 struct net_stat *get_net_stat(const char *dev);
298
299 void update_stuff();
300
301 int round_to_int(float f);
302
303 #define SET_NEED(a) need_mask |= 1 << (a)
304 extern unsigned long long need_mask;
305
306 extern double current_update_time, last_update_time;
307
308 extern int no_buffers;
309
310 /* system dependant (in linux.c) */
311
312 void update_diskio(void);
313 void prepare_update(void);
314 void update_uptime(void);
315 void update_meminfo(void);
316 void update_net_stats(void);
317 void update_wifi_stats(void);
318 void update_cpu_usage(void);
319 void update_total_processes(void);
320 void update_running_processes(void);
321 void update_i8k(void);
322 void get_freq( char *, size_t, char *, int ); /* pk */
323 void get_freq_dynamic( char *, size_t, char *, int ); /* pk */
324 void update_load_average();
325 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
326                     char *devtype);
327 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
328
329 void get_adt746x_cpu( char *, size_t ); /* pk */
330 void get_adt746x_fan( char *, size_t ); /* pk */
331 unsigned int get_diskio(void);
332
333 int open_acpi_temperature(const char *name);
334 double get_acpi_temperature(int fd);
335 void get_acpi_ac_adapter( char *, size_t ); /* pk */
336 void get_acpi_fan( char *, size_t ); /* pk */
337 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
338
339 struct process {
340         struct process *next;
341         struct process *previous;
342
343         pid_t pid;
344         char *name;
345         float amount;
346         unsigned long user_time;
347         unsigned long total;
348         unsigned long kernel_time;
349         unsigned long previous_user_time;
350         unsigned long previous_kernel_time;
351         unsigned int vsize;
352         unsigned int rss;
353         unsigned int time_stamp;
354         unsigned int counted;
355         unsigned int changed;
356         float totalmem;
357 };
358
359 void update_top();
360 void free_all_processes();
361 struct process *get_first_process();
362
363 /* fs-stuff is possibly system dependant (in fs.c) */
364
365 void update_fs_stats(void);
366 struct fs_stat *prepare_fs_stat(const char *path);
367 void clear_fs_stats(void);
368
369 /* in mixer.c */
370
371 int mixer_init(const char *);
372 int mixer_get_avg(int);
373 int mixer_get_left(int);
374 int mixer_get_right(int);
375
376 /* in mail.c */
377
378 extern char *current_mail_spool;
379
380 void update_mail_count();
381
382 /* in seti.c */
383
384 #ifdef SETI
385 extern char *seti_dir;
386
387 void update_seti();
388 #endif
389
390 /* in freebsd.c */
391 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
392 int apm_getinfo(int fd, apm_info_t aip);
393 char *get_apm_adapter(void);
394 char *get_apm_battery_life(void);
395 char *get_apm_battery_time(void);
396 #endif
397 /* in mpd.c */
398
399 #ifdef MPD
400 void update_mpd();
401 #endif
402
403 #ifdef MLDONKEY
404 /* in mldonkey.c */
405 typedef long long int64;
406 /* The info necessary to connect to mldonkey. login and password can be NULL. */
407 typedef struct mldonkey_config {
408         char *mldonkey_hostname;
409         int mldonkey_port;
410         char *mldonkey_login;
411         char *mldonkey_password;
412 } mldonkey_config;
413
414 /* The MLDonkey status returned */
415 typedef struct mldonkey_info {
416         int64 upload_counter;
417         int64 download_counter;
418         int nshared_files;
419         int64 shared_counter;
420         int tcp_upload_rate;
421         int tcp_download_rate;
422         int udp_upload_rate;
423         int udp_download_rate;
424         int ndownloaded_files;
425         int ndownloading_files;
426         int nconnected_networks;
427         int connected_networks[1];
428 } mldonkey_info;
429
430 extern mldonkey_info mlinfo;
431 extern mldonkey_config mlconfig;
432
433 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
434 #endif
435
436 /* in linux.c */
437
438 /* nothing to see here */
439
440 /* in cairo.c */
441
442 extern int do_it(void);
443
444 #endif