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;
105 struct thread_info_s {
107 pthread_mutex_t mutex;
110 struct mail_s { // for imap and pop3
111 unsigned long unseen;
112 unsigned long messages;
124 struct thread_info_s thread_info;
129 unsigned int user, nice, system, idle, iowait, irq, softirq;
178 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
180 unsigned int project_mask;
181 unsigned int current_project;
182 xmms_t items; /* e.g. items[XMMS_STATUS] yields char[] */
183 int runnable; /* used to signal worker thread to stop */
184 pthread_t thread; /* worker thread for xmms updating */
185 pthread_attr_t thread_attr; /* thread attributes */
186 pthread_mutex_t item_mutex; /* mutex for item array */
187 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
203 #ifdef TCP_PORT_MONITOR
204 #include "libtcp-portmon.h"
205 #define MIN_PORT_MONITORS_DEFAULT 16
206 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
237 #ifdef TCP_PORT_MONITOR
238 INFO_TCP_PORT_MONITOR = 22,
240 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
253 #include "libmpdclient.h"
256 volatile int g_signal_pending;
261 struct utsname uname_s;
267 /* memory information in kilobytes */
268 unsigned long mem, memmax, swap, swapmax;
269 unsigned long bufmem, buffers, cached;
271 unsigned short procs;
272 unsigned short run_procs;
275 /* struct cpu_stat cpu_summed; what the hell is this? */
276 unsigned int cpu_count;
277 unsigned int cpu_avg_samples;
279 unsigned int net_avg_samples;
283 int new_mail_count, mail_count;
292 mpd_Connection *conn;
295 struct xmms2_s xmms2;
296 int xmms2_conn_state;
297 xmms_socket_t xmms2_fd;
299 xmmsc_connection_t *xmms2_conn;
301 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
307 struct process *cpu[10];
308 struct process *memu[10];
309 struct process *first_process;
310 unsigned long looped;
311 #ifdef TCP_PORT_MONITOR
312 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
314 short kflags; /* kernel settings, see enum KFLAG */
318 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
319 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
320 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
323 #define KFLAG_SETON(a) info.kflags |= a
324 #define KFLAG_SETOFF(a) info.kflags &= (~a)
325 #define KFLAG_FLIP(a) info.kflags ^= a
326 #define KFLAG_ISSET(a) info.kflags & a
336 char tmpstring1[TEXT_BUFFER_SIZE];
337 char tmpstring2[TEXT_BUFFER_SIZE];
342 #include <X11/Xlib.h>
343 #include <X11/Xlib.h>
344 #include <X11/Xatom.h>
347 #include <X11/Xft/Xft.h>
350 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
352 #include <X11/extensions/Xdbe.h>
355 #define ATOM(a) XInternAtom(display, #a, False)
365 HINT_UNDECORATED = 0,
372 #define SET_HINT(mask,hint) (mask |= (1<<hint))
373 #define TEST_HINT(mask,hint) (mask & (1<<hint))
375 struct conky_window {
376 Window root,window,desktop;
380 XdbeBackBuffer back_buffer;
389 char wm_class_name[256];
406 extern Display *display;
407 extern int display_width;
408 extern int display_height;
411 extern int workarea[4];
413 extern struct conky_window window;
416 void init_window(int use_own_window, int width, int height, int set_trans, int back_colour, char * nodename,
417 char **argv, int argc);
419 void set_transparent_background(Window win);
420 long get_x11_color(const char *);
426 /* struct that has all info */
427 struct information info;
429 void signal_handler(int);
430 void reload_config(void);
434 double get_time(void);
435 FILE *open_file(const char *file, int *reported);
436 void variable_substitute(const char *s, char *dest, unsigned int n);
437 void format_seconds(char *buf, unsigned int n, long t);
438 void format_seconds_short(char *buf, unsigned int n, long t);
439 struct net_stat *get_net_stat(const char *dev);
443 int round_to_int(float f);
445 #define SET_NEED(a) need_mask |= 1 << (a)
446 extern unsigned long long need_mask;
448 extern double current_update_time, last_update_time;
450 extern int no_buffers;
452 /* system dependant (in linux.c) */
454 void update_diskio(void);
455 void prepare_update(void);
456 void update_uptime(void);
457 void update_meminfo(void);
458 void update_net_stats(void);
459 void update_wifi_stats(void);
460 void update_cpu_usage(void);
461 void update_total_processes(void);
462 void update_running_processes(void);
463 void update_i8k(void);
464 char get_freq( char *, size_t, char *, int, unsigned int ); /* pk */
465 void get_freq_dynamic( char *, size_t, char *, int ); /* pk */
466 char get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
467 void update_load_average();
468 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
470 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
472 void get_adt746x_cpu( char *, size_t ); /* pk */
473 void get_adt746x_fan( char *, size_t ); /* pk */
474 unsigned int get_diskio(void);
476 int open_acpi_temperature(const char *name);
477 double get_acpi_temperature(int fd);
478 void get_acpi_ac_adapter( char *, size_t ); /* pk */
479 void get_acpi_fan( char *, size_t ); /* pk */
480 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
481 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
482 void get_ibm_acpi_temps(void);
483 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
484 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
485 void get_cpu_count();
487 struct ibm_acpi_struct {
488 unsigned int temps[8];
491 struct ibm_acpi_struct ibm_acpi;
493 enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME};
494 void get_powerbook_batt_info(char*, size_t, int);
497 struct process *next;
498 struct process *previous;
503 unsigned long user_time;
505 unsigned long kernel_time;
506 unsigned long previous_user_time;
507 unsigned long previous_kernel_time;
510 unsigned int time_stamp;
511 unsigned int counted;
512 unsigned int changed;
517 void free_all_processes();
518 struct process *get_first_process();
520 /* fs-stuff is possibly system dependant (in fs.c) */
522 void update_fs_stats(void);
523 struct fs_stat *prepare_fs_stat(const char *path);
524 void clear_fs_stats(void);
528 int mixer_init(const char *);
529 int mixer_get_avg(int);
530 int mixer_get_left(int);
531 int mixer_get_right(int);
535 extern char *current_mail_spool;
537 void update_mail_count();
542 extern char *seti_dir;
548 #if defined(__FreeBSD__)
552 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
553 int apm_getinfo(int fd, apm_info_t aip);
554 char *get_apm_adapter(void);
555 char *get_apm_battery_life(void);
556 char *get_apm_battery_time(void);
571 typedef long long int64;
572 /* The info necessary to connect to mldonkey. login and password can be NULL. */
573 typedef struct mldonkey_config {
574 char *mldonkey_hostname;
576 char *mldonkey_login;
577 char *mldonkey_password;
580 /* The MLDonkey status returned */
581 typedef struct mldonkey_info {
582 int64 upload_counter;
583 int64 download_counter;
585 int64 shared_counter;
587 int tcp_download_rate;
589 int udp_download_rate;
590 int ndownloaded_files;
591 int ndownloading_files;
592 int nconnected_networks;
593 int connected_networks[1];
596 extern mldonkey_info mlinfo;
597 extern mldonkey_config mlconfig;
599 int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
604 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port);
605 char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);
610 /* nothing to see here */
613 extern int do_it(void);