diff --git a/src/audacious.c b/src/audacious.c index 1014e2aa..21de8469 100644 --- a/src/audacious.c +++ b/src/audacious.c @@ -23,9 +23,6 @@ #include #endif -#include -#include - #include #ifndef AUDACIOUS_LEGACY #include @@ -55,7 +52,6 @@ xmms_remote_get_playlist_length(x) #endif -#include "config.h" #include "conky.h" #include "audacious.h" #include "timed_thread.h" diff --git a/src/audacious.h b/src/audacious.h index db03b406..65a0b67d 100644 --- a/src/audacious.h +++ b/src/audacious.h @@ -22,6 +22,12 @@ #ifndef AUDACIOUS_H #define AUDACIOUS_H +struct audacious_s { + audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */ + int max_title_len; /* e.g. ${audacious_title 50} */ + timed_thread *p_timed_thread; +}; + enum _audacious_items { AUDACIOUS_STATUS = 0, AUDACIOUS_TITLE, diff --git a/src/bmpx.c b/src/bmpx.c index 31d52377..a75e78c2 100644 --- a/src/bmpx.c +++ b/src/bmpx.c @@ -27,9 +27,6 @@ #include #include -#include -#include - #include "conky.h" #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \ diff --git a/src/bmpx.h b/src/bmpx.h new file mode 100644 index 00000000..5808469e --- /dev/null +++ b/src/bmpx.h @@ -0,0 +1,14 @@ +#ifndef BMPX_H_ +#define BMPX_H_ + +void update_bmpx(void); +struct bmpx_s { + char *title; + char *artist; + char *album; + char *uri; + int bitrate; + int track; +}; + +#endif /*BMPX_H_*/ diff --git a/src/common.c b/src/common.c index 59dfd777..78754402 100644 --- a/src/common.c +++ b/src/common.c @@ -26,9 +26,6 @@ * $Id$ */ #include "conky.h" -#include -#include -#include #include #include #include @@ -301,15 +298,15 @@ void update_stuff(void) #ifdef MPD if (NEED(INFO_MPD)) { - if (!mpd_timed_thread) { - init_mpd_stats(&info); - mpd_timed_thread = timed_thread_create(&update_mpd, - (void *) NULL, info.music_player_interval * 1000000); - if (!mpd_timed_thread) { + if (!info.mpd.timed_thread) { + init_mpd_stats(&info.mpd); + info.mpd.timed_thread = timed_thread_create(&update_mpd, + (void *) &info.mpd, info.music_player_interval * 1000000); + if (!info.mpd.timed_thread) { ERR("Failed to create MPD timed thread"); } - timed_thread_register(mpd_timed_thread, &mpd_timed_thread); - if (timed_thread_run(mpd_timed_thread)) { + timed_thread_register(info.mpd.timed_thread, &info.mpd.timed_thread); + if (timed_thread_run(info.mpd.timed_thread)) { ERR("Failed to run MPD timed thread"); } } diff --git a/src/common.h b/src/common.h new file mode 100644 index 00000000..710ee7e7 --- /dev/null +++ b/src/common.h @@ -0,0 +1,47 @@ +#ifndef COMMON_H_ +#define COMMON_H_ + +int check_mount(char *s); +void update_diskio(void); +void prepare_update(void); +void update_uptime(void); +void update_meminfo(void); +void update_net_stats(void); +void update_cpu_usage(void); +void update_total_processes(void); +void update_running_processes(void); +void update_i8k(void); +char get_freq(char *, size_t, const char *, int, unsigned int); +void get_freq_dynamic(char *, size_t, const char *, int); +char get_voltage(char *, size_t, const char *, int, unsigned int); /* ptarjan */ +void update_load_average(void); +void update_top(void); +void free_all_processes(void); +struct process *get_first_process(void); +void get_cpu_count(void); + +int open_sysfs_sensor(const char *dir, const char *dev, const char *type, int n, + int *divisor, char *devtype); + +#define open_i2c_sensor(dev, type, n, divisor, devtype) \ + open_sysfs_sensor("/sys/bus/i2c/devices/", dev, type, n, divisor, devtype) +#define open_platform_sensor(dev, type, n, divisor, devtype) \ + open_sysfs_sensor("/sys/bus/platform/devices/", dev, type, n, divisor, devtype) +#define open_hwmon_sensor(dev, type, n, divisor, devtype) \ + open_sysfs_sensor("/sys/class/hwmon/", dev, type, n, divisor, devtype) + +double get_sysfs_info(int *fd, int arg, char *devtype, char *type); + +void get_adt746x_cpu(char *, size_t); +void get_adt746x_fan(char *, size_t); +unsigned int get_diskio(void); + +int open_acpi_temperature(const char *name); +double get_acpi_temperature(int fd); +void get_acpi_ac_adapter(char *, size_t); +void get_acpi_fan(char *, size_t); +void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item); +int get_battery_perct(const char *bat); +int get_battery_perct_bar(const char *bat); + +#endif /*COMMON_H_*/ diff --git a/src/conky.c b/src/conky.c index eeb3486c..cf920970 100644 --- a/src/conky.c +++ b/src/conky.c @@ -26,8 +26,6 @@ * $Id$ */ #include "conky.h" -#include -#include #include #include #include @@ -37,7 +35,6 @@ #include #include #include -#include #include #if HAVE_DIRENT_H #include @@ -2304,7 +2301,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs) case OBJ_mpd_file: case OBJ_mpd_percent: case OBJ_mpd_smart: - free_mpd_vars(&info); + free_mpd_vars(&info.mpd); break; #endif } diff --git a/src/conky.h b/src/conky.h index a07400df..e75e5988 100644 --- a/src/conky.h +++ b/src/conky.h @@ -35,7 +35,6 @@ #endif /* HAS_MCHECK_H */ #include "config.h" -#include "top.h" #include #include #include @@ -50,19 +49,11 @@ #endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include -#include -#include -#include -#if (defined(i386) || defined(__i386__)) -#include -#endif /* i386 || __i386__ */ +#include "freebsd.h" #endif /* __FreeBSD__ */ #if defined(__OpenBSD__) -#include -#include -#include +#include "openbsd.h" #endif /* __OpenBSD__ */ #ifndef HAVE_STRNDUP @@ -79,7 +70,7 @@ char *strndup(const char *s, size_t n); #endif #ifdef RSS -#include "prss.h" +#include "rss.h" #endif #ifdef SMAPI @@ -92,16 +83,7 @@ char *strndup(const char *s, size_t n); #include "mboxscan.h" #include "timed_thread.h" - -enum { - TOP_CPU, - TOP_NAME, - TOP_PID, - TOP_MEM, - TOP_TIME, - TOP_MEM_RES, - TOP_MEM_VSIZE, -}; +#include "top.h" #define DEFAULT_TEXT_BUFFER_SIZE 256 extern unsigned int text_buffer_size; @@ -124,21 +106,6 @@ extern unsigned int text_buffer_size; #define CRIT_ERR(...) \ { ERR(__VA_ARGS__); exit(EXIT_FAILURE); } -struct i8k_struct { - char *version; - char *bios; - char *serial; - char *cpu_temp; - char *left_fan_status; - char *right_fan_status; - char *left_fan_rpm; - char *right_fan_rpm; - char *ac_status; - char *buttons_status; -}; - -struct i8k_struct i8k; - struct net_stat { const char *dev; int up; @@ -200,70 +167,19 @@ struct mail_s { // for imap and pop3 }; */ #ifdef MPD -struct mpd_s { - char *title; - char *artist; - char *album; - char *status; - char *random; - char *repeat; - char *track; - char *name; - char *file; - int volume; - unsigned int port; - char host[128]; - char password[128]; - float progress; - int bitrate; - int length; - int elapsed; - int max_title_len; /* e.g. ${mpd_title 50} */ -}; - +#include "mpd.h" #endif #ifdef XMMS2 -struct xmms2_s { - char *artist; - char *album; - char *title; - char *genre; - char *comment; - char *url; - char *date; - char* playlist; - int tracknr; - int bitrate; - unsigned int id; - int duration; - int elapsed; - int timesplayed; - float size; - - float progress; - char *status; -}; +#include "xmms2.h" #endif #ifdef AUDACIOUS -struct audacious_s { - audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */ - int max_title_len; /* e.g. ${audacious_title 50} */ - timed_thread *p_timed_thread; -}; +#include "audacious.h" #endif #ifdef BMPX -void update_bmpx(void); -struct bmpx_s { - char *title; - char *artist; - char *album; - char *uri; - int bitrate; - int track; -}; +#include "bmpx.h" #endif void update_entropy(void); @@ -287,7 +203,6 @@ struct gateway_info { #ifdef TCP_PORT_MONITOR #include "libtcp-portmon.h" -#define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256 #endif enum { @@ -353,10 +268,6 @@ enum { IFUP_ADDR } ifup_strictness; -#ifdef MPD -#include "libmpdclient.h" -#endif - /* Update interval */ double update_interval; @@ -391,7 +302,6 @@ struct information { int mail_running; #ifdef MPD struct mpd_s mpd; - mpd_Connection *conn; #endif #ifdef XMMS2 struct xmms2_s xmms2; @@ -450,97 +360,12 @@ char *tmpstring1; char *tmpstring2; #ifdef X11 -/* in x11.c */ - -#include -#include -#include - -#ifdef XFT -#include -#endif - -#ifdef HAVE_XDBE -#include -#endif - -#define ATOM(a) XInternAtom(display, #a, False) - -#ifdef OWN_WINDOW -enum _window_type { - TYPE_NORMAL = 0, - TYPE_DOCK, - TYPE_DESKTOP, - TYPE_OVERRIDE -}; - -enum _window_hints { - HINT_UNDECORATED = 0, - HINT_BELOW, - HINT_ABOVE, - HINT_STICKY, - HINT_SKIP_TASKBAR, - HINT_SKIP_PAGER -}; - -#define SET_HINT(mask, hint) (mask |= (1 << hint)) -#define TEST_HINT(mask, hint) (mask & (1 << hint)) -#endif - -struct conky_window { - Window root, window, desktop; - Drawable drawable; - GC gc; -#ifdef HAVE_XDBE - XdbeBackBuffer back_buffer; -#endif -#ifdef XFT - XftDraw *xftdraw; -#endif - - int width; - int height; -#ifdef OWN_WINDOW - char class_name[256]; - char title[256]; - int x; - int y; - unsigned int type; - unsigned long hints; -#endif -}; - -#ifdef HAVE_XDBE -extern int use_xdbe; -#endif - -#ifdef XFT -extern int use_xft; -#endif - -extern Display *display; -extern int display_width; -extern int display_height; -extern int screen; - -extern int workarea[4]; - -extern struct conky_window window; - -void init_X11(void); -void init_window(int use_own_window, int width, int height, int set_trans, - int back_colour, char **argv, int argc); -void create_gc(void); -void set_transparent_background(Window win); -long get_x11_color(const char *); - +#include "x11.h" #endif /* X11 */ int cpu_separate; int short_units; -/* in common.c */ - /* struct that has all info */ struct information info; @@ -570,157 +395,26 @@ extern double current_update_time, last_update_time; extern int no_buffers; -/* system dependant (in linux.c) */ - -int check_mount(char *s); -void update_diskio(void); -void prepare_update(void); -void update_uptime(void); -void update_meminfo(void); -void update_net_stats(void); -void update_cpu_usage(void); -void update_total_processes(void); -void update_running_processes(void); -void update_i8k(void); -char get_freq(char *, size_t, const char *, int, unsigned int); -void get_freq_dynamic(char *, size_t, const char *, int); -char get_voltage(char *, size_t, const char *, int, unsigned int); /* ptarjan */ -void update_load_average(void); -int interface_up(const char *dev); -char *get_ioscheduler(char *); -int get_laptop_mode(void); -void update_gateway_info(void); - -int open_sysfs_sensor(const char *dir, const char *dev, const char *type, int n, - int *divisor, char *devtype); - -#define open_i2c_sensor(dev, type, n, divisor, devtype) \ - open_sysfs_sensor("/sys/bus/i2c/devices/", dev, type, n, divisor, devtype) -#define open_platform_sensor(dev, type, n, divisor, devtype) \ - open_sysfs_sensor("/sys/bus/platform/devices/", dev, type, n, divisor, devtype) -#define open_hwmon_sensor(dev, type, n, divisor, devtype) \ - open_sysfs_sensor("/sys/class/hwmon/", dev, type, n, divisor, devtype) - -double get_sysfs_info(int *fd, int arg, char *devtype, char *type); - -void get_adt746x_cpu(char *, size_t); -void get_adt746x_fan(char *, size_t); -unsigned int get_diskio(void); - -int open_acpi_temperature(const char *name); -double get_acpi_temperature(int fd); -void get_acpi_ac_adapter(char *, size_t); -void get_acpi_fan(char *, size_t); -void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item); -int get_battery_perct(const char *bat); -int get_battery_perct_bar(const char *bat); -void get_ibm_acpi_fan(char *buf, size_t client_buffer_size); -void get_ibm_acpi_temps(void); -void get_ibm_acpi_volume(char *buf, size_t client_buffer_size); -void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size); -const char *get_disk_protect_queue(const char *); -void get_cpu_count(void); - -struct ibm_acpi_struct { - int temps[8]; -}; - -struct ibm_acpi_struct ibm_acpi; - -#if defined(__OpenBSD__) -void update_obsd_sensors(void); -void get_obsd_vendor(char *buf, size_t client_buffer_size); -void get_obsd_product(char *buf, size_t client_buffer_size); - -#define OBSD_MAX_SENSORS 256 -struct obsd_sensors_struct { - int device; - float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; - unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; - float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; -}; -struct obsd_sensors_struct obsd_sensors; -#endif /* __OpenBSD__ */ - -enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME }; -void get_powerbook_batt_info(char *, size_t, int); - -struct local_mail_s { - char *box; - int mail_count; - int new_mail_count; - float interval; - time_t last_mtime; - double last_update; -}; - -void update_top(void); -void free_all_processes(void); -struct process *get_first_process(void); - -/* fs-stuff is possibly system dependant (in fs.c) */ - -void update_fs_stats(void); -struct fs_stat *prepare_fs_stat(const char *path); -void clear_fs_stats(void); - -/* in mixer.c */ - -int mixer_init(const char *); -int mixer_get_avg(int); -int mixer_get_left(int); -int mixer_get_right(int); - -/* in mail.c */ - -extern char *current_mail_spool; - -void update_mail_count(struct local_mail_s *); - -/* in freebsd.c */ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -kvm_t *kd; +#if defined(__linux__) +#include "linux.h" #endif +#include "fs.h" +#include "mixer.h" +#include "mail.h" + #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) -#ifdef __OpenBSD__ -typedef struct apm_power_info *apm_info_t; -#endif int apm_getinfo(int fd, apm_info_t aip); char *get_apm_adapter(void); char *get_apm_battery_life(void); char *get_apm_battery_time(void); #endif -/* in mpd.c */ -#ifdef MPD -extern void init_mpd_stats(struct information *current_info); -void *update_mpd(void *) __attribute__((noreturn)); -extern timed_thread *mpd_timed_thread; -void free_mpd_vars(struct information *current_info); -#endif /* MPD */ - -/* in xmms2.c */ -#ifdef XMMS2 -void update_xmms2(void); -#endif - -/* in hddtemp.c */ #ifdef HDDTEMP -int scan_hddtemp(const char *arg, char **dev, char **addr, int *port, char **temp); -char *get_hddtemp_info(char *dev, char *addr, int port, char *unit); +#include "hddtemp.h" #endif /* HDDTEMP */ -/* in rss.c */ -#ifdef RSS -PRSS *get_rss_info(char *uri, int delay); -void init_rss_info(void); -void free_rss_info(void); -#endif /* RSS */ - -/* in linux.c */ - /* in nvidia.c */ #ifdef NVIDIA diff --git a/src/diskio.c b/src/diskio.c index 8796f0a8..e0c65d80 100644 --- a/src/diskio.c +++ b/src/diskio.c @@ -29,7 +29,6 @@ #include "conky.h" #include -#include /* The following ifdefs were adapted from gkrellm */ #include diff --git a/src/freebsd.c b/src/freebsd.c index b81ba75d..3184e82a 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -45,9 +45,6 @@ #include #include #include -#include -#include -#include #include #include diff --git a/src/freebsd.h b/src/freebsd.h new file mode 100644 index 00000000..8835c0c8 --- /dev/null +++ b/src/freebsd.h @@ -0,0 +1,15 @@ +#ifndef FREEBSD_H_ +#define FREEBSD_H_ + +#include "common.h" +#include +#include +#include +#include +#if (defined(i386) || defined(__i386__)) +#include +#endif /* i386 || __i386__ */ + +kvm_t *kd; + +#endif /*FREEBSD_H_*/ diff --git a/src/fs.c b/src/fs.c index ce59be09..12b011ac 100644 --- a/src/fs.c +++ b/src/fs.c @@ -27,8 +27,6 @@ #include "conky.h" #include -#include -#include #include #include #include diff --git a/src/fs.h b/src/fs.h new file mode 100644 index 00000000..f786b741 --- /dev/null +++ b/src/fs.h @@ -0,0 +1,8 @@ +#ifndef FS_H_ +#define FS_H_ + +void update_fs_stats(void); +struct fs_stat *prepare_fs_stat(const char *path); +void clear_fs_stats(void); + +#endif /*FS_H_*/ diff --git a/src/hddtemp.c b/src/hddtemp.c index efe0c4ef..f586349a 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -27,9 +27,6 @@ #include "conky.h" #include -#include -#include -#include #include #include #include diff --git a/src/hddtemp.h b/src/hddtemp.h new file mode 100644 index 00000000..2bd14677 --- /dev/null +++ b/src/hddtemp.h @@ -0,0 +1,7 @@ +#ifndef HDDTEMP_H_ +#define HDDTEMP_H_ + +int scan_hddtemp(const char *arg, char **dev, char **addr, int *port, char **temp); +char *get_hddtemp_info(char *dev, char *addr, int port, char *unit); + +#endif /*HDDTEMP_H_*/ diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 9539b9f1..af4c9888 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -39,11 +39,8 @@ #include #include #include -#include #include -#include #include -#include #include #include diff --git a/src/libtcp-portmon.h b/src/libtcp-portmon.h index 41ac4234..aa5ef1dc 100644 --- a/src/libtcp-portmon.h +++ b/src/libtcp-portmon.h @@ -41,6 +41,7 @@ #define TCP_CONNECTION_STARTING_AGE 1 #define TCP_CONNECTION_HASH_KEY_SIZE 28 #define TCP_PORT_MONITOR_HASH_KEY_SIZE 12 +#define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256 /* ------------------------------------------------------------------- * IMPLEMENTATION INTERFACE diff --git a/src/linux.c b/src/linux.c index 54496561..351845d3 100644 --- a/src/linux.c +++ b/src/linux.c @@ -27,9 +27,6 @@ * $Id$ */ #include "conky.h" -#include -#include -#include #include #include #include diff --git a/src/linux.h b/src/linux.h new file mode 100644 index 00000000..8b4346ad --- /dev/null +++ b/src/linux.h @@ -0,0 +1,41 @@ +#ifndef LINUX_H_ +#define LINUX_H_ + +#include "common.h" + +void get_ibm_acpi_fan(char *buf, size_t client_buffer_size); +void get_ibm_acpi_temps(void); +void get_ibm_acpi_volume(char *buf, size_t client_buffer_size); +void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size); +const char *get_disk_protect_queue(const char *); + +struct i8k_struct { + char *version; + char *bios; + char *serial; + char *cpu_temp; + char *left_fan_status; + char *right_fan_status; + char *left_fan_rpm; + char *right_fan_rpm; + char *ac_status; + char *buttons_status; +}; + +struct i8k_struct i8k; + +struct ibm_acpi_struct { + int temps[8]; +}; + +struct ibm_acpi_struct ibm_acpi; + +int interface_up(const char *dev); +char *get_ioscheduler(char *); +int get_laptop_mode(void); +void update_gateway_info(void); + +enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME }; +void get_powerbook_batt_info(char *, size_t, int); + +#endif /*LINUX_H_*/ diff --git a/src/mail.c b/src/mail.c index b4cb6bf9..8ce47a27 100644 --- a/src/mail.c +++ b/src/mail.c @@ -30,8 +30,6 @@ #include #include -#include -#include #include "conky.h" diff --git a/src/mail.h b/src/mail.h new file mode 100644 index 00000000..a24f0a78 --- /dev/null +++ b/src/mail.h @@ -0,0 +1,17 @@ +#ifndef MAIL_H_ +#define MAIL_H_ + +extern char *current_mail_spool; + +struct local_mail_s { + char *box; + int mail_count; + int new_mail_count; + float interval; + time_t last_mtime; + double last_update; +}; + +void update_mail_count(struct local_mail_s *); + +#endif /*MAIL_H_*/ diff --git a/src/mboxscan.c b/src/mboxscan.c index e4a99e5a..53b0c3da 100644 --- a/src/mboxscan.c +++ b/src/mboxscan.c @@ -29,9 +29,6 @@ #include #include #include -#include -#include -#include #include "mboxscan.h" #define FROM_WIDTH 10 diff --git a/src/mixer.c b/src/mixer.c index 6585ef9e..a483ee50 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -29,8 +29,6 @@ #include #include #include -#include -#include #ifdef HAVE_LINUX_SOUNDCARD_H diff --git a/src/mixer.h b/src/mixer.h new file mode 100644 index 00000000..06c62bb0 --- /dev/null +++ b/src/mixer.h @@ -0,0 +1,9 @@ +#ifndef MIXER_H_ +#define MIXER_H_ + +int mixer_init(const char *); +int mixer_get_avg(int); +int mixer_get_left(int); +int mixer_get_right(int); + +#endif /*MIXER_H_*/ diff --git a/src/mpd.c b/src/mpd.c index 8a7a7857..28e75489 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -25,229 +25,221 @@ * $Id$ */ #include "conky.h" -#include -#include -#include -#include "libmpdclient.h" -timed_thread *mpd_timed_thread = NULL; - -void clear_mpd_stats(struct information *current_info); - -void init_mpd_stats(struct information *current_info) +void init_mpd_stats(struct mpd_s *mpd) { - if (current_info->mpd.artist == NULL) { - current_info->mpd.artist = malloc(text_buffer_size); + if (mpd->artist == NULL) { + mpd->artist = malloc(text_buffer_size); } - if (current_info->mpd.album == NULL) { - current_info->mpd.album = malloc(text_buffer_size); + if (mpd->album == NULL) { + mpd->album = malloc(text_buffer_size); } - if (current_info->mpd.title == NULL) { - current_info->mpd.title = malloc(text_buffer_size); + if (mpd->title == NULL) { + mpd->title = malloc(text_buffer_size); } - if (current_info->mpd.random == NULL) { - current_info->mpd.random = malloc(text_buffer_size); + if (mpd->random == NULL) { + mpd->random = malloc(text_buffer_size); } - if (current_info->mpd.repeat == NULL) { - current_info->mpd.repeat = malloc(text_buffer_size); + if (mpd->repeat == NULL) { + mpd->repeat = malloc(text_buffer_size); } - if (current_info->mpd.track == NULL) { - current_info->mpd.track = malloc(text_buffer_size); + if (mpd->track == NULL) { + mpd->track = malloc(text_buffer_size); } - if (current_info->mpd.status == NULL) { - current_info->mpd.status = malloc(text_buffer_size); + if (mpd->status == NULL) { + mpd->status = malloc(text_buffer_size); } - if (current_info->mpd.name == NULL) { - current_info->mpd.name = malloc(text_buffer_size); + if (mpd->name == NULL) { + mpd->name = malloc(text_buffer_size); } - if (current_info->mpd.file == NULL) { - current_info->mpd.file = malloc(text_buffer_size); + if (mpd->file == NULL) { + mpd->file = malloc(text_buffer_size); } - clear_mpd_stats(current_info); + clear_mpd_stats(mpd); } -void free_mpd_vars(struct information *current_info) +void free_mpd_vars(struct mpd_s *mpd) { - if (current_info->mpd.title) { - free(current_info->mpd.title); - current_info->mpd.title = NULL; + if (mpd->title) { + free(mpd->title); + mpd->title = NULL; } - if (current_info->mpd.artist) { - free(current_info->mpd.artist); - current_info->mpd.artist = NULL; + if (mpd->artist) { + free(mpd->artist); + mpd->artist = NULL; } - if (current_info->mpd.album) { - free(current_info->mpd.album); - current_info->mpd.album = NULL; + if (mpd->album) { + free(mpd->album); + mpd->album = NULL; } - if (current_info->mpd.random) { - free(current_info->mpd.random); - current_info->mpd.random = NULL; + if (mpd->random) { + free(mpd->random); + mpd->random = NULL; } - if (current_info->mpd.repeat) { - free(current_info->mpd.repeat); - current_info->mpd.repeat = NULL; + if (mpd->repeat) { + free(mpd->repeat); + mpd->repeat = NULL; } - if (current_info->mpd.track) { - free(current_info->mpd.track); - current_info->mpd.track = NULL; + if (mpd->track) { + free(mpd->track); + mpd->track = NULL; } - if (current_info->mpd.name) { - free(current_info->mpd.name); - current_info->mpd.name = NULL; + if (mpd->name) { + free(mpd->name); + mpd->name = NULL; } - if (current_info->mpd.file) { - free(current_info->mpd.file); - current_info->mpd.file = NULL; + if (mpd->file) { + free(mpd->file); + mpd->file = NULL; } - if (current_info->mpd.status) { - free(current_info->mpd.status); - current_info->mpd.status = NULL; + if (mpd->status) { + free(mpd->status); + mpd->status = NULL; } - if (current_info->conn) { - mpd_closeConnection(current_info->conn); - current_info->conn = 0; + if (mpd->conn) { + mpd_closeConnection(mpd->conn); + mpd->conn = 0; } } -void clear_mpd_stats(struct information *current_info) +void clear_mpd_stats(struct mpd_s *mpd) { - *current_info->mpd.name = 0; - *current_info->mpd.file = 0; - *current_info->mpd.artist = 0; - *current_info->mpd.album = 0; - *current_info->mpd.title = 0; - *current_info->mpd.random = 0; - *current_info->mpd.repeat = 0; - *current_info->mpd.track = 0; - *current_info->mpd.status = 0; - current_info->mpd.bitrate = 0; - current_info->mpd.progress = 0; - current_info->mpd.elapsed = 0; - current_info->mpd.length = 0; + *mpd->name = 0; + *mpd->file = 0; + *mpd->artist = 0; + *mpd->album = 0; + *mpd->title = 0; + *mpd->random = 0; + *mpd->repeat = 0; + *mpd->track = 0; + *mpd->status = 0; + mpd->bitrate = 0; + mpd->progress = 0; + mpd->elapsed = 0; + mpd->length = 0; } void *update_mpd(void *arg) { - struct information *current_info = &info; - - if (arg) { - /* make gcc happy (unused argument) */ + if (arg == NULL) { + CRIT_ERR("update_mpd called with a null argument!"); } + struct mpd_s *mpd = (struct mpd_s *) arg; + while (1) { mpd_Status *status; mpd_InfoEntity *entity; - if (!current_info->conn) { - current_info->conn = mpd_newConnection(current_info->mpd.host, - current_info->mpd.port, 10); + if (!mpd->conn) { + mpd->conn = mpd_newConnection(mpd->host, + mpd->port, 10); } - if (strlen(current_info->mpd.password) > 1) { - mpd_sendPasswordCommand(current_info->conn, - current_info->mpd.password); - mpd_finishCommand(current_info->conn); + if (strlen(mpd->password) > 1) { + mpd_sendPasswordCommand(mpd->conn, + mpd->password); + mpd_finishCommand(mpd->conn); } - timed_thread_lock(mpd_timed_thread); + timed_thread_lock(mpd->timed_thread); - if (current_info->conn->error || current_info->conn == NULL) { - ERR("MPD error: %s\n", current_info->conn->errorStr); - mpd_closeConnection(current_info->conn); - current_info->conn = 0; - clear_mpd_stats(current_info); + if (mpd->conn->error || mpd->conn == NULL) { + ERR("MPD error: %s\n", mpd->conn->errorStr); + mpd_closeConnection(mpd->conn); + mpd->conn = 0; + clear_mpd_stats(mpd); - strncpy(current_info->mpd.status, "MPD not responding", + strncpy(mpd->status, "MPD not responding", text_buffer_size - 1); - timed_thread_unlock(mpd_timed_thread); - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + timed_thread_unlock(mpd->timed_thread); + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } - mpd_sendStatusCommand(current_info->conn); - if ((status = mpd_getStatus(current_info->conn)) == NULL) { - ERR("MPD error: %s\n", current_info->conn->errorStr); - mpd_closeConnection(current_info->conn); - current_info->conn = 0; - clear_mpd_stats(current_info); + mpd_sendStatusCommand(mpd->conn); + if ((status = mpd_getStatus(mpd->conn)) == NULL) { + ERR("MPD error: %s\n", mpd->conn->errorStr); + mpd_closeConnection(mpd->conn); + mpd->conn = 0; + clear_mpd_stats(mpd); - strncpy(current_info->mpd.status, "MPD not responding", + strncpy(mpd->status, "MPD not responding", text_buffer_size - 1); - timed_thread_unlock(mpd_timed_thread); - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + timed_thread_unlock(mpd->timed_thread); + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } - mpd_finishCommand(current_info->conn); - if (current_info->conn->error) { - // fprintf(stderr, "%s\n", current_info->conn->errorStr); - mpd_closeConnection(current_info->conn); - current_info->conn = 0; - timed_thread_unlock(mpd_timed_thread); - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + mpd_finishCommand(mpd->conn); + if (mpd->conn->error) { + // fprintf(stderr, "%s\n", mpd->conn->errorStr); + mpd_closeConnection(mpd->conn); + mpd->conn = 0; + timed_thread_unlock(mpd->timed_thread); + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } - current_info->mpd.volume = status->volume; + mpd->volume = status->volume; /* if (status->error) { printf("error: %s\n", status->error); } */ if (status->state == MPD_STATUS_STATE_PLAY) { - strncpy(current_info->mpd.status, "Playing", text_buffer_size - 1); + strncpy(mpd->status, "Playing", text_buffer_size - 1); } if (status->state == MPD_STATUS_STATE_STOP) { - clear_mpd_stats(current_info); - strncpy(current_info->mpd.status, "Stopped", text_buffer_size - 1); + clear_mpd_stats(mpd); + strncpy(mpd->status, "Stopped", text_buffer_size - 1); } if (status->state == MPD_STATUS_STATE_PAUSE) { - strncpy(current_info->mpd.status, "Paused", text_buffer_size - 1); + strncpy(mpd->status, "Paused", text_buffer_size - 1); } if (status->state == MPD_STATUS_STATE_UNKNOWN) { - clear_mpd_stats(current_info); - *current_info->mpd.status = 0; + clear_mpd_stats(mpd); + *mpd->status = 0; } if (status->state == MPD_STATUS_STATE_PLAY || status->state == MPD_STATUS_STATE_PAUSE) { - current_info->mpd.bitrate = status->bitRate; - current_info->mpd.progress = (float) status->elapsedTime / + mpd->bitrate = status->bitRate; + mpd->progress = (float) status->elapsedTime / status->totalTime; - current_info->mpd.elapsed = status->elapsedTime; - current_info->mpd.length = status->totalTime; + mpd->elapsed = status->elapsedTime; + mpd->length = status->totalTime; if (status->random == 0) { - strcpy(current_info->mpd.random, "Off"); + strcpy(mpd->random, "Off"); } else if (status->random == 1) { - strcpy(current_info->mpd.random, "On"); + strcpy(mpd->random, "On"); } else { - *current_info->mpd.random = 0; + *mpd->random = 0; } if (status->repeat == 0) { - strcpy(current_info->mpd.repeat, "Off"); + strcpy(mpd->repeat, "Off"); } else if (status->repeat == 1) { - strcpy(current_info->mpd.repeat, "On"); + strcpy(mpd->repeat, "On"); } else { - *current_info->mpd.repeat = 0; + *mpd->repeat = 0; } } - if (current_info->conn->error) { - // fprintf(stderr, "%s\n", current_info->conn->errorStr); - mpd_closeConnection(current_info->conn); - current_info->conn = 0; - timed_thread_unlock(mpd_timed_thread); - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + if (mpd->conn->error) { + // fprintf(stderr, "%s\n", mpd->conn->errorStr); + mpd_closeConnection(mpd->conn); + mpd->conn = 0; + timed_thread_unlock(mpd->timed_thread); + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } - mpd_sendCurrentSongCommand(current_info->conn); - while ((entity = mpd_getNextInfoEntity(current_info->conn))) { + mpd_sendCurrentSongCommand(mpd->conn); + while ((entity = mpd_getNextInfoEntity(mpd->conn))) { mpd_Song *song = entity->info.song; if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) { @@ -256,40 +248,40 @@ void *update_mpd(void *arg) } if (song->artist) { - strncpy(current_info->mpd.artist, song->artist, + strncpy(mpd->artist, song->artist, text_buffer_size - 1); } else { - *current_info->mpd.artist = 0; + *mpd->artist = 0; } if (song->album) { - strncpy(current_info->mpd.album, song->album, + strncpy(mpd->album, song->album, text_buffer_size - 1); } else { - *current_info->mpd.album = 0; + *mpd->album = 0; } if (song->title) { - strncpy(current_info->mpd.title, song->title, + strncpy(mpd->title, song->title, text_buffer_size - 1); } else { - *current_info->mpd.title = 0; + *mpd->title = 0; } if (song->track) { - strncpy(current_info->mpd.track, song->track, + strncpy(mpd->track, song->track, text_buffer_size - 1); } else { - *current_info->mpd.track = 0; + *mpd->track = 0; } if (song->name) { - strncpy(current_info->mpd.name, song->name, + strncpy(mpd->name, song->name, text_buffer_size - 1); } else { - *current_info->mpd.name = 0; + *mpd->name = 0; } if (song->file) { - strncpy(current_info->mpd.file, song->file, + strncpy(mpd->file, song->file, text_buffer_size - 1); } else { - *current_info->mpd.file = 0; + *mpd->file = 0; } if (entity != NULL) { mpd_freeInfoEntity(entity); @@ -300,36 +292,36 @@ void *update_mpd(void *arg) mpd_freeInfoEntity(entity); entity = NULL; } - mpd_finishCommand(current_info->conn); - if (current_info->conn->error) { - // fprintf(stderr, "%s\n", current_info->conn->errorStr); - mpd_closeConnection(current_info->conn); - current_info->conn = 0; - timed_thread_unlock(mpd_timed_thread); - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + mpd_finishCommand(mpd->conn); + if (mpd->conn->error) { + // fprintf(stderr, "%s\n", mpd->conn->errorStr); + mpd_closeConnection(mpd->conn); + mpd->conn = 0; + timed_thread_unlock(mpd->timed_thread); + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } - timed_thread_unlock(mpd_timed_thread); - if (current_info->conn->error) { - // fprintf(stderr, "%s\n", current_info->conn->errorStr); - mpd_closeConnection(current_info->conn); - current_info->conn = 0; - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + timed_thread_unlock(mpd->timed_thread); + if (mpd->conn->error) { + // fprintf(stderr, "%s\n", mpd->conn->errorStr); + mpd_closeConnection(mpd->conn); + mpd->conn = 0; + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } mpd_freeStatus(status); - /* if (current_info->conn) { - mpd_closeConnection(current_info->conn); - current_info->conn = 0; + /* if (mpd->conn) { + mpd_closeConnection(mpd->conn); + mpd->conn = 0; } */ - if (timed_thread_test(mpd_timed_thread)) { - timed_thread_exit(mpd_timed_thread); + if (timed_thread_test(mpd->timed_thread)) { + timed_thread_exit(mpd->timed_thread); } continue; } diff --git a/src/mpd.h b/src/mpd.h new file mode 100644 index 00000000..e728775f --- /dev/null +++ b/src/mpd.h @@ -0,0 +1,41 @@ +#ifndef MPD_H_ +#define MPD_H_ + +#include +#include +#include + +#include "libmpdclient.h" +#include "timed_thread.h" + +struct mpd_s { + char *title; + char *artist; + char *album; + char *status; + char *random; + char *repeat; + char *track; + char *name; + char *file; + int volume; + unsigned int port; + char host[128]; + char password[128]; + float progress; + int bitrate; + int length; + int elapsed; + int max_title_len; /* e.g. ${mpd_title 50} */ + mpd_Connection *conn; + timed_thread *timed_thread; +}; + +#include "conky.h" + +extern void init_mpd_stats(struct mpd_s *mpd); +void clear_mpd_stats(struct mpd_s *mpd); +void *update_mpd(void *) __attribute__((noreturn)); +void free_mpd_vars(struct mpd_s *mpd); + +#endif /*MPD_H_*/ diff --git a/src/netbsd.c b/src/netbsd.c index 82bcacfa..89864a14 100644 --- a/src/netbsd.c +++ b/src/netbsd.c @@ -25,36 +25,7 @@ * * $Id$ */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include "conky.h" +#include "netbsd.h" static kvm_t *kd = NULL; int kd_init = 0, nkd_init = 0; diff --git a/src/netbsd.h b/src/netbsd.h new file mode 100644 index 00000000..2cc632bf --- /dev/null +++ b/src/netbsd.h @@ -0,0 +1,31 @@ +#ifndef NETBSD_H_ +#define NETBSD_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include "conky.h" +#include "common.h" + +#endif /*NETBSD_H_*/ diff --git a/src/openbsd.c b/src/openbsd.c index 1a87e874..e972938e 100644 --- a/src/openbsd.c +++ b/src/openbsd.c @@ -49,9 +49,6 @@ #include #include #include -#include -#include -#include #include #include diff --git a/src/openbsd.h b/src/openbsd.h new file mode 100644 index 00000000..131fe260 --- /dev/null +++ b/src/openbsd.h @@ -0,0 +1,26 @@ +#ifndef OPENBSD_H_ +#define OPENBSD_H_ + +#include "common.h" +#include +#include +#include + +void update_obsd_sensors(void); +void get_obsd_vendor(char *buf, size_t client_buffer_size); +void get_obsd_product(char *buf, size_t client_buffer_size); + +#define OBSD_MAX_SENSORS 256 +struct obsd_sensors_struct { + int device; + float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; + unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; + float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; +}; +struct obsd_sensors_struct obsd_sensors; + +#if defined(i386) || defined(__i386__) +typedef struct apm_power_info *apm_info_t; +#endif + +#endif /*OPENBSD_H_*/ diff --git a/src/prss.c b/src/prss.c index 0c25de9b..b2c02989 100644 --- a/src/prss.c +++ b/src/prss.c @@ -15,14 +15,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "config.h" #include "prss.h" #include "conky.h" #include #include -#include -#include -#include #ifndef PARSE_OPTIONS #define PARSE_OPTIONS 0 diff --git a/src/rss.c b/src/rss.c index 3f142774..c1aa0ac5 100644 --- a/src/rss.c +++ b/src/rss.c @@ -27,8 +27,6 @@ #include "conky.h" #include "prss.h" -#include -#include #include #include #include diff --git a/src/rss.h b/src/rss.h new file mode 100644 index 00000000..9391c5a0 --- /dev/null +++ b/src/rss.h @@ -0,0 +1,10 @@ +#ifndef RSS_H_ +#define RSS_H_ + +#include "prss.h" + +PRSS *get_rss_info(char *uri, int delay); +void init_rss_info(void); +void free_rss_info(void); + +#endif /*RSS_H_*/ diff --git a/src/smapi.c b/src/smapi.c index 0a10baec..1d24224a 100644 --- a/src/smapi.c +++ b/src/smapi.c @@ -20,10 +20,8 @@ * $Id$ * */ -#include "conky.h" -#include -#include -#include + +#include "smapi.h" #define SYS_SMAPI_PATH "/sys/devices/platform/smapi" diff --git a/src/smapi.h b/src/smapi.h index 12175039..c1b6ae6d 100644 --- a/src/smapi.h +++ b/src/smapi.h @@ -24,6 +24,9 @@ #ifndef SMAPI_H #define SMAPI_H +#include "conky.h" +#include + int smapi_bat_installed(int); char *smapi_read_str(const char *); diff --git a/src/timed_thread.c b/src/timed_thread.c index 70ddaf46..a63d85c3 100644 --- a/src/timed_thread.c +++ b/src/timed_thread.c @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include #ifndef HAVE_CLOCK_GETTIME #include diff --git a/src/timed_thread.h b/src/timed_thread.h index 75822ab1..b6c0f051 100644 --- a/src/timed_thread.h +++ b/src/timed_thread.h @@ -22,6 +22,8 @@ #ifndef _TIMED_THREAD_H_ #define _TIMED_THREAD_H_ +#include + /* 10000 microseconds = 10 ms = 0.01 sec */ #define MINIMUM_INTERVAL_USECS 10000 diff --git a/src/top.h b/src/top.h index b176f34a..d777dcd2 100644 --- a/src/top.h +++ b/src/top.h @@ -40,8 +40,6 @@ #include "conky.h" #define CPU_THRESHHOLD 0 /* threshhold for the cpu diff to appear */ -#include -#include #include #include #include @@ -56,7 +54,6 @@ #include #include -#include #include #include #include @@ -76,6 +73,16 @@ #define PROCFS_CMDLINE_TEMPLATE "/proc/%d/cmdline" #define MAX_SP 10 // number of elements to sort +enum top_field { + TOP_CPU, + TOP_NAME, + TOP_PID, + TOP_MEM, + TOP_TIME, + TOP_MEM_RES, + TOP_MEM_VSIZE +}; + /****************************************** * Process class * ******************************************/ diff --git a/src/users.c b/src/users.c index 04e5564d..021af1fd 100644 --- a/src/users.c +++ b/src/users.c @@ -29,9 +29,6 @@ #include "conky.h" #include -#include -#include -#include #include static void user_name(char *ptr) diff --git a/src/x11.h b/src/x11.h new file mode 100644 index 00000000..0c218f6a --- /dev/null +++ b/src/x11.h @@ -0,0 +1,86 @@ +#ifndef X11_H_ +#define X11_H_ + +#include +#include +#include + +#ifdef XFT +#include +#endif + +#ifdef HAVE_XDBE +#include +#endif + +#define ATOM(a) XInternAtom(display, #a, False) + +#ifdef OWN_WINDOW +enum _window_type { + TYPE_NORMAL = 0, + TYPE_DOCK, + TYPE_DESKTOP, + TYPE_OVERRIDE +}; + +enum _window_hints { + HINT_UNDECORATED = 0, + HINT_BELOW, + HINT_ABOVE, + HINT_STICKY, + HINT_SKIP_TASKBAR, + HINT_SKIP_PAGER +}; + +#define SET_HINT(mask, hint) (mask |= (1 << hint)) +#define TEST_HINT(mask, hint) (mask & (1 << hint)) +#endif + +struct conky_window { + Window root, window, desktop; + Drawable drawable; + GC gc; +#ifdef HAVE_XDBE + XdbeBackBuffer back_buffer; +#endif +#ifdef XFT + XftDraw *xftdraw; +#endif + + int width; + int height; +#ifdef OWN_WINDOW + char class_name[256]; + char title[256]; + int x; + int y; + unsigned int type; + unsigned long hints; +#endif +}; + +#ifdef HAVE_XDBE +extern int use_xdbe; +#endif + +#ifdef XFT +extern int use_xft; +#endif + +extern Display *display; +extern int display_width; +extern int display_height; +extern int screen; + +extern int workarea[4]; + +extern struct conky_window window; + +void init_X11(void); +void init_window(int use_own_window, int width, int height, int set_trans, + int back_colour, char **argv, int argc); +void create_gc(void); +void set_transparent_background(Window win); +long get_x11_color(const char *); + +#endif /*X11_H_*/ diff --git a/src/xmms2.c b/src/xmms2.c index 42d7dea0..8f5503e6 100644 --- a/src/xmms2.c +++ b/src/xmms2.c @@ -25,9 +25,6 @@ * $Id$ */ #include "conky.h" -#include -#include -#include #include #define CONN_INIT 0 diff --git a/src/xmms2.h b/src/xmms2.h new file mode 100644 index 00000000..e1caf0d2 --- /dev/null +++ b/src/xmms2.h @@ -0,0 +1,27 @@ +#ifndef XMMS2_H_ +#define XMMS2_H_ + +struct xmms2_s { + char *artist; + char *album; + char *title; + char *genre; + char *comment; + char *url; + char *date; + char* playlist; + int tracknr; + int bitrate; + unsigned int id; + int duration; + int elapsed; + int timesplayed; + float size; + + float progress; + char *status; +}; + +void update_xmms2(void); + +#endif /*XMMS2_H_*/