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