2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
13 #if defined(HAS_MCHECK_H)
15 #endif /* HAS_MCHECK_H */
17 #include <sys/utsname.h>
23 #include <sys/param.h>
24 #if defined(__FreeBSD__)
25 #include <sys/mount.h>
26 #include <sys/ucred.h>
27 #endif /* __FreeBSD__ */
30 #if defined(HAVE_CAIRO_H) && defined(HAVE_CAIRO_XLIB_H) && defined(WANT_CAIRO)
33 #include <X11/Xutil.h>
35 #include <cairo-xlib.h>
39 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
40 #include <machine/apm_bios.h>
41 #endif /* __FreeBSD__ */
43 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
52 #define TEXT_BUFFER_SIZE 1280
53 #define P_MAX_SIZE ((TEXT_BUFFER_SIZE * 4) - 2)
55 #include <sys/socket.h>
57 #define ERR(s, varargs...) \
58 fprintf(stderr, "Conky: " s "\n", ##varargs)
61 #define CRIT_ERR(s, varargs...) \
62 { fprintf(stderr, "Conky: " s "\n", ##varargs); exit(EXIT_FAILURE); }
66 #define MIN(a,b) (a>b ? b : a)
69 #define MAX(a,b) (a<b ? b : a)
78 char *left_fan_status;
79 char *right_fan_status;
86 struct i8k_struct i8k;
91 long long last_read_recv, last_read_trans;
92 long long recv, trans;
93 double recv_speed, trans_speed;
96 double net_rec[15], net_trans[15];
99 unsigned int diskio_value;
109 unsigned int user, nice, system, idle, iowait, irq, softirq;
135 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
137 unsigned int project_mask;
138 unsigned int current_project;
139 xmms_t items; /* e.g. items[XMMS_STATUS] yields char[] */
140 int runnable; /* used to signal worker thread to stop */
141 pthread_t thread; /* worker thread for xmms updating */
142 pthread_attr_t thread_attr; /* thread attributes */
143 pthread_mutex_t item_mutex; /* mutex for item array */
144 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
160 #ifdef TCP_PORT_MONITOR
161 #include "libtcp-portmon.h"
162 #define MIN_PORT_MONITORS_DEFAULT 16
163 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
194 #ifdef TCP_PORT_MONITOR
195 INFO_TCP_PORT_MONITOR = 22,
197 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
207 #include "libmpdclient.h"
210 volatile int g_signal_pending;
215 struct utsname uname_s;
221 /* memory information in kilobytes */
222 unsigned long mem, memmax, swap, swapmax;
223 unsigned long bufmem, buffers, cached;
225 unsigned short procs;
226 unsigned short run_procs;
229 /* struct cpu_stat cpu_summed; what the hell is this? */
230 unsigned int cpu_count;
231 unsigned int cpu_avg_samples;
233 unsigned int net_avg_samples;
237 int new_mail_count, mail_count;
244 mpd_Connection *conn;
246 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
252 struct process *cpu[10];
253 struct process *memu[10];
254 struct process *first_process;
255 unsigned long looped;
256 #ifdef TCP_PORT_MONITOR
257 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
259 short kflags; /* kernel settings, see enum KFLAG */
263 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
264 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
265 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
268 #define KFLAG_SETON(a) info.kflags |= a
269 #define KFLAG_SETOFF(a) info.kflags &= (~a)
270 #define KFLAG_FLIP(a) info.kflags ^= a
271 #define KFLAG_ISSET(a) info.kflags & a
281 char tmpstring1[TEXT_BUFFER_SIZE];
282 char tmpstring2[TEXT_BUFFER_SIZE];
287 #include <X11/Xlib.h>
288 #include <X11/Xlib.h>
289 #include <X11/Xatom.h>
292 #include <X11/Xft/Xft.h>
295 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
297 #include <X11/extensions/Xdbe.h>
300 #define ATOM(a) XInternAtom(display, #a, False)
302 struct conky_window {
307 XdbeBackBuffer back_buffer;
330 extern Display *display;
331 extern int display_width;
332 extern int display_height;
335 extern int workarea[4];
337 extern struct conky_window window;
340 #if defined OWN_WINDOW
341 void init_window(int use_own_window, char* wm_class_name, int width, int height, int on_bottom, int fixed_pos, int set_trans, int back_colour, char * nodename);
343 void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour, char * nodename);
346 void set_transparent_background(Window win);
347 long get_x11_color(const char *);
353 /* struct that has all info */
354 struct information info;
356 void signal_handler(int);
357 void reload_config(void);
361 double get_time(void);
362 FILE *open_file(const char *file, int *reported);
363 void variable_substitute(const char *s, char *dest, unsigned int n);
364 void format_seconds(char *buf, unsigned int n, long t);
365 void format_seconds_short(char *buf, unsigned int n, long t);
366 struct net_stat *get_net_stat(const char *dev);
370 int round_to_int(float f);
372 #define SET_NEED(a) need_mask |= 1 << (a)
373 extern unsigned long long need_mask;
375 extern double current_update_time, last_update_time;
377 extern int no_buffers;
379 /* system dependant (in linux.c) */
381 void update_diskio(void);
382 void prepare_update(void);
383 void update_uptime(void);
384 void update_meminfo(void);
385 void update_net_stats(void);
386 void update_wifi_stats(void);
387 void update_cpu_usage(void);
388 void update_total_processes(void);
389 void update_running_processes(void);
390 void update_i8k(void);
391 void get_freq( char *, size_t, char *, int ); /* pk */
392 void get_freq_dynamic( char *, size_t, char *, int ); /* pk */
393 void update_load_average();
394 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
396 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
398 void get_adt746x_cpu( char *, size_t ); /* pk */
399 void get_adt746x_fan( char *, size_t ); /* pk */
400 unsigned int get_diskio(void);
402 int open_acpi_temperature(const char *name);
403 double get_acpi_temperature(int fd);
404 void get_acpi_ac_adapter( char *, size_t ); /* pk */
405 void get_acpi_fan( char *, size_t ); /* pk */
406 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
409 struct process *next;
410 struct process *previous;
415 unsigned long user_time;
417 unsigned long kernel_time;
418 unsigned long previous_user_time;
419 unsigned long previous_kernel_time;
422 unsigned int time_stamp;
423 unsigned int counted;
424 unsigned int changed;
429 void free_all_processes();
430 struct process *get_first_process();
432 /* fs-stuff is possibly system dependant (in fs.c) */
434 void update_fs_stats(void);
435 struct fs_stat *prepare_fs_stat(const char *path);
436 void clear_fs_stats(void);
440 int mixer_init(const char *);
441 int mixer_get_avg(int);
442 int mixer_get_left(int);
443 int mixer_get_right(int);
447 extern char *current_mail_spool;
449 void update_mail_count();
454 extern char *seti_dir;
460 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
461 int apm_getinfo(int fd, apm_info_t aip);
462 char *get_apm_adapter(void);
463 char *get_apm_battery_life(void);
464 char *get_apm_battery_time(void);
474 typedef long long int64;
475 /* The info necessary to connect to mldonkey. login and password can be NULL. */
476 typedef struct mldonkey_config {
477 char *mldonkey_hostname;
479 char *mldonkey_login;
480 char *mldonkey_password;
483 /* The MLDonkey status returned */
484 typedef struct mldonkey_info {
485 int64 upload_counter;
486 int64 download_counter;
488 int64 shared_counter;
490 int tcp_download_rate;
492 int udp_download_rate;
493 int ndownloaded_files;
494 int ndownloading_files;
495 int nconnected_networks;
496 int connected_networks[1];
499 extern mldonkey_info mlinfo;
500 extern mldonkey_config mlconfig;
502 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
507 /* nothing to see here */
511 extern int do_it(void);