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