2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
12 #if defined(AUDACIOUS) || defined(INFOPIPE)
15 #if defined(HAS_MCHECK_H)
17 #endif /* HAS_MCHECK_H */
19 #include <sys/utsname.h>
25 #include <sys/param.h>
26 #if defined(__FreeBSD__)
27 #include <sys/mount.h>
28 #include <sys/ucred.h>
29 #endif /* __FreeBSD__ */
32 #if defined(HAVE_CAIRO_H) && defined(HAVE_CAIRO_XLIB_H) && defined(WANT_CAIRO)
35 #include <X11/Xutil.h>
37 #include <cairo-xlib.h>
41 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
42 #include <machine/apm_bios.h>
43 #endif /* __FreeBSD__ */
50 #define TEXT_BUFFER_SIZE 1024
51 #define P_MAX_SIZE ((TEXT_BUFFER_SIZE * 4) - 2)
53 #include <sys/socket.h>
55 #define ERR(s, varargs...) \
56 fprintf(stderr, "Conky: " s "\n", ##varargs)
59 #define CRIT_ERR(s, varargs...) \
60 { fprintf(stderr, "Conky: " s "\n", ##varargs); exit(EXIT_FAILURE); }
64 #define MIN(a,b) (a>b ? b : a)
67 #define MAX(a,b) (a<b ? b : a)
76 char *left_fan_status;
77 char *right_fan_status;
84 struct i8k_struct i8k;
89 long long last_read_recv, last_read_trans;
90 long long recv, trans;
91 double recv_speed, trans_speed;
94 double net_rec[15], net_trans[15];
97 unsigned int diskio_value;
107 unsigned int user, nice, system, idle, iowait, irq, softirq;
131 #include "audacious.h"
133 audacious_t items; /* e.g. items[AUDACIOUS_STATUS] yields char[] */
134 int runnable; /* used to signal infopipe thread to stop */
135 pthread_t thread; /* worker thread for infopipe updating */
136 pthread_attr_t thread_attr; /* thread attributes */
137 pthread_mutex_t item_mutex; /* mutex for item array */
138 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
155 #include "infopipe.h"
157 infopipe_t items; /* e.g. items[INFOPIPE_STATUS] yields char[] */
158 int runnable; /* used to signal infopipe thread to stop */
159 pthread_t thread; /* worker thread for infopipe updating */
160 pthread_attr_t thread_attr; /* thread attributes */
161 pthread_mutex_t item_mutex; /* mutex for item array */
162 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
166 #ifdef TCP_PORT_MONITOR
167 #include "libtcp-portmon.h"
168 #define MIN_PORT_MONITORS_DEFAULT 16
169 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
200 #ifdef TCP_PORT_MONITOR
201 INFO_TCP_PORT_MONITOR = 22,
216 #include "libmpdclient.h"
219 volatile int g_signal_pending;
224 struct utsname uname_s;
230 /* memory information in kilobytes */
231 unsigned long mem, memmax, swap, swapmax;
232 unsigned long bufmem, buffers, cached;
234 unsigned short procs;
235 unsigned short run_procs;
238 /* struct cpu_stat cpu_summed; what the hell is this? */
239 unsigned int cpu_count;
240 unsigned int cpu_avg_samples;
242 unsigned int net_avg_samples;
246 int new_mail_count, mail_count;
253 mpd_Connection *conn;
256 struct audacious_s audacious;
262 struct infopipe_s infopipe;
264 struct process *cpu[10];
265 struct process *memu[10];
266 struct process *first_process;
267 unsigned long looped;
268 #ifdef TCP_PORT_MONITOR
269 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
271 short kflags; /* kernel settings, see enum KFLAG */
275 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
276 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
277 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
280 #define KFLAG_SETON(a) info.kflags |= a
281 #define KFLAG_SETOFF(a) info.kflags &= (~a)
282 #define KFLAG_FLIP(a) info.kflags ^= a
283 #define KFLAG_ISSET(a) info.kflags & a
293 char tmpstring1[TEXT_BUFFER_SIZE];
294 char tmpstring2[TEXT_BUFFER_SIZE];
299 #include <X11/Xlib.h>
300 #include <X11/Xlib.h>
301 #include <X11/Xatom.h>
304 #include <X11/Xft/Xft.h>
307 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
309 #include <X11/extensions/Xdbe.h>
312 #define ATOM(a) XInternAtom(display, #a, False)
314 struct conky_window {
319 XdbeBackBuffer back_buffer;
342 extern Display *display;
343 extern int display_width;
344 extern int display_height;
347 extern int workarea[4];
349 extern struct conky_window window;
352 #if defined OWN_WINDOW
353 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);
355 void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour, char * nodename);
358 void set_transparent_background(Window win);
359 long get_x11_color(const char *);
365 /* struct that has all info */
366 struct information info;
368 void signal_handler(int);
369 void reload_config(void);
373 double get_time(void);
374 FILE *open_file(const char *file, int *reported);
375 void variable_substitute(const char *s, char *dest, unsigned int n);
376 void format_seconds(char *buf, unsigned int n, long t);
377 void format_seconds_short(char *buf, unsigned int n, long t);
378 struct net_stat *get_net_stat(const char *dev);
382 int round_to_int(float f);
384 #define SET_NEED(a) need_mask |= 1 << (a)
385 extern unsigned long long need_mask;
387 extern double current_update_time, last_update_time;
389 extern int no_buffers;
391 /* system dependant (in linux.c) */
393 void update_diskio(void);
394 void prepare_update(void);
395 void update_uptime(void);
396 void update_meminfo(void);
397 void update_net_stats(void);
398 void update_wifi_stats(void);
399 void update_cpu_usage(void);
400 void update_total_processes(void);
401 void update_running_processes(void);
402 void update_i8k(void);
403 void get_freq( char *, size_t, char *, int ); /* pk */
404 void get_freq_dynamic( char *, size_t, char *, int ); /* pk */
405 void update_load_average();
406 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
408 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
410 void get_adt746x_cpu( char *, size_t ); /* pk */
411 void get_adt746x_fan( char *, size_t ); /* pk */
412 unsigned int get_diskio(void);
414 int open_acpi_temperature(const char *name);
415 double get_acpi_temperature(int fd);
416 void get_acpi_ac_adapter( char *, size_t ); /* pk */
417 void get_acpi_fan( char *, size_t ); /* pk */
418 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
421 struct process *next;
422 struct process *previous;
427 unsigned long user_time;
429 unsigned long kernel_time;
430 unsigned long previous_user_time;
431 unsigned long previous_kernel_time;
434 unsigned int time_stamp;
435 unsigned int counted;
436 unsigned int changed;
441 void free_all_processes();
442 struct process *get_first_process();
444 /* fs-stuff is possibly system dependant (in fs.c) */
446 void update_fs_stats(void);
447 struct fs_stat *prepare_fs_stat(const char *path);
448 void clear_fs_stats(void);
452 int mixer_init(const char *);
453 int mixer_get_avg(int);
454 int mixer_get_left(int);
455 int mixer_get_right(int);
459 extern char *current_mail_spool;
461 void update_mail_count();
466 extern char *seti_dir;
472 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
473 int apm_getinfo(int fd, apm_info_t aip);
474 char *get_apm_adapter(void);
475 char *get_apm_battery_life(void);
476 char *get_apm_battery_time(void);
486 typedef long long int64;
487 /* The info necessary to connect to mldonkey. login and password can be NULL. */
488 typedef struct mldonkey_config {
489 char *mldonkey_hostname;
491 char *mldonkey_login;
492 char *mldonkey_password;
495 /* The MLDonkey status returned */
496 typedef struct mldonkey_info {
497 int64 upload_counter;
498 int64 download_counter;
500 int64 shared_counter;
502 int tcp_download_rate;
504 int udp_download_rate;
505 int ndownloaded_files;
506 int ndownloading_files;
507 int nconnected_networks;
508 int connected_networks[1];
511 extern mldonkey_info mlinfo;
512 extern mldonkey_config mlconfig;
514 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
519 /* nothing to see here */
523 extern int do_it(void);