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