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