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