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