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