made defines of some literal values and defines to configure.ac.in
[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 #undef EQUAL
38 #undef FALSE
39 #undef TRUE
40 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
41 #define FALSE 0
42 #define TRUE 1
43
44 #include "config.h"
45 #include <sys/utsname.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <locale.h>
49 #include <langinfo.h>
50 #include <wchar.h>
51 #include <sys/param.h>
52
53 #if !defined(__GNUC__)
54 #  define __attribute__(x) /* nothing */
55 #endif
56
57 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
58 #include "freebsd.h"
59 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
60
61 #if defined(__OpenBSD__)
62 #include "openbsd.h"
63 #endif /* __OpenBSD__ */
64
65 #ifndef HAVE_STRNDUP
66 // use our own strndup() if it's not available
67 char *strndup(const char *s, size_t n);
68 #endif /* HAVE_STRNDUP */
69
70 #ifdef AUDACIOUS
71 #include "audacious.h"
72 #endif
73
74 #ifdef XMMS2
75 #include <xmmsclient/xmmsclient.h>
76 #endif
77
78 #ifdef RSS
79 #include "rss.h"
80 #endif
81
82 #ifdef EVE
83 #include "eve.h"
84 #endif
85
86 #ifdef SMAPI
87 #include "smapi.h"
88 #endif
89
90 #ifdef NVIDIA
91 #include "nvidia.h"
92 #endif
93
94 #include "mboxscan.h"
95 #include "timed_thread.h"
96 #include "top.h"
97
98 #define DEFAULT_TEXT_BUFFER_SIZE 256
99 extern unsigned int text_buffer_size;
100
101 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
102 #define MAX_SPECIALS_DEFAULT 512
103
104 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
105 #define MAX_USER_TEXT_DEFAULT 16384
106
107 #include <sys/socket.h>
108
109 #define ERR(...) { \
110         fprintf(stderr, PACKAGE_NAME": "); \
111         fprintf(stderr, __VA_ARGS__); \
112         fprintf(stderr, "\n"); \
113 }
114
115 /* critical error */
116 #define CRIT_ERR(...) \
117         { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
118
119 struct net_stat {
120         const char *dev;
121         int up;
122         long long last_read_recv, last_read_trans;
123         long long recv, trans;
124         double recv_speed, trans_speed;
125         struct sockaddr addr;
126         char* addrs;
127         double net_rec[15], net_trans[15];
128         // wireless extensions
129         char essid[32];
130         char bitrate[16];
131         char mode[16];
132         int link_qual;
133         int link_qual_max;
134         char ap[18];
135 };
136
137 struct dns_data {
138         int nscount;
139         char **ns_list;
140 };
141
142 struct fs_stat {
143         char path[DEFAULT_TEXT_BUFFER_SIZE];
144         char type[DEFAULT_TEXT_BUFFER_SIZE];
145         long long size;
146         long long avail;
147         long long free;
148         char set;
149 };
150
151 #include "diskio.h"
152
153 struct mail_s {                 // for imap and pop3
154         unsigned long unseen;
155         unsigned long messages;
156         unsigned long used;
157         unsigned long quota;
158         unsigned long port;
159         float interval;
160         double last_update;
161         char host[128];
162         char user[128];
163         char pass[128];
164         char command[1024];
165         char folder[128];
166         timed_thread *p_timed_thread;
167         char secure;
168 };
169
170 /* struct cpu_stat {
171         unsigned int user, nice, system, idle, iowait, irq, softirq;
172         int cpu_avg_samples;
173 }; */
174
175 #ifdef MPD
176 #include "mpd.h"
177 #endif
178
179 #ifdef XMMS2
180 #include "xmms2.h"
181 #endif
182
183 #ifdef AUDACIOUS
184 #include "audacious.h"
185 #endif
186
187 #ifdef BMPX
188 #include "bmpx.h"
189 #endif
190
191 void update_entropy(void);
192 struct entropy_s {
193         unsigned int entropy_avail;
194         unsigned int poolsize;
195 };
196
197 struct usr_info {
198         char *names;
199         char *times;
200         char *terms;
201         int number;
202 };
203
204 struct gateway_info {
205         char *iface;
206         char *ip;
207         int count;
208 };
209
210 #ifdef X11
211 struct monitor_info {
212         int number;
213         int current;
214 };
215
216 struct x11_info {
217         struct monitor_info monitor;
218 };
219 #endif
220
221 #ifdef TCP_PORT_MONITOR
222 #include "libtcp-portmon.h"
223 #endif
224
225 enum {
226         INFO_CPU = 0,
227         INFO_MAIL = 1,
228         INFO_MEM = 2,
229         INFO_NET = 3,
230         INFO_PROCS = 4,
231         INFO_RUN_PROCS = 5,
232         INFO_UPTIME = 6,
233         INFO_BUFFERS = 7,
234         INFO_FS = 8,
235         INFO_SYSFS = 9,
236         INFO_MIXER = 10,
237         INFO_LOADAVG = 11,
238         INFO_UNAME = 12,
239         INFO_FREQ = 13,
240 #ifdef MPD
241         INFO_MPD = 14,
242 #endif
243         INFO_TOP = 15,
244         INFO_WIFI = 16,
245         INFO_DISKIO = 17,
246         INFO_I8K = 18,
247 #ifdef TCP_PORT_MONITOR
248         INFO_TCP_PORT_MONITOR = 19,
249 #endif
250 #ifdef AUDACIOUS
251         INFO_AUDACIOUS = 20,
252 #endif
253 #ifdef BMPX
254         INFO_BMPX = 21,
255 #endif
256 #ifdef XMMS2
257         INFO_XMMS2 = 22,
258 #endif
259         INFO_ENTROPY = 23,
260 #ifdef RSS
261         INFO_RSS = 24,
262 #endif
263 #ifdef SMAPI
264         INFO_SMAPI = 25,
265 #endif
266         INFO_USERS = 26,
267         INFO_GW = 27,
268 #ifdef NVIDIA
269         INFO_NVIDIA = 28,
270 #endif
271 #ifdef X11
272         INFO_X11 = 29,
273 #endif
274         INFO_DNS = 30
275
276 };
277
278 /* get_battery_stuff() item selector */
279 enum {
280         BATTERY_STATUS,
281         BATTERY_TIME
282 };
283
284 /* if_up strictness selector */
285 enum {
286         IFUP_UP,
287         IFUP_LINK,
288         IFUP_ADDR
289 } ifup_strictness;
290
291 /* Update interval */
292 double update_interval;
293
294 volatile int g_signal_pending;
295
296 struct information {
297         unsigned int mask;
298
299         struct utsname uname_s;
300
301         char freq[10];
302
303         double uptime;
304
305         /* memory information in kilobytes */
306         unsigned long long mem, memeasyfree, memfree, memmax, swap, swapmax;
307         unsigned long long bufmem, buffers, cached;
308
309         unsigned short procs;
310         unsigned short run_procs;
311
312         float *cpu_usage;
313         /* struct cpu_stat cpu_summed; what the hell is this? */
314         unsigned int cpu_count;
315         unsigned int cpu_avg_samples;
316
317         unsigned int net_avg_samples;
318
319         float loadavg[3];
320
321         struct mail_s *mail;
322         int mail_running;
323 #ifdef MPD
324         struct mpd_s mpd;
325 #endif
326 #ifdef XMMS2
327         struct xmms2_s xmms2;
328         int xmms2_conn_state;
329         xmms_socket_t xmms2_fd;
330         fd_set xmms2_fdset;
331         xmmsc_connection_t *xmms2_conn;
332 #endif
333 #ifdef AUDACIOUS
334         AUDACIOUS_S audacious;
335 #endif
336 #ifdef BMPX
337         struct bmpx_s bmpx;
338 #endif
339         struct usr_info users;
340         struct gateway_info gw_info;
341         struct dns_data nameserver_info;
342         struct process *cpu[10];
343         struct process *memu[10];
344         struct process *first_process;
345         unsigned long looped;
346 #ifdef TCP_PORT_MONITOR
347         tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
348 #endif
349         struct entropy_s entropy;
350         double music_player_interval;
351
352 #ifdef X11
353         struct x11_info x11;
354 #endif
355
356         short kflags;   /* kernel settings, see enum KFLAG */
357
358         unsigned int diskio_value;
359         unsigned int diskio_read_value;
360         unsigned int diskio_write_value;
361 };
362
363 enum {
364         /* set to true if kernel uses "long" format for /proc/stats */
365         KFLAG_IS_LONGSTAT = 0x01,
366         /* set to true if kernel shows # of threads for the proc value
367          * in sysinfo() call */
368         KFLAG_PROC_IS_THREADS = 0x02
369         /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
370         /* KFLAG_NEXT_ONE = 0x04 */
371 };
372
373 #define KFLAG_SETON(a) info.kflags |= a
374 #define KFLAG_SETOFF(a) info.kflags &= (~a)
375 #define KFLAG_FLIP(a) info.kflags ^= a
376 #define KFLAG_ISSET(a) info.kflags & a
377
378 #define TO_X 1
379 #define TO_STDOUT 2
380 int output_methods;
381
382 int top_cpu;
383 int top_mem;
384
385 int use_spacer;
386
387 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
388
389 char *tmpstring1;
390 char *tmpstring2;
391
392 #ifdef X11
393 #include "x11.h"
394 #endif /* X11 */
395
396 int cpu_separate;
397 int short_units;
398
399 /* struct that has all info */
400 struct information info;
401
402 void signal_handler(int);
403 void reload_config(void);
404 void clean_up(void);
405
406 void update_uname(void);
407 double get_time(void);
408 FILE *open_file(const char *file, int *reported);
409 void variable_substitute(const char *s, char *dest, unsigned int n);
410 void format_seconds(char *buf, unsigned int n, long t);
411 void format_seconds_short(char *buf, unsigned int n, long t);
412 struct net_stat *get_net_stat(const char *dev);
413 void clear_net_stats(void);
414 void free_dns_data(void);
415 void update_dns_data(void);
416 void update_users(void);
417
418 #ifdef X11
419 void update_x11info(void);
420 #endif
421
422 void update_stuff(void);
423
424 int round_to_int(float f);
425
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 #if defined(__linux__)
433 #include "linux.h"
434 #endif
435
436 #include "fs.h"
437 #include "mixer.h"
438 #include "mail.h"
439
440 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
441                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
442 int apm_getinfo(int fd, apm_info_t aip);
443 char *get_apm_adapter(void);
444 char *get_apm_battery_life(void);
445 char *get_apm_battery_time(void);
446 #endif
447
448 #ifdef HDDTEMP
449 #include "hddtemp.h"
450 #endif /* HDDTEMP */
451
452 /* in nvidia.c */
453 #ifdef NVIDIA
454
455 int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow);
456
457 #endif /* NVIDIA */
458
459 #endif