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__ */
31 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
32 #include <machine/apm_bios.h>
33 #endif /* __FreeBSD__ */
36 #include "audacious.h"
40 #include <xmmsclient/xmmsclient.h>
48 #define TEXT_BUFFER_SIZE 1280
49 #define P_MAX_SIZE ((TEXT_BUFFER_SIZE * 4) - 2)
51 #include <sys/socket.h>
53 #define ERR(s, varargs...) \
54 fprintf(stderr, "Conky: " s "\n", ##varargs)
57 #define CRIT_ERR(s, varargs...) \
58 { fprintf(stderr, "Conky: " s "\n", ##varargs); exit(EXIT_FAILURE); }
65 char *left_fan_status;
66 char *right_fan_status;
73 struct i8k_struct i8k;
78 long long last_read_recv, last_read_trans;
79 long long recv, trans;
80 double recv_speed, trans_speed;
83 double net_rec[15], net_trans[15];
86 unsigned int diskio_value;
95 struct thread_info_s {
97 pthread_mutex_t mutex;
100 struct mail_s { // for imap and pop3
101 unsigned long unseen;
102 unsigned long messages;
114 struct thread_info_s thread_info;
119 unsigned int user, nice, system, idle, iowait, irq, softirq;
170 audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */
171 int runnable; /* used to signal worker thread to stop */
172 pthread_t thread; /* worker thread */
173 pthread_attr_t thread_attr; /* thread attributes */
174 pthread_mutex_t item_mutex; /* mutex for item array */
175 pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
191 #ifdef TCP_PORT_MONITOR
192 #include "libtcp-portmon.h"
193 #define MIN_PORT_MONITORS_DEFAULT 16
194 #define MIN_PORT_MONITOR_CONNECTIONS_DEFAULT 256
219 #ifdef TCP_PORT_MONITOR
220 INFO_TCP_PORT_MONITOR = 19,
235 #include "libmpdclient.h"
238 volatile int g_signal_pending;
243 struct utsname uname_s;
249 /* memory information in kilobytes */
250 unsigned long mem, memmax, swap, swapmax;
251 unsigned long bufmem, buffers, cached;
253 unsigned short procs;
254 unsigned short run_procs;
257 /* struct cpu_stat cpu_summed; what the hell is this? */
258 unsigned int cpu_count;
259 unsigned int cpu_avg_samples;
261 unsigned int net_avg_samples;
265 int new_mail_count, mail_count;
270 mpd_Connection *conn;
273 struct xmms2_s xmms2;
274 int xmms2_conn_state;
275 xmms_socket_t xmms2_fd;
277 xmmsc_connection_t *xmms2_conn;
280 struct audacious_s audacious;
285 struct process *cpu[10];
286 struct process *memu[10];
287 struct process *first_process;
288 unsigned long looped;
289 #ifdef TCP_PORT_MONITOR
290 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
292 short kflags; /* kernel settings, see enum KFLAG */
296 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
297 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
298 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
301 #define KFLAG_SETON(a) info.kflags |= a
302 #define KFLAG_SETOFF(a) info.kflags &= (~a)
303 #define KFLAG_FLIP(a) info.kflags ^= a
304 #define KFLAG_ISSET(a) info.kflags & a
314 char tmpstring1[TEXT_BUFFER_SIZE];
315 char tmpstring2[TEXT_BUFFER_SIZE];
320 #include <X11/Xlib.h>
321 #include <X11/Xlib.h>
322 #include <X11/Xatom.h>
325 #include <X11/Xft/Xft.h>
329 #include <X11/extensions/Xdbe.h>
332 #define ATOM(a) XInternAtom(display, #a, False)
342 HINT_UNDECORATED = 0,
349 #define SET_HINT(mask,hint) (mask |= (1<<hint))
350 #define TEST_HINT(mask,hint) (mask & (1<<hint))
352 struct conky_window {
353 Window root,window,desktop;
357 XdbeBackBuffer back_buffer;
366 char wm_class_name[256];
383 extern Display *display;
384 extern int display_width;
385 extern int display_height;
388 extern int workarea[4];
390 extern struct conky_window window;
393 void init_window(int use_own_window, int width, int height, int set_trans, int back_colour, char * nodename,
394 char **argv, int argc);
396 void set_transparent_background(Window win);
397 long get_x11_color(const char *);
403 /* struct that has all info */
404 struct information info;
406 void signal_handler(int);
407 void reload_config(void);
411 double get_time(void);
412 FILE *open_file(const char *file, int *reported);
413 void variable_substitute(const char *s, char *dest, unsigned int n);
414 void format_seconds(char *buf, unsigned int n, long t);
415 void format_seconds_short(char *buf, unsigned int n, long t);
416 struct net_stat *get_net_stat(const char *dev);
420 int round_to_int(float f);
422 #define SET_NEED(a) need_mask |= 1 << (a)
423 extern unsigned long long need_mask;
425 extern double current_update_time, last_update_time;
427 extern int no_buffers;
429 /* system dependant (in linux.c) */
431 void update_diskio(void);
432 void prepare_update(void);
433 void update_uptime(void);
434 void update_meminfo(void);
435 void update_net_stats(void);
436 void update_wifi_stats(void);
437 void update_cpu_usage(void);
438 void update_total_processes(void);
439 void update_running_processes(void);
440 void update_i8k(void);
441 char get_freq( char *, size_t, char *, int, unsigned int );
442 void get_freq_dynamic( char *, size_t, char *, int );
443 char get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
444 void update_load_average();
445 int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
447 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
449 void get_adt746x_cpu( char *, size_t );
450 void get_adt746x_fan( char *, size_t );
451 unsigned int get_diskio(void);
453 int open_acpi_temperature(const char *name);
454 double get_acpi_temperature(int fd);
455 void get_acpi_ac_adapter( char *, size_t );
456 void get_acpi_fan( char *, size_t );
457 void get_battery_stuff(char *buf, unsigned int n, const char *bat);
458 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
459 void get_ibm_acpi_temps(void);
460 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
461 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
462 void get_cpu_count();
464 struct ibm_acpi_struct {
465 unsigned int temps[8];
468 struct ibm_acpi_struct ibm_acpi;
470 enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME};
471 void get_powerbook_batt_info(char*, size_t, int);
474 struct process *next;
475 struct process *previous;
480 unsigned long user_time;
482 unsigned long kernel_time;
483 unsigned long previous_user_time;
484 unsigned long previous_kernel_time;
487 unsigned int time_stamp;
488 unsigned int counted;
489 unsigned int changed;
494 void free_all_processes();
495 struct process *get_first_process();
497 /* fs-stuff is possibly system dependant (in fs.c) */
499 void update_fs_stats(void);
500 struct fs_stat *prepare_fs_stat(const char *path);
501 void clear_fs_stats(void);
505 int mixer_init(const char *);
506 int mixer_get_avg(int);
507 int mixer_get_left(int);
508 int mixer_get_right(int);
512 extern char *current_mail_spool;
514 void update_mail_count();
517 #if defined(__FreeBSD__)
521 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
522 int apm_getinfo(int fd, apm_info_t aip);
523 char *get_apm_adapter(void);
524 char *get_apm_battery_life(void);
525 char *get_apm_battery_time(void);
540 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port);
541 char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);