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