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