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