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