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__ */
46 #include "audacious.h"
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;
180 audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */
181 int runnable; /* used to signal worker thread to stop */
182 pthread_t thread; /* worker thread */
183 pthread_attr_t thread_attr; /* thread attributes */
184 pthread_mutex_t item_mutex; /* mutex for item array */
185 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
201 #ifdef TCP_PORT_MONITOR
202 #include "libtcp-portmon.h"
203 #define MIN_PORT_MONITORS_DEFAULT 16
204 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
229 #ifdef TCP_PORT_MONITOR
230 INFO_TCP_PORT_MONITOR = 19,
245 #include "libmpdclient.h"
248 volatile int g_signal_pending;
253 struct utsname uname_s;
259 /* memory information in kilobytes */
260 unsigned long mem, memmax, swap, swapmax;
261 unsigned long bufmem, buffers, cached;
263 unsigned short procs;
264 unsigned short run_procs;
267 /* struct cpu_stat cpu_summed; what the hell is this? */
268 unsigned int cpu_count;
269 unsigned int cpu_avg_samples;
271 unsigned int net_avg_samples;
275 int new_mail_count, mail_count;
280 mpd_Connection *conn;
283 struct xmms2_s xmms2;
284 int xmms2_conn_state;
285 xmms_socket_t xmms2_fd;
287 xmmsc_connection_t *xmms2_conn;
290 struct audacious_s audacious;
295 struct process *cpu[10];
296 struct process *memu[10];
297 struct process *first_process;
298 unsigned long looped;
299 #ifdef TCP_PORT_MONITOR
300 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
302 short kflags; /* kernel settings, see enum KFLAG */
306 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
307 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
308 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
311 #define KFLAG_SETON(a) info.kflags |= a
312 #define KFLAG_SETOFF(a) info.kflags &= (~a)
313 #define KFLAG_FLIP(a) info.kflags ^= a
314 #define KFLAG_ISSET(a) info.kflags & a
324 char tmpstring1[TEXT_BUFFER_SIZE];
325 char tmpstring2[TEXT_BUFFER_SIZE];
330 #include <X11/Xlib.h>
331 #include <X11/Xlib.h>
332 #include <X11/Xatom.h>
335 #include <X11/Xft/Xft.h>
338 #if defined(HAVE_XDBE) && defined(DOUBLE_BUFFER)
340 #include <X11/extensions/Xdbe.h>
343 #define ATOM(a) XInternAtom(display, #a, False)
353 HINT_UNDECORATED = 0,
360 #define SET_HINT(mask,hint) (mask |= (1<<hint))
361 #define TEST_HINT(mask,hint) (mask & (1<<hint))
363 struct conky_window {
364 Window root,window,desktop;
368 XdbeBackBuffer back_buffer;
377 char wm_class_name[256];
394 extern Display *display;
395 extern int display_width;
396 extern int display_height;
399 extern int workarea[4];
401 extern struct conky_window window;
404 void init_window(int use_own_window, int width, int height, int set_trans, int back_colour, char * nodename,
405 char **argv, int argc);
407 void set_transparent_background(Window win);
408 long get_x11_color(const char *);
414 /* struct that has all info */
415 struct information info;
417 void signal_handler(int);
418 void reload_config(void);
422 double get_time(void);
423 FILE *open_file(const char *file, int *reported);
424 void variable_substitute(const char *s, char *dest, unsigned int n);
425 void format_seconds(char *buf, unsigned int n, long t);
426 void format_seconds_short(char *buf, unsigned int n, long t);
427 struct net_stat *get_net_stat(const char *dev);
431 int round_to_int(float f);
433 #define SET_NEED(a) need_mask |= 1 << (a)
434 extern unsigned long long need_mask;
436 extern double current_update_time, last_update_time;
438 extern int no_buffers;
440 /* system dependant (in linux.c) */
442 void update_diskio(void);
443 void prepare_update(void);
444 void update_uptime(void);
445 void update_meminfo(void);
446 void update_net_stats(void);
447 void update_wifi_stats(void);
448 void update_cpu_usage(void);
449 void update_total_processes(void);
450 void update_running_processes(void);
451 void update_i8k(void);
452 char get_freq( char *, size_t, char *, int, unsigned int );
453 void get_freq_dynamic( char *, size_t, char *, int );
454 char get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
455 void update_load_average();
456 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
458 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
460 void get_adt746x_cpu( char *, size_t );
461 void get_adt746x_fan( char *, size_t );
462 unsigned int get_diskio(void);
464 int open_acpi_temperature(const char *name);
465 double get_acpi_temperature(int fd);
466 void get_acpi_ac_adapter( char *, size_t );
467 void get_acpi_fan( char *, size_t );
468 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
469 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
470 void get_ibm_acpi_temps(void);
471 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
472 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
473 void get_cpu_count();
475 struct ibm_acpi_struct {
476 unsigned int temps[8];
479 struct ibm_acpi_struct ibm_acpi;
481 enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME};
482 void get_powerbook_batt_info(char*, size_t, int);
485 struct process *next;
486 struct process *previous;
491 unsigned long user_time;
493 unsigned long kernel_time;
494 unsigned long previous_user_time;
495 unsigned long previous_kernel_time;
498 unsigned int time_stamp;
499 unsigned int counted;
500 unsigned int changed;
505 void free_all_processes();
506 struct process *get_first_process();
508 /* fs-stuff is possibly system dependant (in fs.c) */
510 void update_fs_stats(void);
511 struct fs_stat *prepare_fs_stat(const char *path);
512 void clear_fs_stats(void);
516 int mixer_init(const char *);
517 int mixer_get_avg(int);
518 int mixer_get_left(int);
519 int mixer_get_right(int);
523 extern char *current_mail_spool;
525 void update_mail_count();
528 #if defined(__FreeBSD__)
532 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
533 int apm_getinfo(int fd, apm_info_t aip);
534 char *get_apm_adapter(void);
535 char *get_apm_battery_life(void);
536 char *get_apm_battery_time(void);
551 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port);
552 char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);
557 /* nothing to see here */
560 extern int do_it(void);