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