* Fixed issue with SIGPIPE and mpd
[monky] / src / conky.h
1 /*
2  * Conky, a system monitor, based on torsmo
3  *
4  * Any original torsmo code is licensed under the BSD license
5  *
6  * All code written since the fork of torsmo is licensed under the GPL
7  *
8  * Please see COPYING for details
9  *
10  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11  * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
12  * All rights reserved.
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
25  *
26  *  $Id$
27  */
28
29 #ifndef _conky_h_
30 #define _conky_h_
31
32 #if defined(HAS_MCHECK_H)
33 #include <mcheck.h>
34 #endif /* HAS_MCHECK_H */
35 #include "config.h"
36 #include <sys/utsname.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <locale.h>
41 #include <langinfo.h>
42 #include <wchar.h>
43 #include <sys/param.h>
44 #if defined(__FreeBSD__)
45 #include <sys/mount.h>
46 #include <sys/ucred.h>
47 #include <fcntl.h>
48 #include <kvm.h>
49 #endif /* __FreeBSD__ */
50
51 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
52 #include <machine/apm_bios.h>
53 #endif /* __FreeBSD__ */
54
55 #if defined(__OpenBSD__)
56 #include <sys/sysctl.h>
57 #include <sys/sensors.h>
58 #include <machine/apmvar.h>
59 #endif /* __OpenBSD__ */
60
61 #ifdef AUDACIOUS
62 #include "audacious.h"
63 #endif
64
65 #ifdef XMMS2
66 #include <xmmsclient/xmmsclient.h>
67 #endif
68
69 #ifdef RSS
70 #include "prss.h"
71 #endif
72
73 #include "mboxscan.h"
74 #include "timed_thread.h"
75
76 #define TOP_CPU 1
77 #define TOP_NAME 2
78 #define TOP_PID 3
79 #define TOP_MEM 4
80
81 #define TEXT_BUFFER_SIZE 1280
82 #define P_MAX_SIZE ((TEXT_BUFFER_SIZE * 4) - 2) 
83 extern unsigned int text_buffer_size;
84
85 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
86 #define MAX_SPECIALS_DEFAULT 512
87
88 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
89 #define MAX_USER_TEXT_DEFAULT 16384
90
91 #include <sys/socket.h>
92
93 #define ERR(s, varargs...) \
94 fprintf(stderr, "Conky: " s "\n", ##varargs)
95
96 /* critical error */
97 #define CRIT_ERR(s, varargs...) \
98 { fprintf(stderr, "Conky: " s "\n", ##varargs);  exit(EXIT_FAILURE); }
99
100 struct i8k_struct {
101         char *version;
102         char *bios;
103         char *serial;
104         char *cpu_temp;
105         char *left_fan_status;
106         char *right_fan_status;
107         char *left_fan_rpm;
108         char *right_fan_rpm;
109         char *ac_status;
110         char *buttons_status;
111 };
112
113 struct i8k_struct i8k;
114
115 struct net_stat {
116         const char *dev;
117         int up;
118         long long last_read_recv, last_read_trans;
119         long long recv, trans;
120         double recv_speed, trans_speed;
121         struct sockaddr addr;
122         double net_rec[15], net_trans[15];
123         // wireless extensions
124         char essid[32];
125         char bitrate[16];
126         char mode[16];
127         char ap[18];
128         int link_qual;
129         int link_qual_max;
130 };
131
132 unsigned int diskio_value;
133 unsigned int diskio_read_value;
134 unsigned int diskio_write_value;
135
136 struct fs_stat {
137         char *path;
138         long long size;
139         long long avail;
140         long long free;
141 };
142
143 struct mail_s {                 // for imap and pop3
144         unsigned long unseen;
145         unsigned long messages;
146         unsigned long used;
147         unsigned long quota;
148         unsigned long port;
149         float interval;
150         double last_update;
151         char host[128];
152         char user[128];
153         char pass[128];
154         char command[1024];
155         char folder[128];
156         char secure;
157         timed_thread *p_timed_thread;
158 } mail;
159
160 /*struct cpu_stat {
161         unsigned int user, nice, system, idle, iowait, irq, softirq;
162         int cpu_avg_samples;
163 };*/
164
165 #ifdef MPD
166 struct mpd_s {
167         char *title;
168         char *artist;
169         char *album;
170         char *status;
171         char *random;
172         char *repeat;
173         char *track;
174         char *name;
175         char *file;
176         int volume;
177         unsigned int port;
178         char host[128];
179         char password[128];
180         float progress;
181         int bitrate;
182         int length;
183         int elapsed;
184         int max_title_len;              /* e.g. ${mpd_title 50} */
185 };
186
187 #endif
188
189 #ifdef XMMS2
190 struct xmms2_s {
191     char* artist;
192     char* album;
193     char* title;
194     char* genre;
195     char* comment;
196     char* decoder;
197     char* transport;
198     char* url;
199     char* date;
200     int tracknr;
201     int bitrate;
202     unsigned int id;
203     int duration;
204     int elapsed;
205     float size;
206
207     float progress;
208     char* status;
209 };
210 #endif
211
212 #ifdef AUDACIOUS
213 struct audacious_s {
214         audacious_t items;              /* e.g. items[AUDACIOUS_STATUS] */
215         int max_title_len;              /* e.g. ${audacious_title 50} */
216         timed_thread *p_timed_thread;
217 };
218 #endif
219
220 #ifdef BMPX
221 void update_bmpx();
222 struct bmpx_s {
223         char *title;
224         char *artist;
225         char *album;
226         char *uri;
227         int bitrate;
228         int track;
229 };
230 #endif
231
232 void update_entropy();
233 struct entropy_s {
234         unsigned int entropy_avail;
235         unsigned int poolsize;
236 };
237
238 #ifdef TCP_PORT_MONITOR
239 #include "libtcp-portmon.h"
240 #define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256
241 #endif
242
243 enum {
244         INFO_CPU = 0,
245         INFO_MAIL = 1,
246         INFO_MEM = 2,
247         INFO_NET = 3,
248         INFO_PROCS = 4,
249         INFO_RUN_PROCS = 5,
250         INFO_UPTIME = 6,
251         INFO_BUFFERS = 7,
252         INFO_FS = 8,
253         INFO_SYSFS = 9,
254         INFO_MIXER = 10,
255         INFO_LOADAVG = 11,
256         INFO_UNAME = 12,
257         INFO_FREQ = 13,
258 #ifdef MPD
259         INFO_MPD = 14,
260 #endif
261         INFO_TOP = 15,
262         INFO_WIFI = 16,
263         INFO_DISKIO = 17,
264         INFO_I8K = 18,
265 #ifdef TCP_PORT_MONITOR
266   INFO_TCP_PORT_MONITOR = 19,
267 #endif
268 #ifdef AUDACIOUS
269         INFO_AUDACIOUS = 20,
270 #endif
271 #ifdef BMPX
272         INFO_BMPX = 21,
273 #endif
274 #ifdef XMMS2
275         INFO_XMMS2 = 22,
276 #endif
277         INFO_ENTROPY = 23,
278 #ifdef RSS
279         INFO_RSS = 24,
280 #endif
281 };
282
283
284 /* get_battery_stuff() item selector */
285 enum {
286         BATTERY_STATUS,
287         BATTERY_TIME
288 };
289
290 #ifdef MPD
291 #include "libmpdclient.h"
292 #endif
293
294 /* Update interval */
295 double update_interval;
296
297 volatile int g_signal_pending;
298
299 struct information {
300         unsigned int mask;
301
302         struct utsname uname_s;
303
304         char freq[10];
305
306         double uptime;
307
308         /* memory information in kilobytes */
309         unsigned long long mem, memmax, swap, swapmax;
310         unsigned long long bufmem, buffers, cached;
311
312         unsigned short procs;
313         unsigned short run_procs;
314
315         float *cpu_usage;
316         /*      struct cpu_stat cpu_summed; what the hell is this? */
317         unsigned int cpu_count;
318         unsigned int cpu_avg_samples;
319
320         unsigned int net_avg_samples;
321
322         float loadavg[3];
323
324         int new_mail_count, mail_count;
325         struct mail_s* mail;
326         int mail_running;
327 #ifdef MPD
328         struct mpd_s mpd;
329         mpd_Connection *conn;
330 #endif
331 #ifdef XMMS2
332         struct xmms2_s xmms2;
333         int xmms2_conn_state;
334         xmms_socket_t xmms2_fd; 
335         fd_set xmms2_fdset;
336         xmmsc_connection_t *xmms2_conn;
337 #endif
338 #ifdef AUDACIOUS
339         struct audacious_s audacious;
340 #endif
341 #ifdef BMPX
342         struct bmpx_s bmpx;
343 #endif
344         struct process *cpu[10];
345         struct process *memu[10];
346         struct process *first_process;
347         unsigned long looped;
348 #ifdef TCP_PORT_MONITOR
349   tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
350 #endif
351         short kflags;  /* kernel settings, see enum KFLAG */
352         struct entropy_s entropy;
353 };
354
355 enum {
356         KFLAG_IS_LONGSTAT = 0x01,         /* set to true if kernel uses "long" format for /proc/stats */
357         KFLAG_PROC_IS_THREADS=0x02       /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
358 /*      KFLAG_NEXT_ONE=0x04                 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
359      }; 
360
361 #define KFLAG_SETON(a) info.kflags |= a 
362 #define KFLAG_SETOFF(a) info.kflags &= (~a)
363 #define KFLAG_FLIP(a) info.kflags ^= a
364 #define KFLAG_ISSET(a) info.kflags & a
365
366
367 int out_to_console;
368
369 int top_cpu;
370 int top_mem;
371
372 int use_spacer;
373
374 char tmpstring1[TEXT_BUFFER_SIZE];
375 char tmpstring2[TEXT_BUFFER_SIZE];
376
377 #ifdef X11
378 /* in x11.c */
379
380 #include <X11/Xlib.h>
381 #include <X11/Xlib.h>
382 #include <X11/Xatom.h>
383
384 #ifdef XFT
385 #include <X11/Xft/Xft.h>
386 #endif
387
388 #ifdef HAVE_XDBE
389 #include <X11/extensions/Xdbe.h>
390 #endif
391
392 #define ATOM(a) XInternAtom(display, #a, False)
393
394 #ifdef OWN_WINDOW
395 enum _window_type {
396         TYPE_NORMAL = 0,
397         TYPE_DESKTOP,
398         TYPE_OVERRIDE
399 };
400
401 enum _window_hints {
402         HINT_UNDECORATED = 0,
403         HINT_BELOW,
404         HINT_ABOVE,
405         HINT_STICKY,
406         HINT_SKIP_TASKBAR,
407         HINT_SKIP_PAGER
408 };
409 #define SET_HINT(mask,hint)     (mask |= (1<<hint))
410 #define TEST_HINT(mask,hint)    (mask & (1<<hint))
411 #endif
412 struct conky_window {
413         Window root,window,desktop;
414         Drawable drawable;
415         GC gc;
416 #ifdef HAVE_XDBE
417         XdbeBackBuffer back_buffer;
418 #endif
419 #ifdef XFT
420         XftDraw *xftdraw;
421 #endif
422
423         int width;
424         int height;
425 #ifdef OWN_WINDOW
426         char class_name[256];
427   char title[256];
428         int x;
429         int y;
430         unsigned int type;
431         unsigned long hints;
432 #endif
433 };
434
435 #ifdef HAVE_XDBE
436 extern int use_xdbe;
437 #endif
438
439
440 #ifdef XFT
441 extern int use_xft;
442 #endif
443
444 extern Display *display;
445 extern int display_width;
446 extern int display_height;
447 extern int screen;
448
449 extern int workarea[4];
450
451 extern struct conky_window window;
452
453 void init_X11();
454 void init_window(int use_own_window, int width, int height, int set_trans, int back_colour, 
455                  char **argv, int argc);
456 void create_gc();
457 void set_transparent_background(Window win);
458 long get_x11_color(const char *);
459
460 #endif /* X11 */
461
462 /* in common.c */
463
464 /* struct that has all info */
465 struct information info;
466
467 void signal_handler(int);
468 void reload_config(void);
469 void clean_up(void);
470
471 void update_uname();
472 double get_time(void);
473 FILE *open_file(const char *file, int *reported);
474 void variable_substitute(const char *s, char *dest, unsigned int n);
475 void format_seconds(char *buf, unsigned int n, long t);
476 void format_seconds_short(char *buf, unsigned int n, long t);
477 struct net_stat *get_net_stat(const char *dev);
478 void clear_net_stats(void);
479
480 void update_stuff();
481
482 int round_to_int(float f);
483
484 #define SET_NEED(a) need_mask |= 1 << (a)
485 extern unsigned long long need_mask;
486
487 extern double current_update_time, last_update_time;
488
489 extern int no_buffers;
490
491 /* system dependant (in linux.c) */
492
493 int check_mount(char *s);
494 void update_diskio(void);
495 void prepare_update(void);
496 void update_uptime(void);
497 void update_meminfo(void);
498 void update_net_stats(void);
499 void update_cpu_usage(void);
500 void update_total_processes(void);
501 void update_running_processes(void);
502 void update_i8k(void);
503 char get_freq( char *, size_t, char *, int, unsigned int ); 
504 void get_freq_dynamic( char *, size_t, char *, int ); 
505 char get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
506 void update_load_average();
507
508 int open_sysfs_sensor(const char *dir, const char *dev, const char *type, int n, int *div, char *devtype);
509 #define open_i2c_sensor(dev,type,n,div,devtype) \
510     open_sysfs_sensor("/sys/bus/i2c/devices/",dev,type,n,div,devtype)
511
512 #define open_platform_sensor(dev,type,n,div,devtype) \
513     open_sysfs_sensor("/sys/bus/platform/devices/",dev,type,n,div,devtype)
514
515 #define open_hwmon_sensor(dev,type,n,div,devtype) \
516    open_sysfs_sensor("/sys/class/hwmon/",dev,type,n,div,devtype); \
517
518 double get_sysfs_info(int *fd, int arg, char *devtype, char *type);
519
520 void get_adt746x_cpu( char *, size_t ); 
521 void get_adt746x_fan( char *, size_t ); 
522 unsigned int get_diskio(void);
523
524 int open_acpi_temperature(const char *name);
525 double get_acpi_temperature(int fd);
526 void get_acpi_ac_adapter( char *, size_t ); 
527 void get_acpi_fan( char *, size_t ); 
528 void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
529 int get_battery_perct(const char *bat);
530 int get_battery_perct_bar(const char *bat);
531 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
532 void get_ibm_acpi_temps(void);
533 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
534 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
535 void get_cpu_count();
536
537 struct ibm_acpi_struct {
538     unsigned int temps[8];
539 };
540
541 struct ibm_acpi_struct ibm_acpi;
542
543 #if defined(__OpenBSD__)
544 void update_obsd_sensors(void);
545 void get_obsd_vendor(char *buf, size_t client_buffer_size);
546 void get_obsd_product(char *buf, size_t client_buffer_size);
547
548 #define OBSD_MAX_SENSORS 256
549 struct obsd_sensors_struct {
550         int device;
551         float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
552         unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
553         float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
554 };
555 struct obsd_sensors_struct obsd_sensors;
556 #endif /* __OpenBSD__ */
557
558
559 enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME};
560 void get_powerbook_batt_info(char*, size_t, int);
561
562 struct process {
563         struct process *next;
564         struct process *previous;
565
566         pid_t pid;
567         char *name;
568         float amount;
569         unsigned long user_time;
570         unsigned long total;
571         unsigned long kernel_time;
572         unsigned long previous_user_time;
573         unsigned long previous_kernel_time;
574         unsigned int vsize;
575         unsigned int rss;
576         unsigned int time_stamp;
577         unsigned int counted;
578         unsigned int changed;
579         float totalmem;
580 };
581
582 void update_top();
583 void free_all_processes();
584 struct process *get_first_process();
585
586 /* fs-stuff is possibly system dependant (in fs.c) */
587
588 void update_fs_stats(void);
589 struct fs_stat *prepare_fs_stat(const char *path);
590 void clear_fs_stats(void);
591
592 /* in mixer.c */
593
594 int mixer_init(const char *);
595 int mixer_get_avg(int);
596 int mixer_get_left(int);
597 int mixer_get_right(int);
598
599 /* in mail.c */
600
601 extern char *current_mail_spool;
602
603 void update_mail_count();
604
605 /* in freebsd.c */
606 #if defined(__FreeBSD__)
607 kvm_t *kd;
608 #endif
609
610 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
611 #ifdef __OpenBSD__
612 typedef struct apm_power_info *apm_info_t;
613 #endif
614 int apm_getinfo(int fd, apm_info_t aip);
615 char *get_apm_adapter(void);
616 char *get_apm_battery_life(void);
617 char *get_apm_battery_time(void);
618 #endif
619
620 /* in mpd.c */
621 #ifdef MPD
622 void update_mpd();
623 #endif
624
625 /* in xmms2.c */
626 #ifdef XMMS2
627 void update_xmms2();
628 #endif
629
630 /* in hddtemp.c */
631 #ifdef HDDTEMP
632 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port);
633 char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);
634 #endif /* HDDTEMP */
635
636 /* in rss.c */
637 #ifdef RSS
638 PRSS* get_rss_info(char *uri, int delay);
639 void init_rss_info();
640 void free_rss_info();
641 #endif /* RSS */
642
643 /* in linux.c */
644
645 #endif
646
647