2 * Conky, a system monitor, based on torsmo
4 * Any original torsmo code is licensed under the BSD license
6 * All code written since the fork of torsmo is licensed under the GPL
8 * Please see COPYING for details
10 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
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/>.
32 #if defined(HAS_MCHECK_H)
34 #endif /* HAS_MCHECK_H */
36 #include <sys/utsname.h>
43 #include <sys/param.h>
44 #if defined(__FreeBSD__)
45 #include <sys/mount.h>
46 #include <sys/ucred.h>
49 #endif /* __FreeBSD__ */
51 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
52 #include <machine/apm_bios.h>
53 #endif /* __FreeBSD__ */
55 #if defined(__OpenBSD__)
56 #include <sys/sysctl.h>
57 #include <sys/sensors.h>
58 #include <machine/apmvar.h>
59 #endif /* __OpenBSD__ */
62 #include "audacious.h"
66 #include <xmmsclient/xmmsclient.h>
74 #include "timed_thread.h"
81 #define TEXT_BUFFER_SIZE 1280
82 #define P_MAX_SIZE ((TEXT_BUFFER_SIZE * 4) - 2)
83 extern unsigned int text_buffer_size;
85 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
86 #define MAX_SPECIALS_DEFAULT 512
88 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
89 #define MAX_USER_TEXT_DEFAULT 16384
91 #include <sys/socket.h>
93 #define ERR(s, varargs...) \
94 fprintf(stderr, "Conky: " s "\n", ##varargs)
97 #define CRIT_ERR(s, varargs...) \
98 { fprintf(stderr, "Conky: " s "\n", ##varargs); exit(EXIT_FAILURE); }
105 char *left_fan_status;
106 char *right_fan_status;
110 char *buttons_status;
113 struct i8k_struct i8k;
118 long long last_read_recv, last_read_trans;
119 long long recv, trans;
120 double recv_speed, trans_speed;
121 struct sockaddr addr;
122 double net_rec[15], net_trans[15];
123 // wireless extensions
132 unsigned int diskio_value;
133 unsigned int diskio_read_value;
134 unsigned int diskio_write_value;
143 struct mail_s { // for imap and pop3
144 unsigned long unseen;
145 unsigned long messages;
157 timed_thread *p_timed_thread;
161 unsigned int user, nice, system, idle, iowait, irq, softirq;
184 int max_title_len; /* e.g. ${mpd_title 50} */
214 audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */
215 int max_title_len; /* e.g. ${audacious_title 50} */
216 timed_thread *p_timed_thread;
232 void update_entropy();
234 unsigned int entropy_avail;
235 unsigned int poolsize;
238 #ifdef TCP_PORT_MONITOR
239 #include "libtcp-portmon.h"
240 #define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256
265 #ifdef TCP_PORT_MONITOR
266 INFO_TCP_PORT_MONITOR = 19,
284 /* get_battery_stuff() item selector */
291 #include "libmpdclient.h"
294 /* Update interval */
295 double update_interval;
297 volatile int g_signal_pending;
302 struct utsname uname_s;
308 /* memory information in kilobytes */
309 unsigned long long mem, memmax, swap, swapmax;
310 unsigned long long bufmem, buffers, cached;
312 unsigned short procs;
313 unsigned short run_procs;
316 /* struct cpu_stat cpu_summed; what the hell is this? */
317 unsigned int cpu_count;
318 unsigned int cpu_avg_samples;
320 unsigned int net_avg_samples;
324 int new_mail_count, mail_count;
329 mpd_Connection *conn;
332 struct xmms2_s xmms2;
333 int xmms2_conn_state;
334 xmms_socket_t xmms2_fd;
336 xmmsc_connection_t *xmms2_conn;
339 struct audacious_s audacious;
344 struct process *cpu[10];
345 struct process *memu[10];
346 struct process *first_process;
347 unsigned long looped;
348 #ifdef TCP_PORT_MONITOR
349 tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
351 short kflags; /* kernel settings, see enum KFLAG */
352 struct entropy_s entropy;
353 double music_player_interval;
357 KFLAG_IS_LONGSTAT = 0x01, /* set to true if kernel uses "long" format for /proc/stats */
358 KFLAG_PROC_IS_THREADS=0x02 /* set to true if kernel shows # of threads for the proc value in sysinfo() call */
359 /* KFLAG_NEXT_ONE=0x04 bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
362 #define KFLAG_SETON(a) info.kflags |= a
363 #define KFLAG_SETOFF(a) info.kflags &= (~a)
364 #define KFLAG_FLIP(a) info.kflags ^= a
365 #define KFLAG_ISSET(a) info.kflags & a
375 char tmpstring1[TEXT_BUFFER_SIZE];
376 char tmpstring2[TEXT_BUFFER_SIZE];
381 #include <X11/Xlib.h>
382 #include <X11/Xlib.h>
383 #include <X11/Xatom.h>
386 #include <X11/Xft/Xft.h>
390 #include <X11/extensions/Xdbe.h>
393 #define ATOM(a) XInternAtom(display, #a, False)
403 HINT_UNDECORATED = 0,
410 #define SET_HINT(mask,hint) (mask |= (1<<hint))
411 #define TEST_HINT(mask,hint) (mask & (1<<hint))
413 struct conky_window {
414 Window root,window,desktop;
418 XdbeBackBuffer back_buffer;
427 char class_name[256];
445 extern Display *display;
446 extern int display_width;
447 extern int display_height;
450 extern int workarea[4];
452 extern struct conky_window window;
455 void init_window(int use_own_window, int width, int height, int set_trans, int back_colour,
456 char **argv, int argc);
458 void set_transparent_background(Window win);
459 long get_x11_color(const char *);
465 /* struct that has all info */
466 struct information info;
468 void signal_handler(int);
469 void reload_config(void);
473 double get_time(void);
474 FILE *open_file(const char *file, int *reported);
475 void variable_substitute(const char *s, char *dest, unsigned int n);
476 void format_seconds(char *buf, unsigned int n, long t);
477 void format_seconds_short(char *buf, unsigned int n, long t);
478 struct net_stat *get_net_stat(const char *dev);
479 void clear_net_stats(void);
483 int round_to_int(float f);
485 #define SET_NEED(a) need_mask |= 1 << (a)
486 extern unsigned long long need_mask;
488 extern double current_update_time, last_update_time;
490 extern int no_buffers;
492 /* system dependant (in linux.c) */
494 int check_mount(char *s);
495 void update_diskio(void);
496 void prepare_update(void);
497 void update_uptime(void);
498 void update_meminfo(void);
499 void update_net_stats(void);
500 void update_cpu_usage(void);
501 void update_total_processes(void);
502 void update_running_processes(void);
503 void update_i8k(void);
504 char get_freq( char *, size_t, char *, int, unsigned int );
505 void get_freq_dynamic( char *, size_t, char *, int );
506 char get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
507 void update_load_average();
509 int open_sysfs_sensor(const char *dir, const char *dev, const char *type, int n, int *div, char *devtype);
510 #define open_i2c_sensor(dev,type,n,div,devtype) \
511 open_sysfs_sensor("/sys/bus/i2c/devices/",dev,type,n,div,devtype)
513 #define open_platform_sensor(dev,type,n,div,devtype) \
514 open_sysfs_sensor("/sys/bus/platform/devices/",dev,type,n,div,devtype)
516 #define open_hwmon_sensor(dev,type,n,div,devtype) \
517 open_sysfs_sensor("/sys/class/hwmon/",dev,type,n,div,devtype); \
519 double get_sysfs_info(int *fd, int arg, char *devtype, char *type);
521 void get_adt746x_cpu( char *, size_t );
522 void get_adt746x_fan( char *, size_t );
523 unsigned int get_diskio(void);
525 int open_acpi_temperature(const char *name);
526 double get_acpi_temperature(int fd);
527 void get_acpi_ac_adapter( char *, size_t );
528 void get_acpi_fan( char *, size_t );
529 void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
530 int get_battery_perct(const char *bat);
531 int get_battery_perct_bar(const char *bat);
532 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
533 void get_ibm_acpi_temps(void);
534 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
535 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
536 void get_cpu_count();
538 struct ibm_acpi_struct {
539 unsigned int temps[8];
542 struct ibm_acpi_struct ibm_acpi;
544 #if defined(__OpenBSD__)
545 void update_obsd_sensors(void);
546 void get_obsd_vendor(char *buf, size_t client_buffer_size);
547 void get_obsd_product(char *buf, size_t client_buffer_size);
549 #define OBSD_MAX_SENSORS 256
550 struct obsd_sensors_struct {
552 float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
553 unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
554 float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
556 struct obsd_sensors_struct obsd_sensors;
557 #endif /* __OpenBSD__ */
560 enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME};
561 void get_powerbook_batt_info(char*, size_t, int);
564 struct process *next;
565 struct process *previous;
570 unsigned long user_time;
572 unsigned long kernel_time;
573 unsigned long previous_user_time;
574 unsigned long previous_kernel_time;
577 unsigned int time_stamp;
578 unsigned int counted;
579 unsigned int changed;
584 void free_all_processes();
585 struct process *get_first_process();
587 /* fs-stuff is possibly system dependant (in fs.c) */
589 void update_fs_stats(void);
590 struct fs_stat *prepare_fs_stat(const char *path);
591 void clear_fs_stats(void);
595 int mixer_init(const char *);
596 int mixer_get_avg(int);
597 int mixer_get_left(int);
598 int mixer_get_right(int);
602 extern char *current_mail_spool;
604 void update_mail_count();
607 #if defined(__FreeBSD__)
611 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
613 typedef struct apm_power_info *apm_info_t;
615 int apm_getinfo(int fd, apm_info_t aip);
616 char *get_apm_adapter(void);
617 char *get_apm_battery_life(void);
618 char *get_apm_battery_time(void);
623 extern void init_mpd_stats(struct information *current_info);
624 void *update_mpd(void);
625 extern timed_thread *mpd_timed_thread;
635 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port);
636 char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);
641 PRSS* get_rss_info(char *uri, int delay);
642 void init_rss_info();
643 void free_rss_info();