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