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