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