4af6a492ff65c51f91090cef763bbc57d3269633
[monky] / src / conky.h
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  *
3  * Conky, a system monitor, based on torsmo
4  *
5  * Any original torsmo code is licensed under the BSD license
6  *
7  * All code written since the fork of torsmo is licensed under the GPL
8  *
9  * Please see COPYING for details
10  *
11  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
13  *      (see AUTHORS)
14  * All rights reserved.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  *
28  * vim: ts=4 sw=4 noet ai cindent syntax=c
29  *
30  */
31
32 #ifndef _conky_h_
33 #define _conky_h_
34
35 #include "config.h"     /* defines */
36 #include "common.h"     /* at least for struct dns_data */
37 #include <sys/utsname.h> /* struct uname_s */
38 #include <arpa/inet.h>
39
40 #if defined(HAS_MCHECK_H)
41 #include <mcheck.h>
42 #endif /* HAS_MCHECK_H */
43
44 #undef EQUAL
45 #undef FALSE
46 #undef TRUE
47 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
48 #define FALSE 0
49 #define TRUE 1
50
51 #define DEFAULT_BAR_WIDTH_NO_X 10
52
53 #if !defined(__GNUC__)
54 #  define __attribute__(x) /* nothing */
55 #endif
56
57 #ifndef HAVE_STRNDUP
58 // use our own strndup() if it's not available
59 char *strndup(const char *s, size_t n);
60 #endif /* HAVE_STRNDUP */
61
62 /* headers of optional features
63  * include them here, so we don't need to run the check
64  * in every code file optionally using the feature
65  */
66
67 #ifdef AUDACIOUS
68 #include "audacious.h"
69 #endif
70
71 #ifdef BMPX
72 #include "bmpx.h"
73 #endif
74
75 #ifdef EVE
76 #include "eve.h"
77 #endif
78
79 #ifdef HDDTEMP
80 #include "hddtemp.h"
81 #endif /* HDDTEMP */
82
83 #ifdef MOC
84 #include "moc.h"
85 #endif
86
87 #ifdef MPD
88 #include "mpd.h"
89 #endif
90
91 #ifdef NVIDIA
92 #include "nvidia.h"
93 #endif
94
95 #ifdef HAVE_CURL
96 #include "ccurl_thread.h"
97 #endif /* HAVE_CURL */
98
99 #ifdef RSS
100 #include "rss.h"
101 #endif /* RSS */
102
103 #ifdef XOAP
104 #ifndef WEATHER
105 #error "WEATHER needs to be defined if XOAP is defined"
106 #endif /* WEATHER */
107 #endif /* XOAP */
108
109 #ifdef WEATHER
110 #include "weather.h"
111 #endif /* WEATHER */
112
113 #ifdef TCP_PORT_MONITOR
114 #include "tcp-portmon.h"
115 #endif
116
117 #ifdef XMMS2
118 #include "xmms2.h"
119 #endif
120
121 #ifdef IBM
122 #include "ibm.h"
123 #include "smapi.h"
124 #endif
125
126 #ifdef APCUPSD
127 #include "apcupsd.h"
128 #endif
129
130 /* sony support */
131 #include "sony.h"
132
133 /* A size for temporary, static buffers to use when
134  * one doesn't know what to choose. Defaults to 256.  */
135 extern unsigned int text_buffer_size;
136
137 struct entropy_s {
138         unsigned int entropy_avail;
139         unsigned int poolsize;
140 };
141
142 struct usr_info {
143         char *names;
144         char *times;
145         char *terms;
146         int number;
147 };
148
149 struct gateway_info {
150         char *iface;
151         char *ip;
152         int count;
153 };
154
155 #ifdef X11
156 struct monitor_info {
157         int number;
158         int current;
159 };
160
161 struct desktop_info {
162         int current;
163         int number;
164         unsigned int nitems;
165         char *all_names;
166         char *name;
167 };
168
169 struct x11_info {
170         struct monitor_info monitor;
171         struct desktop_info desktop;
172 };
173
174 int get_stippled_borders(void);
175
176 #endif /* X11 */
177
178 /* defined in conky.c */
179 extern long default_fg_color, default_bg_color, default_out_color;
180 extern long color0, color1, color2, color3, color4, color5, color6, color7,
181            color8, color9;
182 void set_current_text_color(long colour);
183 long get_current_text_color(void);
184
185 void set_updatereset(int);
186 int get_updatereset(void);
187
188 struct conftree {
189         char* string;
190         struct conftree* horz_next;
191         struct conftree* vert_next;
192         struct conftree* back;
193 };
194
195 char load_config_file(const char *);
196
197 char *get_global_text(void);
198 extern long global_text_lines;
199
200 //adds newstring to to the tree unless you can already see it when travelling back.
201 //if it's possible to attach it then it returns a pointer to the leaf, else it returns NULL
202 struct conftree* conftree_add(struct conftree* previous, const char* newstring);
203
204 extern struct conftree *currentconffile;
205
206 #define MAX_TEMPLATES 10
207 char **get_templates(void);
208
209 enum {
210         INFO_CPU = 0,
211         INFO_MAIL = 1,
212         INFO_MEM = 2,
213         INFO_NET = 3,
214         INFO_PROCS = 4,
215         INFO_RUN_PROCS = 5,
216         INFO_UPTIME = 6,
217         INFO_BUFFERS = 7,
218         INFO_FS = 8,
219         INFO_SYSFS = 9,
220         INFO_MIXER = 10,
221         INFO_LOADAVG = 11,
222         INFO_UNAME = 12,
223         INFO_FREQ = 13,
224 #ifdef MPD
225         INFO_MPD = 14,
226 #endif
227         INFO_TOP = 15,
228         INFO_WIFI = 16,
229         INFO_DISKIO = 17,
230         INFO_I8K = 18,
231 #ifdef TCP_PORT_MONITOR
232         INFO_TCP_PORT_MONITOR = 19,
233 #endif
234 #ifdef AUDACIOUS
235         INFO_AUDACIOUS = 20,
236 #endif
237 #ifdef BMPX
238         INFO_BMPX = 21,
239 #endif
240 #ifdef XMMS2
241         INFO_XMMS2 = 22,
242 #endif
243         INFO_ENTROPY = 23,
244 #ifdef IBM
245         INFO_SMAPI = 25,
246 #endif
247         INFO_USERS = 26,
248         INFO_GW = 27,
249 #ifdef NVIDIA
250         INFO_NVIDIA = 28,
251 #endif
252 #ifdef X11
253         INFO_X11 = 29,
254 #endif
255         INFO_DNS = 30,
256 #ifdef MOC
257         INFO_MOC = 31,
258 #endif
259 #ifdef APCUPSD
260         INFO_APCUPSD = 32,
261 #endif
262 #ifdef WEATHER
263         INFO_WEATHER = 33,
264 #endif
265 };
266
267 /* get_battery_stuff() item selector
268  * needed by conky.c, linux.c and freebsd.c */
269 enum {
270         BATTERY_STATUS,
271         BATTERY_TIME
272 };
273
274 /* if_up strictness selector
275  * needed by conky.c and linux.c (and potentially others) */
276 enum {
277         IFUP_UP,
278         IFUP_LINK,
279         IFUP_ADDR
280 } ifup_strictness;
281
282 struct information {
283         unsigned int mask;
284
285         struct utsname uname_s;
286
287         char freq[10];
288
289         double uptime;
290
291         /* memory information in kilobytes */
292         unsigned long long mem, memeasyfree, memfree, memmax, swap, swapfree, swapmax;
293         unsigned long long bufmem, buffers, cached;
294
295         unsigned short procs;
296         unsigned short run_procs;
297
298         float *cpu_usage;
299         /* struct cpu_stat cpu_summed; what the hell is this? */
300         unsigned int cpu_count;
301         int cpu_avg_samples;
302
303         int net_avg_samples;
304
305         int diskio_avg_samples;
306
307         float loadavg[3];
308
309         struct mail_s *mail;
310         int mail_running;
311 #ifdef XMMS2
312         struct xmms2_s xmms2;
313 #endif
314 #ifdef AUDACIOUS
315         AUDACIOUS_S audacious;
316 #endif
317 #ifdef BMPX
318         struct bmpx_s bmpx;
319 #endif
320         struct usr_info users;
321         struct gateway_info gw_info;
322         struct dns_data nameserver_info;
323         struct process *cpu[10];
324         struct process *memu[10];
325         struct process *time[10];
326 #ifdef IOSTATS
327         struct process *io[10];
328 #endif
329         struct process *first_process;
330         unsigned long looped;
331         struct entropy_s entropy;
332         double music_player_interval;
333
334 #ifdef X11
335         struct x11_info x11;
336 #endif
337
338 #ifdef APCUPSD
339         APCUPSD_S apcupsd;
340 #endif
341
342         short kflags;   /* kernel settings, see enum KFLAG */
343 };
344
345 #ifdef HAVE_LUA
346 #include "llua.h"
347 #endif /* HAVE_LUA */
348
349 /* needed by linux.c and top.c -> outsource somewhere */
350 enum {
351         /* set to true if kernel uses "long" format for /proc/stats */
352         KFLAG_IS_LONGSTAT = 0x01,
353         /* set to true if kernel shows # of threads for the proc value
354          * in sysinfo() call */
355         KFLAG_PROC_IS_THREADS = 0x02
356         /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
357         /* KFLAG_NEXT_ONE = 0x04 */
358 };
359 #define KFLAG_SETON(a) info.kflags |= a
360 #define KFLAG_SETOFF(a) info.kflags &= (~a)
361 #define KFLAG_FLIP(a) info.kflags ^= a
362 #define KFLAG_ISSET(a) info.kflags & a
363
364 /* defined in conky.c, needed by top.c */
365 extern int top_cpu, top_mem, top_time;
366 #ifdef IOSTATS
367 extern int top_io;
368 #endif
369
370 /* defined in conky.c, needed by top.c */
371 extern int cpu_separate;
372
373 /* struct that has all info to be shared between
374  * instances of the same text object */
375 extern struct information info;
376
377 /* defined in users.c */
378 void update_users(void);
379
380 /* defined in conky.c */
381 extern double current_update_time, last_update_time, update_interval;
382
383 /* defined in conky.c */
384 int spaced_print(char *, int, const char *, int, ...)
385         __attribute__((format(printf, 3, 5)));
386 extern int inotify_fd;
387
388 /* defined in conky.c
389  * evaluates 'text' and places the result in 'buffer'
390  */
391 void evaluate(const char *text, char *buffer);
392
393 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
394 extern unsigned int max_user_text;
395
396 /* path to config file */
397 extern char *current_config;
398
399 /* just a wrapper for read_exec() defined in conky.c */
400 void do_read_exec(const char *data, char *buf, const int size);
401
402 #ifdef X11
403 #define TO_X 1
404 #endif /* X11 */
405 #define TO_STDOUT 2
406 #define TO_STDERR 4
407 #define OVERWRITE_FILE 8
408 #define APPEND_FILE 16
409 #ifdef NCURSES
410 #define TO_NCURSES 32
411 #endif /* NCURSES */
412 enum x_initialiser_state {
413         NO = 0,
414         YES = 1,
415         NEVER = 2
416 };
417 extern int output_methods;
418 extern enum x_initialiser_state x_initialised;
419
420 void set_update_interval(double interval);
421
422 #define DEFAULT_TEXT_BUFFER_SIZE_S "##DEFAULT_TEXT_BUFFER_SIZE"
423
424 #define NOBATTERY 0
425
426 /* to get rid of 'unused variable' warnings */
427 #define UNUSED(a)  (void)a
428 #define UNUSED_ATTR __attribute__ ((unused))
429
430 #endif /* _conky_h_ */