ca953920e7f15c82043f3cff76e4f86258220ff4
[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         int volume;
100         unsigned int port;
101         char host[128];
102         float progress;
103         int bitrate;
104         int length;
105         int elapsed;
106 };
107 #endif
108
109 enum {
110         INFO_CPU = 0,
111         INFO_MAIL = 1,
112         INFO_MEM = 2,
113         INFO_NET = 3,
114 #ifdef SETI
115         INFO_SETI = 4,
116 #endif
117         INFO_PROCS = 5,
118         INFO_RUN_PROCS = 6,
119         INFO_UPTIME = 7,
120         INFO_BUFFERS = 8,
121         INFO_FS = 9,
122         INFO_I2C = 10,
123         INFO_MIXER = 11,
124         INFO_LOADAVG = 12,
125         INFO_UNAME = 13,
126         INFO_FREQ = 14,
127 #ifdef MPD
128         INFO_MPD = 15,
129 #endif
130         INFO_TOP = 16,
131 #ifdef MLDONKEY
132         INFO_MLDONKEY = 18,
133 #endif
134         INFO_WIFI = 19,
135         INFO_DISKIO = 20,
136         INFO_I8K = 21,
137 };
138
139
140 #ifdef MPD
141 #include "libmpdclient.h"
142 #endif
143
144 struct information {
145         unsigned int mask;
146
147         struct utsname uname_s;
148
149         char freq[10];
150
151         double uptime;
152
153         /* memory information in kilobytes */
154         unsigned int mem, memmax, swap, swapmax;
155         unsigned int bufmem, buffers, cached;
156
157         unsigned int procs;
158         unsigned int run_procs;
159
160         float *cpu_usage;
161         /*      struct cpu_stat cpu_summed; what the hell is this? */
162         unsigned int cpu_count;
163         unsigned int cpu_avg_samples;
164
165         unsigned int net_avg_samples;
166
167         float loadavg[3];
168
169         int new_mail_count, mail_count;
170 #ifdef SETI
171         float seti_prog;
172         float seti_credit;
173 #endif
174 #ifdef MPD
175         struct mpd_s mpd;
176         mpd_Connection *conn;
177 #endif
178         struct process *cpu[10];
179         struct process *memu[10];
180         unsigned long looped;
181 };
182
183 int out_to_console;
184
185 int top_cpu;
186 int top_mem;
187
188 int use_spacer;
189
190 char *tmpstring1;
191 char *tmpstring2;
192
193 #ifdef X11
194 /* in x11.c */
195
196 #include <X11/Xlib.h>
197 #include <X11/Xlib.h>
198 #include <X11/Xatom.h>
199
200 #ifdef XFT
201 #include <X11/Xft/Xft.h>
202 #endif
203
204 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
205 #define XDBE
206 #include <X11/extensions/Xdbe.h>
207 #endif
208
209 #define ATOM(a) XInternAtom(display, #a, False)
210
211 struct conky_window {
212         Window window;
213         Drawable drawable;
214         GC gc;
215 #ifdef XDBE
216         XdbeBackBuffer back_buffer;
217 #endif
218 #ifdef XFT
219         XftDraw *xftdraw;
220 #endif
221
222         int width;
223         int height;
224 #ifdef OWN_WINDOW
225         int x;
226         int y;
227 #endif
228 };
229
230 #ifdef XDBE
231 extern int use_xdbe;
232 #endif
233
234
235 #ifdef XFT
236 extern int use_xft;
237 #endif
238
239 extern Display *display;
240 extern int display_width;
241 extern int display_height;
242 extern int screen;
243
244 extern int workarea[4];
245
246 extern struct conky_window window;
247
248 void init_X11();
249 #if defined OWN_WINDOW
250 void init_window(int use_own_window, int width, int height, int on_bottom, int fixed_pos, int set_trans, int back_colour);
251 #else
252 void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour);
253 #endif
254 void create_gc();
255 void set_transparent_background(Window win);
256 long get_x11_color(const char *);
257
258 #endif /* X11 */
259
260 /* in common.c */
261
262 /* struct that has all info */
263 struct information info;
264
265 void update_uname();
266 double get_time(void);
267 FILE *open_file(const char *file, int *reported);
268 void variable_substitute(const char *s, char *dest, unsigned int n);
269 void format_seconds(char *buf, unsigned int n, long t);
270 void format_seconds_short(char *buf, unsigned int n, long t);
271 struct net_stat *get_net_stat(const char *dev);
272
273 void update_stuff();
274
275 int round_to_int(float f);
276
277 #define SET_NEED(a) need_mask |= 1 << (a)
278 extern unsigned long long need_mask;
279
280 extern double current_update_time, last_update_time;
281
282 extern int no_buffers;
283
284 /* system dependant (in linux.c) */
285
286 void update_diskio(void);
287 void prepare_update(void);
288 void update_uptime(void);
289 void update_meminfo(void);
290 void update_net_stats(void);
291 void update_wifi_stats(void);
292 void update_cpu_usage(void);
293 void update_total_processes(void);
294 void update_running_processes(void);
295 void update_i8k(void);
296 float get_freq();
297 float get_freq_dynamic();
298 void update_load_average();
299 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
300                     char *devtype);
301 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
302
303 char *get_adt746x_cpu(void);
304 char *get_adt746x_fan(void);
305 unsigned int get_diskio(void);
306
307 int open_acpi_temperature(const char *name);
308 double get_acpi_temperature(int fd);
309 char *get_acpi_ac_adapter(void);
310 char *get_acpi_fan(void);
311 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
312
313 struct process {
314         struct process *next;
315         struct process *previous;
316
317         pid_t pid;
318         char *name;
319         float amount;
320         unsigned int user_time;
321         unsigned int total;
322         unsigned int kernel_time;
323         unsigned int previous_user_time;
324         unsigned int previous_kernel_time;
325         unsigned int vsize;
326         unsigned int rss;
327         unsigned int time_stamp;
328         unsigned int counted;
329         unsigned int changed;
330         float totalmem;
331 };
332
333 void update_top();
334
335 /* fs-stuff is possibly system dependant (in fs.c) */
336
337 void update_fs_stats(void);
338 struct fs_stat *prepare_fs_stat(const char *path);
339 void clear_fs_stats(void);
340
341 /* in mixer.c */
342
343 int mixer_init(const char *);
344 int mixer_get_avg(int);
345 int mixer_get_left(int);
346 int mixer_get_right(int);
347
348 /* in mail.c */
349
350 extern char *current_mail_spool;
351
352 void update_mail_count();
353
354 /* in seti.c */
355
356 #ifdef SETI
357 extern char *seti_dir;
358
359 void update_seti();
360 #endif
361
362 /* in freebsd.c */
363 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
364 int apm_getinfo(int fd, apm_info_t aip);
365 char *get_apm_adapter(void);
366 char *get_apm_battery_life(void);
367 char *get_apm_battery_time(void);
368 #endif
369 /* in mpd.c */
370
371 #ifdef MPD
372 void update_mpd();
373 #endif
374
375 #ifdef MLDONKEY
376 /* in mldonkey.c */
377 typedef long long int64;
378 /* The info necessary to connect to mldonkey. login and password can be NULL. */
379 typedef struct mldonkey_config {
380         char *mldonkey_hostname;
381         int mldonkey_port;
382         char *mldonkey_login;
383         char *mldonkey_password;
384 } mldonkey_config;
385
386 /* The MLDonkey status returned */
387 typedef struct mldonkey_info {
388         int64 upload_counter;
389         int64 download_counter;
390         int nshared_files;
391         int64 shared_counter;
392         int tcp_upload_rate;
393         int tcp_download_rate;
394         int udp_upload_rate;
395         int udp_download_rate;
396         int ndownloaded_files;
397         int ndownloading_files;
398         int nconnected_networks;
399         int connected_networks[1];
400 } mldonkey_info;
401
402 extern mldonkey_info mlinfo;
403 extern mldonkey_config mlconfig;
404
405 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
406 #endif
407
408 /* in linux.c */
409
410 /* nothing to see here */
411
412 /* in cairo.c */
413
414 extern int do_it(void);
415
416 #endif