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>
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__ */
45 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
50 #include <xmmsclient/xmmsclient.h>
58 #define TEXT_BUFFER_SIZE 1280
59 #define P_MAX_SIZE ((TEXT_BUFFER_SIZE * 4) - 2)
61 #include <sys/socket.h>
63 #define ERR(s, varargs...) \
64 fprintf(stderr, "Conky: " s "\n", ##varargs)
67 #define CRIT_ERR(s, varargs...) \
68 { fprintf(stderr, "Conky: " s "\n", ##varargs); exit(EXIT_FAILURE); }
75 char *left_fan_status;
76 char *right_fan_status;
83 struct i8k_struct i8k;
88 long long last_read_recv, last_read_trans;
89 long long recv, trans;
90 double recv_speed, trans_speed;
93 double net_rec[15], net_trans[15];
96 unsigned int diskio_value;
106 unsigned int user, nice, system, idle, iowait, irq, softirq;
147 unsigned int elapsed;
151 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
153 unsigned int project_mask;
154 unsigned int current_project;
155 xmms_t items; /* e.g. items[XMMS_STATUS] yields char[] */
156 int runnable; /* used to signal worker thread to stop */
157 pthread_t thread; /* worker thread for xmms updating */
158 pthread_attr_t thread_attr; /* thread attributes */
159 pthread_mutex_t item_mutex; /* mutex for item array */
160 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
176 #ifdef TCP_PORT_MONITOR
177 #include "libtcp-portmon.h"
178 #define MIN_PORT_MONITORS_DEFAULT 16
179 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
210 #ifdef TCP_PORT_MONITOR
211 INFO_TCP_PORT_MONITOR = 22,
213 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
226 #include "libmpdclient.h"
229 volatile int g_signal_pending;
234 struct utsname uname_s;
240 /* memory information in kilobytes */
241 unsigned long mem, memmax, swap, swapmax;
242 unsigned long bufmem, buffers, cached;
244 unsigned short procs;
245 unsigned short run_procs;
248 /* struct cpu_stat cpu_summed; what the hell is this? */
249 unsigned int cpu_count;
250 unsigned int cpu_avg_samples;
252 unsigned int net_avg_samples;
256 int new_mail_count, mail_count;
263 mpd_Connection *conn;
266 struct xmms2_s xmms2;
267 int xmms2_conn_state;
268 xmms_socket_t xmms2_fd;
270 xmmsc_connection_t *xmms2_conn;
272 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
278 struct process *cpu[10];
279 struct process *memu[10];
280 struct process *first_process;
281 unsigned long looped;
282 #ifdef TCP_PORT_MONITOR
283 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
285 short kflags; /* kernel settings, see enum KFLAG */
289 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
290 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
291 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
294 #define KFLAG_SETON(a) info.kflags |= a
295 #define KFLAG_SETOFF(a) info.kflags &= (~a)
296 #define KFLAG_FLIP(a) info.kflags ^= a
297 #define KFLAG_ISSET(a) info.kflags & a
307 char tmpstring1[TEXT_BUFFER_SIZE];
308 char tmpstring2[TEXT_BUFFER_SIZE];
313 #include <X11/Xlib.h>
314 #include <X11/Xlib.h>
315 #include <X11/Xatom.h>
318 #include <X11/Xft/Xft.h>
321 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
323 #include <X11/extensions/Xdbe.h>
326 #define ATOM(a) XInternAtom(display, #a, False)
336 HINT_UNDECORATED = 0,
343 #define SET_HINT(mask,hint) (mask |= (1<<hint))
344 #define TEST_HINT(mask,hint) (mask & (1<<hint))
346 struct conky_window {
347 Window root,window,desktop;
351 XdbeBackBuffer back_buffer;
360 char wm_class_name[256];
377 extern Display *display;
378 extern int display_width;
379 extern int display_height;
382 extern int workarea[4];
384 extern struct conky_window window;
387 void init_window(int use_own_window, int width, int height, int set_trans, int back_colour, char * nodename,
388 char **argv, int argc);
390 void set_transparent_background(Window win);
391 long get_x11_color(const char *);
397 /* struct that has all info */
398 struct information info;
400 void signal_handler(int);
401 void reload_config(void);
405 double get_time(void);
406 FILE *open_file(const char *file, int *reported);
407 void variable_substitute(const char *s, char *dest, unsigned int n);
408 void format_seconds(char *buf, unsigned int n, long t);
409 void format_seconds_short(char *buf, unsigned int n, long t);
410 struct net_stat *get_net_stat(const char *dev);
414 int round_to_int(float f);
416 #define SET_NEED(a) need_mask |= 1 << (a)
417 extern unsigned long long need_mask;
419 extern double current_update_time, last_update_time;
421 extern int no_buffers;
423 /* system dependant (in linux.c) */
425 void update_diskio(void);
426 void prepare_update(void);
427 void update_uptime(void);
428 void update_meminfo(void);
429 void update_net_stats(void);
430 void update_wifi_stats(void);
431 void update_cpu_usage(void);
432 void update_total_processes(void);
433 void update_running_processes(void);
434 void update_i8k(void);
435 void get_freq( char *, size_t, char *, int ); /* pk */
436 void get_freq_dynamic( char *, size_t, char *, int ); /* pk */
437 void update_load_average();
438 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
440 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
442 void get_adt746x_cpu( char *, size_t ); /* pk */
443 void get_adt746x_fan( char *, size_t ); /* pk */
444 unsigned int get_diskio(void);
446 int open_acpi_temperature(const char *name);
447 double get_acpi_temperature(int fd);
448 void get_acpi_ac_adapter( char *, size_t ); /* pk */
449 void get_acpi_fan( char *, size_t ); /* pk */
450 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
453 struct process *next;
454 struct process *previous;
459 unsigned long user_time;
461 unsigned long kernel_time;
462 unsigned long previous_user_time;
463 unsigned long previous_kernel_time;
466 unsigned int time_stamp;
467 unsigned int counted;
468 unsigned int changed;
473 void free_all_processes();
474 struct process *get_first_process();
476 /* fs-stuff is possibly system dependant (in fs.c) */
478 void update_fs_stats(void);
479 struct fs_stat *prepare_fs_stat(const char *path);
480 void clear_fs_stats(void);
484 int mixer_init(const char *);
485 int mixer_get_avg(int);
486 int mixer_get_left(int);
487 int mixer_get_right(int);
491 extern char *current_mail_spool;
493 void update_mail_count();
498 extern char *seti_dir;
504 #if defined(__FreeBSD__)
508 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
509 int apm_getinfo(int fd, apm_info_t aip);
510 char *get_apm_adapter(void);
511 char *get_apm_battery_life(void);
512 char *get_apm_battery_time(void);
527 typedef long long int64;
528 /* The info necessary to connect to mldonkey. login and password can be NULL. */
529 typedef struct mldonkey_config {
530 char *mldonkey_hostname;
532 char *mldonkey_login;
533 char *mldonkey_password;
536 /* The MLDonkey status returned */
537 typedef struct mldonkey_info {
538 int64 upload_counter;
539 int64 download_counter;
541 int64 shared_counter;
543 int tcp_download_rate;
545 int udp_download_rate;
546 int ndownloaded_files;
547 int ndownloading_files;
548 int nconnected_networks;
549 int connected_networks[1];
552 extern mldonkey_info mlinfo;
553 extern mldonkey_config mlconfig;
555 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
560 /* nothing to see here */
564 extern int do_it(void);