1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #if defined(HAS_MCHECK_H)
35 #endif /* HAS_MCHECK_H */
38 #include <sys/utsname.h>
45 #include <sys/param.h>
47 #if !defined(__GNUC__)
48 # define __attribute__(x) /* nothing */
51 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
52 #include <sys/mount.h>
53 #include <sys/ucred.h>
56 #if (defined(i386) || defined(__i386__))
57 #include <machine/apm_bios.h>
58 #endif /* i386 || __i386__ */
59 #endif /* __FreeBSD__ */
61 #if defined(__OpenBSD__)
62 #include <sys/sysctl.h>
63 #include <sys/sensors.h>
64 #include <machine/apmvar.h>
65 #endif /* __OpenBSD__ */
68 // use our own strndup() if it's not available
69 char *strndup(const char *s, size_t n);
70 #endif /* HAVE_STRNDUP */
73 #include "audacious.h"
77 #include <xmmsclient/xmmsclient.h>
93 #include "timed_thread.h"
105 #define DEFAULT_TEXT_BUFFER_SIZE 256
106 extern unsigned int text_buffer_size;
108 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
109 #define MAX_SPECIALS_DEFAULT 512
111 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
112 #define MAX_USER_TEXT_DEFAULT 16384
114 #include <sys/socket.h>
117 fprintf(stderr, "Conky: "); \
118 fprintf(stderr, __VA_ARGS__); \
119 fprintf(stderr, "\n"); \
123 #define CRIT_ERR(...) \
124 { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
131 char *left_fan_status;
132 char *right_fan_status;
136 char *buttons_status;
139 struct i8k_struct i8k;
144 long long last_read_recv, last_read_trans;
145 long long recv, trans;
146 double recv_speed, trans_speed;
147 struct sockaddr addr;
149 double net_rec[15], net_trans[15];
150 // wireless extensions
164 unsigned int diskio_value;
165 unsigned int diskio_read_value;
166 unsigned int diskio_write_value;
169 char path[DEFAULT_TEXT_BUFFER_SIZE];
170 char type[DEFAULT_TEXT_BUFFER_SIZE];
179 struct mail_s { // for imap and pop3
180 unsigned long unseen;
181 unsigned long messages;
192 timed_thread *p_timed_thread;
197 unsigned int user, nice, system, idle, iowait, irq, softirq;
220 int max_title_len; /* e.g. ${mpd_title 50} */
250 audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */
251 int max_title_len; /* e.g. ${audacious_title 50} */
252 timed_thread *p_timed_thread;
257 void update_bmpx(void);
268 void update_entropy(void);
270 unsigned int entropy_avail;
271 unsigned int poolsize;
281 struct gateway_info {
287 #ifdef TCP_PORT_MONITOR
288 #include "libtcp-portmon.h"
289 #define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256
314 #ifdef TCP_PORT_MONITOR
315 INFO_TCP_PORT_MONITOR = 19,
342 /* get_battery_stuff() item selector */
348 /* if_up strictness selector */
356 #include "libmpdclient.h"
359 /* Update interval */
360 double update_interval;
362 volatile int g_signal_pending;
367 struct utsname uname_s;
373 /* memory information in kilobytes */
374 unsigned long long mem, memmax, swap, swapmax;
375 unsigned long long bufmem, buffers, cached;
377 unsigned short procs;
378 unsigned short run_procs;
381 /* struct cpu_stat cpu_summed; what the hell is this? */
382 unsigned int cpu_count;
383 unsigned int cpu_avg_samples;
385 unsigned int net_avg_samples;
393 mpd_Connection *conn;
396 struct xmms2_s xmms2;
397 int xmms2_conn_state;
398 xmms_socket_t xmms2_fd;
400 xmmsc_connection_t *xmms2_conn;
403 struct audacious_s audacious;
408 struct usr_info users;
409 struct gateway_info gw_info;
410 struct dns_data nameserver_info;
411 struct process *cpu[10];
412 struct process *memu[10];
413 struct process *first_process;
414 unsigned long looped;
415 #ifdef TCP_PORT_MONITOR
416 tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
418 struct entropy_s entropy;
419 double music_player_interval;
421 short kflags; /* kernel settings, see enum KFLAG */
425 /* set to true if kernel uses "long" format for /proc/stats */
426 KFLAG_IS_LONGSTAT = 0x01,
427 /* set to true if kernel shows # of threads for the proc value
428 * in sysinfo() call */
429 KFLAG_PROC_IS_THREADS = 0x02
430 /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
431 /* KFLAG_NEXT_ONE = 0x04 */
434 #define KFLAG_SETON(a) info.kflags |= a
435 #define KFLAG_SETOFF(a) info.kflags &= (~a)
436 #define KFLAG_FLIP(a) info.kflags ^= a
437 #define KFLAG_ISSET(a) info.kflags & a
446 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
454 #include <X11/Xlib.h>
455 #include <X11/Xlib.h>
456 #include <X11/Xatom.h>
459 #include <X11/Xft/Xft.h>
463 #include <X11/extensions/Xdbe.h>
466 #define ATOM(a) XInternAtom(display, #a, False)
477 HINT_UNDECORATED = 0,
485 #define SET_HINT(mask, hint) (mask |= (1 << hint))
486 #define TEST_HINT(mask, hint) (mask & (1 << hint))
489 struct conky_window {
490 Window root, window, desktop;
494 XdbeBackBuffer back_buffer;
503 char class_name[256];
520 extern Display *display;
521 extern int display_width;
522 extern int display_height;
525 extern int workarea[4];
527 extern struct conky_window window;
530 void init_window(int use_own_window, int width, int height, int set_trans,
531 int back_colour, char **argv, int argc);
532 void create_gc(void);
533 void set_transparent_background(Window win);
534 long get_x11_color(const char *);
543 /* struct that has all info */
544 struct information info;
546 void signal_handler(int);
547 void reload_config(void);
550 void update_uname(void);
551 double get_time(void);
552 FILE *open_file(const char *file, int *reported);
553 void variable_substitute(const char *s, char *dest, unsigned int n);
554 void format_seconds(char *buf, unsigned int n, long t);
555 void format_seconds_short(char *buf, unsigned int n, long t);
556 struct net_stat *get_net_stat(const char *dev);
557 void clear_net_stats(void);
558 void free_dns_data(void);
559 void update_dns_data(void);
560 void update_users(void);
562 void update_stuff(void);
564 int round_to_int(float f);
566 extern unsigned long long need_mask;
568 extern double current_update_time, last_update_time;
570 extern int no_buffers;
572 /* system dependant (in linux.c) */
574 int check_mount(char *s);
575 void update_diskio(void);
576 void prepare_update(void);
577 void update_uptime(void);
578 void update_meminfo(void);
579 void update_net_stats(void);
580 void update_cpu_usage(void);
581 void update_total_processes(void);
582 void update_running_processes(void);
583 void update_i8k(void);
584 char get_freq(char *, size_t, const char *, int, unsigned int);
585 void get_freq_dynamic(char *, size_t, const char *, int);
586 char get_voltage(char *, size_t, const char *, int, unsigned int); /* ptarjan */
587 void update_load_average(void);
588 int interface_up(const char *dev);
589 char *get_ioscheduler(char *);
590 int get_laptop_mode(void);
591 void update_gateway_info(void);
593 int open_sysfs_sensor(const char *dir, const char *dev, const char *type, int n,
594 int *divisor, char *devtype);
596 #define open_i2c_sensor(dev, type, n, divisor, devtype) \
597 open_sysfs_sensor("/sys/bus/i2c/devices/", dev, type, n, divisor, devtype)
598 #define open_platform_sensor(dev, type, n, divisor, devtype) \
599 open_sysfs_sensor("/sys/bus/platform/devices/", dev, type, n, divisor, devtype)
600 #define open_hwmon_sensor(dev, type, n, divisor, devtype) \
601 open_sysfs_sensor("/sys/class/hwmon/", dev, type, n, divisor, devtype)
603 double get_sysfs_info(int *fd, int arg, char *devtype, char *type);
605 void get_adt746x_cpu(char *, size_t);
606 void get_adt746x_fan(char *, size_t);
607 unsigned int get_diskio(void);
609 int open_acpi_temperature(const char *name);
610 double get_acpi_temperature(int fd);
611 void get_acpi_ac_adapter(char *, size_t);
612 void get_acpi_fan(char *, size_t);
613 void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
614 int get_battery_perct(const char *bat);
615 int get_battery_perct_bar(const char *bat);
616 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
617 void get_ibm_acpi_temps(void);
618 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
619 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
620 const char *get_disk_protect_queue(const char *);
621 void get_cpu_count(void);
623 struct ibm_acpi_struct {
627 struct ibm_acpi_struct ibm_acpi;
629 #if defined(__OpenBSD__)
630 void update_obsd_sensors(void);
631 void get_obsd_vendor(char *buf, size_t client_buffer_size);
632 void get_obsd_product(char *buf, size_t client_buffer_size);
634 #define OBSD_MAX_SENSORS 256
635 struct obsd_sensors_struct {
637 float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
638 unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
639 float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
641 struct obsd_sensors_struct obsd_sensors;
642 #endif /* __OpenBSD__ */
644 enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME };
645 void get_powerbook_batt_info(char *, size_t, int);
648 struct process *next;
649 struct process *previous;
654 unsigned long user_time;
656 unsigned long kernel_time;
657 unsigned long previous_user_time;
658 unsigned long previous_kernel_time;
659 unsigned long total_cpu_time;
662 unsigned int time_stamp;
663 unsigned int counted;
664 unsigned int changed;
668 struct local_mail_s {
677 void update_top(void);
678 void free_all_processes(void);
679 struct process *get_first_process(void);
681 /* fs-stuff is possibly system dependant (in fs.c) */
683 void update_fs_stats(void);
684 struct fs_stat *prepare_fs_stat(const char *path);
685 void clear_fs_stats(void);
689 int mixer_init(const char *);
690 int mixer_get_avg(int);
691 int mixer_get_left(int);
692 int mixer_get_right(int);
696 extern char *current_mail_spool;
698 void update_mail_count(struct local_mail_s *);
701 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
705 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
706 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
708 typedef struct apm_power_info *apm_info_t;
710 int apm_getinfo(int fd, apm_info_t aip);
711 char *get_apm_adapter(void);
712 char *get_apm_battery_life(void);
713 char *get_apm_battery_time(void);
718 extern void init_mpd_stats(struct information *current_info);
719 void *update_mpd(void *) __attribute__((noreturn));
720 extern timed_thread *mpd_timed_thread;
721 void free_mpd_vars(struct information *current_info);
726 void update_xmms2(void);
731 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port, char **temp);
732 char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);
737 PRSS *get_rss_info(char *uri, int delay);
738 void init_rss_info(void);
739 void free_rss_info(void);
747 int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow);