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