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