patch 1319461
[monky] / src / conky.h
1 /*
2  * Conky, a system monitor, based on torsmo
3  *
4  * This program is licensed under BSD license, read COPYING
5  *
6  *  $Id$
7  */
8
9 #ifndef _conky_h_
10 #define _conky_h_
11
12 #if defined(HAS_MCHECK_H)
13 #include <mcheck.h>
14 #endif /* HAS_MCHECK_H */
15 #include "config.h"
16 #include <sys/utsname.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <locale.h>
20 #include <langinfo.h>
21 #include <wchar.h>
22
23 #ifdef X11
24 #if defined(HAVE_CAIRO_H) && defined(HAVE_CAIRO_XLIB_H) && defined(WANT_CAIRO)
25 #define CAIRO
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <cairo.h>
29 #include <cairo-xlib.h>
30 #endif
31 #endif /* X11 */
32
33 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
34 #include <machine/apm_bios.h>
35 #endif /* __FreeBSD__ */
36
37 #define TOP_CPU 1
38 #define TOP_NAME 2
39 #define TOP_PID 3
40 #define TOP_MEM 4
41
42 #define TEXT_BUFFER_SIZE 1024
43
44 #include <sys/socket.h>
45
46 #define ERR(s, varargs...) \
47 fprintf(stderr, "Conky: " s "\n", ##varargs)
48
49 /* critical error */
50 #define CRIT_ERR(s, varargs...) \
51 { fprintf(stderr, "Conky: " s "\n", ##varargs);  exit(EXIT_FAILURE); }
52
53 struct i8k_struct {
54         char *version;
55         char *bios;
56         char *serial;
57         char *cpu_temp;
58         char *left_fan_status;
59         char *right_fan_status;
60         char *left_fan_rpm;
61         char *right_fan_rpm;
62         char *ac_status;
63         char *buttons_status;
64 };
65
66 struct i8k_struct i8k;
67
68 struct net_stat {
69         const char *dev;
70         int up;
71         long long last_read_recv, last_read_trans;
72         long long recv, trans;
73         double recv_speed, trans_speed;
74         struct sockaddr addr;
75         int linkstatus;
76         double net_rec[15], net_trans[15];
77 };
78
79 unsigned int diskio_value;
80
81 struct fs_stat {
82         int fd;
83         char *path;
84         long long size;
85         long long avail;
86 };
87
88 /*struct cpu_stat {
89         unsigned int user, nice, system, idle, iowait, irq, softirq;
90         int cpu_avg_samples;
91 };*/
92
93 #ifdef MPD
94 struct mpd_s {
95         char *title;
96         char *artist;
97         char *album;
98         char *status;
99         char *random;
100         char *repeat;
101         char *track;
102         int volume;
103         unsigned int port;
104         char host[128];
105         float progress;
106         int bitrate;
107         int length;
108         int elapsed;
109 };
110 #endif
111
112 enum {
113         INFO_CPU = 0,
114         INFO_MAIL = 1,
115         INFO_MEM = 2,
116         INFO_NET = 3,
117 #ifdef SETI
118         INFO_SETI = 4,
119 #endif
120         INFO_PROCS = 5,
121         INFO_RUN_PROCS = 6,
122         INFO_UPTIME = 7,
123         INFO_BUFFERS = 8,
124         INFO_FS = 9,
125         INFO_I2C = 10,
126         INFO_MIXER = 11,
127         INFO_LOADAVG = 12,
128         INFO_UNAME = 13,
129         INFO_FREQ = 14,
130 #ifdef MPD
131         INFO_MPD = 15,
132 #endif
133         INFO_TOP = 16,
134 #ifdef MLDONKEY
135         INFO_MLDONKEY = 18,
136 #endif
137         INFO_WIFI = 19,
138         INFO_DISKIO = 20,
139         INFO_I8K = 21,
140 };
141
142
143 #ifdef MPD
144 #include "libmpdclient.h"
145 #endif
146
147 struct information {
148         unsigned int mask;
149
150         struct utsname uname_s;
151
152         char freq[10];
153
154         double uptime;
155
156         /* memory information in kilobytes */
157         unsigned int mem, memmax, swap, swapmax;
158         unsigned int bufmem, buffers, cached;
159
160         unsigned int procs;
161         unsigned int run_procs;
162
163         float *cpu_usage;
164         /*      struct cpu_stat cpu_summed; what the hell is this? */
165         unsigned int cpu_count;
166         unsigned int cpu_avg_samples;
167
168         unsigned int net_avg_samples;
169
170         float loadavg[3];
171
172         int new_mail_count, mail_count;
173 #ifdef SETI
174         float seti_prog;
175         float seti_credit;
176 #endif
177 #ifdef MPD
178         struct mpd_s mpd;
179         mpd_Connection *conn;
180 #endif
181         struct process *cpu[10];
182         struct process *memu[10];
183         unsigned long looped;
184 };
185
186 int out_to_console;
187
188 int top_cpu;
189 int top_mem;
190
191 int use_spacer;
192
193 char *tmpstring1;
194 char *tmpstring2;
195
196 #ifdef X11
197 /* in x11.c */
198
199 #include <X11/Xlib.h>
200 #include <X11/Xlib.h>
201 #include <X11/Xatom.h>
202
203 #ifdef XFT
204 #include <X11/Xft/Xft.h>
205 #endif
206
207 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
208 #define XDBE
209 #include <X11/extensions/Xdbe.h>
210 #endif
211
212 #define ATOM(a) XInternAtom(display, #a, False)
213
214 struct conky_window {
215         Window window;
216         Drawable drawable;
217         GC gc;
218 #ifdef XDBE
219         XdbeBackBuffer back_buffer;
220 #endif
221 #ifdef XFT
222         XftDraw *xftdraw;
223 #endif
224
225         int width;
226         int height;
227 #ifdef OWN_WINDOW
228         int x;
229         int y;
230 #endif
231 };
232
233 #ifdef XDBE
234 extern int use_xdbe;
235 #endif
236
237
238 #ifdef XFT
239 extern int use_xft;
240 #endif
241
242 extern Display *display;
243 extern int display_width;
244 extern int display_height;
245 extern int screen;
246
247 extern int workarea[4];
248
249 extern struct conky_window window;
250
251 void init_X11();
252 #if defined OWN_WINDOW
253 void init_window(int use_own_window, int width, int height, int on_bottom, int fixed_pos, int set_trans, int back_colour);
254 #else
255 void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour);
256 #endif
257 void create_gc();
258 void set_transparent_background(Window win);
259 long get_x11_color(const char *);
260
261 #endif /* X11 */
262
263 /* in common.c */
264
265 /* struct that has all info */
266 struct information info;
267
268 void update_uname();
269 double get_time(void);
270 FILE *open_file(const char *file, int *reported);
271 void variable_substitute(const char *s, char *dest, unsigned int n);
272 void format_seconds(char *buf, unsigned int n, long t);
273 void format_seconds_short(char *buf, unsigned int n, long t);
274 struct net_stat *get_net_stat(const char *dev);
275
276 void update_stuff();
277
278 int round_to_int(float f);
279
280 #define SET_NEED(a) need_mask |= 1 << (a)
281 extern unsigned long long need_mask;
282
283 extern double current_update_time, last_update_time;
284
285 extern int no_buffers;
286
287 /* system dependant (in linux.c) */
288
289 void update_diskio(void);
290 void prepare_update(void);
291 void update_uptime(void);
292 void update_meminfo(void);
293 void update_net_stats(void);
294 void update_wifi_stats(void);
295 void update_cpu_usage(void);
296 void update_total_processes(void);
297 void update_running_processes(void);
298 void update_i8k(void);
299 float get_freq();
300 float get_freq_dynamic();
301 void update_load_average();
302 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
303                     char *devtype);
304 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
305
306 char *get_adt746x_cpu(void);
307 char *get_adt746x_fan(void);
308 unsigned int get_diskio(void);
309
310 int open_acpi_temperature(const char *name);
311 double get_acpi_temperature(int fd);
312 char *get_acpi_ac_adapter(void);
313 char *get_acpi_fan(void);
314 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
315
316 struct process {
317         struct process *next;
318         struct process *previous;
319
320         pid_t pid;
321         char *name;
322         float amount;
323         unsigned int user_time;
324         unsigned int total;
325         unsigned int kernel_time;
326         unsigned int previous_user_time;
327         unsigned int previous_kernel_time;
328         unsigned int vsize;
329         unsigned int rss;
330         unsigned int time_stamp;
331         unsigned int counted;
332         unsigned int changed;
333         float totalmem;
334 };
335
336 void update_top();
337
338 /* fs-stuff is possibly system dependant (in fs.c) */
339
340 void update_fs_stats(void);
341 struct fs_stat *prepare_fs_stat(const char *path);
342 void clear_fs_stats(void);
343
344 /* in mixer.c */
345
346 int mixer_init(const char *);
347 int mixer_get_avg(int);
348 int mixer_get_left(int);
349 int mixer_get_right(int);
350
351 /* in mail.c */
352
353 extern char *current_mail_spool;
354
355 void update_mail_count();
356
357 /* in seti.c */
358
359 #ifdef SETI
360 extern char *seti_dir;
361
362 void update_seti();
363 #endif
364
365 /* in freebsd.c */
366 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
367 int apm_getinfo(int fd, apm_info_t aip);
368 char *get_apm_adapter(void);
369 char *get_apm_battery_life(void);
370 char *get_apm_battery_time(void);
371 #endif
372 /* in mpd.c */
373
374 #ifdef MPD
375 void update_mpd();
376 #endif
377
378 #ifdef MLDONKEY
379 /* in mldonkey.c */
380 typedef long long int64;
381 /* The info necessary to connect to mldonkey. login and password can be NULL. */
382 typedef struct mldonkey_config {
383         char *mldonkey_hostname;
384         int mldonkey_port;
385         char *mldonkey_login;
386         char *mldonkey_password;
387 } mldonkey_config;
388
389 /* The MLDonkey status returned */
390 typedef struct mldonkey_info {
391         int64 upload_counter;
392         int64 download_counter;
393         int nshared_files;
394         int64 shared_counter;
395         int tcp_upload_rate;
396         int tcp_download_rate;
397         int udp_upload_rate;
398         int udp_download_rate;
399         int ndownloaded_files;
400         int ndownloading_files;
401         int nconnected_networks;
402         int connected_networks[1];
403 } mldonkey_info;
404
405 extern mldonkey_info mlinfo;
406 extern mldonkey_config mlconfig;
407
408 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
409 #endif
410
411 /* in linux.c */
412
413 /* nothing to see here */
414
415 /* in cairo.c */
416
417 extern int do_it(void);
418
419 #endif