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