From 7264b97e7ad71701f46063e9290324ce3166b888 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 8 Mar 2010 18:13:55 +0100 Subject: [PATCH 01/41] Add missing header after commit d93dc72e6dbaaa254eaf7ccf0b014d6af1bb45ea;hpb=0336b5d67daf0b03868c4e594a0eca15a4aecd00 --- src/tailhead.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tailhead.cc b/src/tailhead.cc index 2ac6af67..931c3f25 100644 --- a/src/tailhead.cc +++ b/src/tailhead.cc @@ -38,6 +38,7 @@ #include #include #include +#include #define MAX_HEADTAIL_LINES 30 #define DEFAULT_MAX_HEADTAIL_USES 2 From 405a1753660b4a31475e1c15d2545e146fd558bd Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 5 Mar 2010 21:40:41 +0100 Subject: [PATCH 02/41] add vi modeline --- src/fonts.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fonts.h b/src/fonts.h index f08e788c..e8c988c8 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -1,4 +1,5 @@ /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=cpp * * Conky, a system monitor, based on torsmo * From 5e13dce11c295b170c9b40d34b491f3813812ef8 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 12 Mar 2010 19:27:07 +0100 Subject: [PATCH 03/41] Simplify border width expressions by common subexpression elimination --- src/conky.cc | 59 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 726446a6..96e7b4f8 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -985,10 +985,12 @@ static void update_text_area(void) if (own_window && !fixed_pos) { x += workarea[0]; y += workarea[1]; - text_start_x = window.border_inner_margin + window.border_outer_margin + window.border_width; - text_start_y = window.border_inner_margin + window.border_outer_margin + window.border_width; - window.x = x - window.border_inner_margin - window.border_outer_margin - window.border_width; - window.y = y - window.border_inner_margin - window.border_outer_margin - window.border_width; + + long border_total = window.border_inner_margin + + window.border_outer_margin + window.border_width; + text_start_x = text_start_y = border_total; + window.x = x - border_total; + window.y = y - border_total; } else #endif { @@ -1844,10 +1846,12 @@ static void clear_text(int exposures) #endif if (display && window.window) { // make sure these are !null /* there is some extra space for borders and outlines */ - XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width, - text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width, - text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, - text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, exposures ? True : 0); + long border_total = window.border_inner_margin + + window.border_outer_margin + window.border_width; + + XClearArea(display, window.window, text_start_x - border_total, + text_start_y - border_total, text_width + 2*border_total, + text_height + 2*border_total, exposures ? True : 0); } } #endif /* BUILD_X11 */ @@ -1964,16 +1968,20 @@ static void main_loop(void) need_to_update = 0; selected_font = 0; update_text_area(); + + long border_total = window.border_inner_margin + + window.border_outer_margin + window.border_width; + #ifdef OWN_WINDOW if (own_window) { int changed = 0; /* resize window if it isn't right size */ if (!fixed_size - && (text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2 != window.width - || text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2 != window.height)) { - window.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2; - window.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2; + && (text_width + 2*border_total != window.width + || text_height + 2*border_total != window.height)) { + window.width = text_width + 2*border_total; + window.height = text_height + 2*border_total; draw_stuff(); /* redraw everything in our newly sized window */ XResizeWindow(display, window.window, window.width, window.height); /* resize window */ @@ -2041,10 +2049,10 @@ static void main_loop(void) if (use_xdbe) { XRectangle r; - r.x = text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width; - r.y = text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width; - r.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2; - r.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2; + r.x = text_start_x - border_total; + r.y = text_start_y - border_total; + r.width = text_width + 2*border_total; + r.height = text_height + 2*border_total; XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region); } #endif @@ -2201,10 +2209,12 @@ static void main_loop(void) if (use_xdbe) { XRectangle r; - r.x = text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width; - r.y = text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width; - r.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2; - r.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2; + long border_total = window.border_inner_margin + + window.border_outer_margin + window.border_width; + r.x = text_start_x - border_total; + r.y = text_start_y - border_total; + r.width = text_width + 2*border_total; + r.height = text_height + 2*border_total; XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region); } #endif @@ -2379,10 +2389,11 @@ void clean_up(void *memtofree1, void* memtofree2) #ifdef BUILD_X11 if (x_initialised == YES) { if(window_created == 1) { - XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width, - text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width, - text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, - text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, 0); + long border_total = window.border_inner_margin + + window.border_outer_margin + window.border_width; + XClearArea(display, window.window, text_start_x - border_total, + text_start_y - border_total, text_width + 2*border_total, + text_height + 2*border_total, 0); } destroy_window(); free_fonts(); From cc71dea079e51340c8ed376ab073f945c9a0c3da Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Sat, 13 Mar 2010 19:28:45 +0100 Subject: [PATCH 04/41] Fix doc re. mixer names (cherry picked from commit 1fe99bc578106379bc642dd47daee081f9db563f) --- doc/variables.xml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 76bf77f6..04bd6147 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2071,15 +2071,10 @@ Prints the mixer value as reported by the OS. - Default mixer is "vol", but you can specify one of the - following optional arguments: "vol", "bass", "treble", - "synth", "pcm", "speaker", "line", "mic", "cd", "mix", - "pcm2", "rec", "igain", "ogain", "line1", "line2", "line3", - "dig1", "dig2", "dig3", "phin", "phout", "video", "radio", - "monitor". Refer to the definition of SOUND_DEVICE_NAMES in - <linux/soundcard.h> (on Linux), <soundcard.h> - (on OpenBSD), or <sys/soundcard.h> to find the exact - options available on your system. + Default mixer is "Master", but you can specify one of the + available ALSA Simple mixer controls. + You can find the list of those available on your system + using amixer. From 4b386667770e8ec7a31b938fc234cf5a73120d57 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 14 Mar 2010 22:24:03 +0100 Subject: [PATCH 05/41] Fix a couple of problems when compiling without OWN_WINDOW --- src/conky.cc | 11 ++++++----- src/x11.cc | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 96e7b4f8..54ce5b2f 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1969,9 +1969,10 @@ static void main_loop(void) selected_font = 0; update_text_area(); +#if defined(OWN_WINDOW) || defined(BUILD_XDBE) long border_total = window.border_inner_margin + window.border_outer_margin + window.border_width; - +#endif #ifdef OWN_WINDOW if (own_window) { int changed = 0; @@ -2878,9 +2879,9 @@ static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **va } #ifdef BUILD_X11 -void setalignment(int* text_alignment, unsigned int windowtype, const char* value, const char *f, int line, bool conffile) { +void setalignment(int* text_alignment, const char* value, const char *f, int line, bool conffile) { #ifdef OWN_WINDOW - if (windowtype == TYPE_DOCK) { + if (window.type == TYPE_DOCK) { NORM_ERR("alignment is disabled when own_window_type is dock"); } else #endif /*OWN_WINDOW */ @@ -2942,7 +2943,7 @@ char load_config_file(const char *f) } } CONF("alignment") { - setalignment(&text_alignment, window.type, value, f, line, true); + setalignment(&text_alignment, value, f, line, true); } CONF("background") { fork_to_background = string_to_bool(value); @@ -4074,7 +4075,7 @@ void initialisation(int argc, char **argv) { set_first_font(optarg); break; case 'a': - setalignment(&text_alignment, window.type, optarg, NULL, 0, false); + setalignment(&text_alignment, optarg, NULL, 0, false); break; #ifdef OWN_WINDOW diff --git a/src/x11.cc b/src/x11.cc index 8285b8b8..9f8f4020 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -266,6 +266,8 @@ void destroy_window(void) void init_window(int own_window, int w, int h, int set_trans, int back_colour, char **argv, int argc) { + // these vars are unused if OWN_WINDOW is not defined + (void)own_window; (void)w; (void)h; (void)argv; (void)argc; /* There seems to be some problems with setting transparent background * (on fluxbox this time). It doesn't happen always and I don't know why it * happens but I bet the bug is somewhere here. */ From 8c30957671c57b27ea82c427b9a2ad5271ef4732 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 18 Mar 2010 21:26:10 +0100 Subject: [PATCH 06/41] fix "conky's $mpd_* don't update", sf.net #2970555 --- src/mpd.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpd.cc b/src/mpd.cc index cddc8911..c096f055 100644 --- a/src/mpd.cc +++ b/src/mpd.cc @@ -304,7 +304,7 @@ bool mpd_process(thread_handle &handle) static void update_mpd_thread(thread_handle &handle) { - while (1) if (mpd_process(handle)) return; + while (mpd_process(handle)) ; /* never reached */ } From d3723e727c911de1fb52ff506aa868156ccae05e Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 18 Mar 2010 21:31:18 +0100 Subject: [PATCH 07/41] Fix a leak in mpd.cc (refcount fail) --- src/mpd.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mpd.cc b/src/mpd.cc index c096f055..c3dbddca 100644 --- a/src/mpd.cc +++ b/src/mpd.cc @@ -99,8 +99,6 @@ void init_mpd(void) { if (!(refcount++)) /* first client */ memset(&mpd_info, 0, sizeof(mpd_info)); - - refcount++; } static void clear_mpd(void) From 939985042ae78b10d4983146dbb7bbd90369ad7d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 19 Mar 2010 20:33:49 +0100 Subject: [PATCH 08/41] Remove a redundant copy of arg[cv] --- src/conky.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 54ce5b2f..22f84f16 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2755,20 +2755,17 @@ static void X11_initialisation(void) #endif /* DEBUG */ } -static char **xargv = 0; -static int xargc = 0; - static void X11_create_window(void) { if (output_methods & TO_X) { #ifdef OWN_WINDOW init_window(own_window, text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, set_transparent, background_colour, - xargv, xargc); + argv_copy, argc_copy); #else /* OWN_WINDOW */ init_window(0, text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, set_transparent, 0, - xargv, xargc); + argv_copy, argc_copy); #endif /* OWN_WINDOW */ setup_fonts(); @@ -4174,8 +4171,6 @@ void initialisation(int argc, char **argv) { memset(tmpstring2, 0, text_buffer_size); #ifdef BUILD_X11 - xargc = argc; - xargv = argv; X11_create_window(); #endif /* BUILD_X11 */ #ifdef BUILD_LUA From 34f3547c0d26fa4cf7f73678ace2c9c1c3b7605b Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sat, 10 Apr 2010 20:11:20 +0200 Subject: [PATCH 09/41] Bugfix: When the first line behind TEXT was a comment, the start of the second line wasn't parsed --- src/core.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.cc b/src/core.cc index 0c3410ff..88fa8ece 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1819,7 +1819,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const strfold(p, 1); } else if (*p == '#') { char c; - if (remove_comment(p, &c) && p > orig_p && c == '\n') { + if (remove_comment(p, &c) && p >= orig_p && c == '\n') { /* if remove_comment removed a newline, we need to 'back up' with p */ p--; } From 15326c502c5ce965c119de1581991355d3d05fb8 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 11 Apr 2010 19:13:14 +0200 Subject: [PATCH 10/41] Bugfix: battery_bar should also work without argument --- src/core.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.cc b/src/core.cc index 88fa8ece..6de868f5 100644 --- a/src/core.cc +++ b/src/core.cc @@ -318,11 +318,11 @@ struct text_object *construct_text_object(char *s, const char *arg, long END OBJ(battery_bar, 0) char bat[64]; if (arg) { - arg = scan_bar(obj, arg, 100); sscanf(arg, "%63s", bat); } else { strcpy(bat, "BAT0"); } + scan_bar(obj, bat, 100); obj->data.s = strndup(bat, text_buffer_size); obj->callbacks.barval = &get_battery_perct_bar; obj->callbacks.free = &gen_free_opaque; From a6b43da87586b0857ec12f18d86d2897ae1d3f6a Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 12 Apr 2010 12:33:24 +0200 Subject: [PATCH 11/41] Bugfix: ac-adapter is sometimes called ADP1 in sysfs instead of AC --- src/core.cc | 3 --- src/linux.cc | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core.cc b/src/core.cc index 6de868f5..975d90d3 100644 --- a/src/core.cc +++ b/src/core.cc @@ -183,9 +183,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long NORM_ERR("acpiacadapter: arg is only used on linux"); #endif } - if(! obj->data.opaque) - obj->data.opaque = strdup("AC"); - obj->callbacks.print = &print_acpiacadapter; obj->callbacks.free = &gen_free_opaque; #endif /* !__OpenBSD__ */ diff --git a/src/linux.cc b/src/linux.cc index 8327345e..8994b7e9 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -1353,6 +1353,8 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) Update: it seems the folder name is hardware-dependent. We add an aditional adapter argument, specifying the folder name. + + Update: on some systems it's /sys/class/power_supply/ADP1 instead of /sys/class/power_supply/AC */ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter) @@ -1361,14 +1363,20 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char buf[256]; char buf2[256]; + struct stat sb; FILE *fp; if (!p_client_buffer || client_buffer_size <= 0) { return; } - snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter); - fp = open_file(buf2, &rep); + if(adapter) + snprintf(buf2, sizeof(buf2), "%s/%s/uevent", SYSFS_AC_ADAPTER_DIR, adapter); + else{ + snprintf(buf2, sizeof(buf2), "%s/AC/uevent", SYSFS_AC_ADAPTER_DIR); + if(stat(buf2, &sb) == -1) snprintf(buf2, sizeof(buf2), "%s/ADP1/uevent", SYSFS_AC_ADAPTER_DIR); + } + if(stat(buf2, &sb) == 0) fp = open_file(buf2, &rep); else fp = 0; if (fp) { /* sysfs processing */ while (!feof(fp)) { From 1de13eb7286779eed17446d9f161aa71e2881ecc Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 12 Apr 2010 12:48:02 +0200 Subject: [PATCH 12/41] update docs --- doc/variables.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 04bd6147..e33b63dc 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -7,8 +7,8 @@ ACPI ac adapter state. On linux, the adapter option specifies the - subfolder of /sys/class/power_supply containing the state information (defaults - to "AC"). Other systems ignore it. + subfolder of /sys/class/power_supply containing the state information (tries "AC" + and "ADP1" if there is no argument given). Non-linux systems ignore it. From 96ec637af972228df356811a97b1253e196d6b60 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 12 Apr 2010 13:37:49 +0200 Subject: [PATCH 13/41] Bugfix: mixerbar showed wrong values --- src/mixer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mixer.cc b/src/mixer.cc index 42a27b2a..c1ac9de2 100644 --- a/src/mixer.cc +++ b/src/mixer.cc @@ -318,10 +318,10 @@ void scan_mixer_bar(struct text_object *obj, const char *arg) if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) { obj->data.i = mixer_init(buf1); - scan_bar(obj, arg + n, 255); + scan_bar(obj, arg + n, 100); } else { obj->data.i = mixer_init(NULL); - scan_bar(obj, arg, 255); + scan_bar(obj, arg, 100); } } From ce5a64d08af7e58b9f4d8e2f2f621bdc821faf75 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 12 Apr 2010 16:55:03 +0200 Subject: [PATCH 14/41] Removed all code depending on MIXER_IS_ALSA Reasons: -As far as i know, all systems can use the non-MIXER_IS_ALSA way to get the values -This code shows wrong mixer values -You can't define MIXER_IS_ALSA with the current cmake configuration -In the current state this code is incorrect c++ and does not compile (altough it's probably correct c, i didn't check that) The 3 last reasons can be fixed, but i'm not in favor of doing that because of the 1st reason --- src/mixer.cc | 165 --------------------------------------------------- 1 file changed, 165 deletions(-) diff --git a/src/mixer.cc b/src/mixer.cc index c1ac9de2..b8d09d09 100644 --- a/src/mixer.cc +++ b/src/mixer.cc @@ -38,9 +38,6 @@ #include -#ifdef MIXER_IS_ALSA -#include -#else #ifdef HAVE_LINUX_SOUNDCARD_H #include #else @@ -50,173 +47,12 @@ #include #endif /* __OpenBSD__ */ #endif /* HAVE_LINUX_SOUNDCARD_H */ -#endif /* MIXER_IS_ALSA */ #define MIXER_DEV "/dev/mixer" -#ifdef MIXER_IS_ALSA -#define MAX_MIXERS 8 -struct mixer_control { - char name[64]; - snd_mixer_t *mixer; - snd_mixer_selem_id_t *sid; - snd_mixer_elem_t *elem; - long vol_min, vol_max; -}; - -static struct mixer_control mixer_data[MAX_MIXERS]; -int num_mixers = 0; -static char soundcard[64] = "default"; -#else static int mixer_fd; static const char *devs[] = SOUND_DEVICE_NAMES; -#endif -#ifdef MIXER_IS_ALSA -static int parse_simple_id(const char *str, snd_mixer_selem_id_t *sid) -{ - int c, size; - char buf[128]; - char *ptr = buf; - - while (*str == ' ' || *str == '\t') - str++; - if (!(*str)) - return -EINVAL; - size = 1; /* for '\0' */ - if (*str != '"' && *str != '\'') { - while (*str && *str != ',') { - if (size < (int)sizeof(buf)) { - *ptr++ = *str; - size++; - } - str++; - } - } else { - c = *str++; - while (*str && *str != c) { - if (size < (int)sizeof(buf)) { - *ptr++ = *str; - size++; - } - str++; - } - if (*str == c) - str++; - } - if (*str == '\0') { - snd_mixer_selem_id_set_index(sid, 0); - *ptr = 0; - goto _set; - } - if (*str != ',') - return -EINVAL; - *ptr = 0; /* terminate the string */ - str++; - if (!isdigit(*str)) - return -EINVAL; - snd_mixer_selem_id_set_index(sid, atoi(str)); - _set: - snd_mixer_selem_id_set_name(sid, buf); - return 0; -} - -int mixer_init (const char *name) -{ - /* from amixer.c, replaced -EINVAL with -1 */ - int i, err; - if (!name) - name = "Master"; - - for (i = 0; i < num_mixers; i++) { - if (!strcasecmp (mixer_data[i].name, name)) { - return i; - } - } - if (i == MAX_MIXERS) { - fprintf (stderr, "max mixers (%d) reached\n", MAX_MIXERS); - return -1; - }; - - num_mixers++; -#define data mixer_data[i] - - strncpy (mixer_data[i].name, name, 63); - mixer_data[i].name[63] = '\0'; - snd_mixer_selem_id_alloca (&data.sid); - data.mixer = NULL; - if (parse_simple_id (name, data.sid) < 0) { - fprintf (stderr, "Wrong mixer identifier: %s\n", name); - return -1; - } - if ((err = snd_mixer_open (&data.mixer, 0)) < 0) { - fprintf (stderr, "snd_mixer_open: %s\n", snd_strerror (err)); - return -1; - } - if ((err = snd_mixer_attach (data.mixer, soundcard)) < 0) { - fprintf (stderr, "snd_mixer_attach: %s\n", snd_strerror (err)); - return -1; - } - if ((err = snd_mixer_selem_register (data.mixer, NULL, NULL)) < 0) { - fprintf (stderr, "snd_mixer_selem_register: %s\n", - snd_strerror (err)); - return -1; - } - if ((err = snd_mixer_load (data.mixer)) < 0) { - fprintf (stderr, "snd_mixer_load: %s\n", snd_strerror (err)); - return -1; - } - if (!(data.elem = snd_mixer_find_selem (data.mixer, data.sid))) { - fprintf (stderr, "snd_mixer_find_selem (\"%s\", %i)\n", - snd_mixer_selem_id_get_name (data.sid), - snd_mixer_selem_id_get_index (data.sid)); - return -1; - } - snd_mixer_selem_get_playback_volume_range(data.elem, &data.vol_min, &data.vol_max); - return i; -} -static int mixer_get_avg (int i) -{ - long val; - - snd_mixer_handle_events (data.mixer); - snd_mixer_selem_get_playback_volume (data.elem, 0, &val); - if(data.vol_max != 100) { - float avgf = ((float)val / data.vol_max) * 100; - int avg = (int)avgf; - return (avgf - avg < 0.5) ? avg : avg + 1; - } - return (int) val; -} -static int mixer_get_left (int i) -{ - /* stub */ - return mixer_get_avg (i); -} -static int mixer_get_right (int i) -{ - /* stub */ - return mixer_get_avg (i); -} -int mixer_to_255(int i, int x) -{ - return (x-data.vol_min)*255/(data.vol_max-data.vol_min); -} -int mixer_is_mute(int i) -{ - snd_mixer_handle_events (data.mixer); - if (snd_mixer_selem_has_playback_switch (data.elem)) { - int val, err; - if ((err = snd_mixer_selem_get_playback_switch(data.elem, 0, &val)) < 0) - fprintf (stderr, "playback_switch: %s\n", snd_strerror (err)); - return !val; - } else { - return !mixer_get_avg(i); - } -} -#undef data - -#else /* MIXER_IS_ALSA */ int mixer_init(const char *name) { unsigned int i; @@ -282,7 +118,6 @@ int mixer_is_mute(int i) } #define mixer_to_255(i, x) x -#endif /* MIXER_IS_ALSA */ void parse_mixer_arg(struct text_object *obj, const char *arg) { From f1c717286b28267f9982621541d95633bd6074e4 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 12 Apr 2010 22:40:16 +0200 Subject: [PATCH 15/41] inotifi_init1() is not available on older systems -> replace with inotify_init() + fcntl() atomicity should not be important here, since we don't have any threads running at the point of the call --- src/conky.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/conky.cc b/src/conky.cc index 22f84f16..64660525 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -4291,7 +4291,13 @@ int main(int argc, char **argv) #endif /* BUILD_WEATHER_XOAP */ #ifdef HAVE_SYS_INOTIFY_H - inotify_fd = inotify_init1(IN_NONBLOCK); + inotify_fd = inotify_init(); + if(inotify_fd != -1) { + int fl; + + fl = fcntl(inotify_fd, F_GETFL); + fcntl(inotify_fd, F_SETFL, fl | O_NONBLOCK); + } #endif /* HAVE_SYS_INOTIFY_H */ initialisation(argc, argv); From dbfbc5f28c48f565a8859e2059aa50c49c09df48 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 12 Apr 2010 23:27:12 +0200 Subject: [PATCH 16/41] Bugfix: adding/removing use_xft in the config had no effect unless you restarted conky, reloading the config was not enough --- src/conky.cc | 3 +++ src/x11.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conky.cc b/src/conky.cc index 64660525..f90fc740 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2623,6 +2623,9 @@ static void set_default_configurations(void) output_methods = TO_STDOUT; #endif #ifdef BUILD_X11 +#ifdef BUILD_XFT + use_xft = 0; +#endif show_graph_scale = 0; show_graph_range = 0; draw_shades = 1; diff --git a/src/x11.cc b/src/x11.cc index 9f8f4020..12a8ca23 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -44,7 +44,7 @@ #ifdef BUILD_XFT #include -int use_xft = 0; +int use_xft; #endif #ifdef BUILD_XDBE From cda990633c94c97496c5ebc317bae06cf6a2002e Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Tue, 13 Apr 2010 17:02:39 +0200 Subject: [PATCH 17/41] Add support for --stdin-config --- doc/command_options.xml | 9 +++++++++ src/conky.cc | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/command_options.xml b/doc/command_options.xml index e920e3c2..ad1b0e43 100644 --- a/doc/command_options.xml +++ b/doc/command_options.xml @@ -119,6 +119,15 @@ conky -s 'Your uptime is: $uptime' + + + + + + + Read configuration from stdin. + + diff --git a/src/conky.cc b/src/conky.cc index f90fc740..33607bc3 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -331,6 +331,8 @@ struct information info; /* path to config file */ std::string current_config; +bool stdinconfig = false; + /* set to 1 if you want all text to be in uppercase */ static unsigned int stuff_in_uppercase; @@ -3897,6 +3899,7 @@ static void print_help(const char *prog_name) { " -y Y y position\n" #endif /* BUILD_X11 */ " -s, --for-scripts=TEXT render TEXT on stdout and exit, enclose TEXT by single quotes\n" + " -S, --stdin-config read configuration from stdin\n" " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n" " -u, --interval=SECS update interval\n" " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n" @@ -3915,7 +3918,7 @@ inline void reset_optind() { } /* : means that character before that takes an argument */ -static const char *getopt_string = "vVqdDs:t:u:i:hc:p:" +static const char *getopt_string = "vVqdDSs:t:u:i:hc:p:" #ifdef BUILD_X11 "x:y:w:a:f:X:" #ifdef OWN_WINDOW @@ -3953,6 +3956,7 @@ static const struct option longopts[] = { { "window-id", 1, NULL, 'w' }, #endif /* BUILD_X11 */ { "for-scripts", 1, NULL, 's' }, + { "stdin-config", 0, NULL, 'S' }, { "text", 1, NULL, 't' }, { "interval", 1, NULL, 'u' }, { "pause", 1, NULL, 'p' }, @@ -3960,8 +3964,13 @@ static const struct option longopts[] = { }; void set_current_config() { - /* check if specified config file is valid */ - if (not current_config.empty()) { + /* set configfile to stdin if that's requested or check if specified config file is valid */ + if(stdinconfig) { + char mystdin[32]; +#define CONKYSTDIN "/proc/%u/fd/0" + sprintf(mystdin, CONKYSTDIN, getpid()); + current_config = mystdin; + } else if (not current_config.empty()) { struct stat sb; if (stat(current_config.c_str(), &sb) || (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) { @@ -4259,6 +4268,9 @@ int main(int argc, char **argv) case 'c': current_config = optarg; break; + case 'S': + stdinconfig = true; + break; case 'q': if (!freopen("/dev/null", "w", stderr)) CRIT_ERR(0, 0, "could not open /dev/null as stderr!"); From 08ea4391d47f43be557dd32e9ab4226d884803ca Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 14 Apr 2010 16:59:50 +0200 Subject: [PATCH 18/41] Deprecated max_specials, made it unlimited by changing the data structure for specials --- cmake/ConkyBuildOptions.cmake | 1 - cmake/config.h.in | 1 - doc/config_settings.xml | 10 -- extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/conky.cc | 205 +++++++++++++++++----------------- src/specials.cc | 26 ++--- src/specials.h | 7 +- 8 files changed, 120 insertions(+), 134 deletions(-) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 0187d7f4..827bdcee 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -54,7 +54,6 @@ set(SYSTEM_CONFIG_FILE "/etc/conky/conky.conf" CACHE STRING "Default system-wide set(PACKAGE_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/lib/conky" CACHE STRING "Package library path (where Lua bindings are installed" FORCE) set(DEFAULTNETDEV "eth0" CACHE STRING "Default networkdevice") set(CONFIG_FILE "$HOME/.conkyrc" CACHE STRING "Configfile of the user") -set(MAX_SPECIALS_DEFAULT "512" CACHE STRING "Default maximum number of special things, e.g. fonts, offsets, aligns, etc.") set(MAX_USER_TEXT_DEFAULT "16384" CACHE STRING "Default maximum size of config TEXT buffer, i.e. below TEXT line.") set(DEFAULT_TEXT_BUFFER_SIZE "256" CACHE STRING "Default size used for temporary, static text buffers") set(MAX_NET_INTERFACES "16" CACHE STRING "Maximum number of network devices") diff --git a/cmake/config.h.in b/cmake/config.h.in index fad59201..f7b7dc17 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -15,7 +15,6 @@ #define PACKAGE_LIBDIR "@PACKAGE_LIBRARY_DIR@" #define DEFAULTNETDEV "@DEFAULTNETDEV@" #define CONFIG_FILE "@CONFIG_FILE@" -#define MAX_SPECIALS_DEFAULT @MAX_SPECIALS_DEFAULT@ #define MAX_USER_TEXT_DEFAULT @MAX_USER_TEXT_DEFAULT@ #define DEFAULT_TEXT_BUFFER_SIZE @DEFAULT_TEXT_BUFFER_SIZE@ #define MAX_NET_INTERFACES @MAX_NET_INTERFACES@ diff --git a/doc/config_settings.xml b/doc/config_settings.xml index b5a5d973..2f174ba7 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -453,16 +453,6 @@ many connections (if 0 or not set, default is 256) - - - - - - - Maximum number of special things, e.g. fonts, - offsets, aligns, etc. (default is 512) - - diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 70e9f2b5..1d315ea8 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -5,7 +5,7 @@ syntax "conky" "(\.*conkyrc.*$|conky.conf)" ## Configuration items -color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_specials|max_text_width|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" +color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_text_width|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" ## Configuration item constants color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index 0ab80c97..d02e1b00 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -12,7 +12,7 @@ endif syn region ConkyrcComment start=/^\s*#/ end=/$/ -syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook lua_startup_hook mail_spool max_port_monitor_connections max_specials max_text_width max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size times_in_seconds top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont +syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook lua_startup_hook mail_spool max_port_monitor_connections max_text_width max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size times_in_seconds top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont syn keyword ConkyrcConstant \ above diff --git a/src/conky.cc b/src/conky.cc index 33607bc3..8826679a 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -812,8 +812,6 @@ static void generate_text(void) char *p; unsigned int i, j, k; - special_count = 0; - /* update info */ current_update_time = get_time(); @@ -879,7 +877,7 @@ int get_string_width(const char *s) static int get_string_width_special(char *s, int special_index) { char *p, *final; - int idx = 1; + special_t *current = specials; int width = 0; long i; @@ -892,6 +890,9 @@ static int get_string_width_special(char *s, int special_index) p = strndup(s, text_buffer_size); final = p; + for(i = 0; i < special_index; i++) + current = current->next; + while (*p) { if (*p == SPECIAL_CHAR) { /* shift everything over by 1 so that the special char @@ -899,12 +900,12 @@ static int get_string_width_special(char *s, int special_index) for (i = 0; i < (long)strlen(p); i++) { *(p + i) = *(p + i + 1); } - if (specials[special_index + idx].type == GRAPH - || specials[special_index + idx].type == GAUGE - || specials[special_index + idx].type == BAR) { - width += specials[special_index + idx].width; + if (current->type == GRAPH + || current->type == GAUGE + || current->type == BAR) { + width += current->width; } - idx++; + current = current->next; } else if (*p == SECRIT_MULTILINE_CHAR) { *p = 0; break; @@ -1028,6 +1029,10 @@ static int text_size_updater(char *s, int special_index) int lw; int contain_SECRIT_MULTILINE_CHAR = 0; char *p; + special_t *current = specials; + + for(int i = 0; i < special_index; i++) + current = current->next; if ((output_methods & TO_X) == 0) return 0; @@ -1039,40 +1044,41 @@ static int text_size_updater(char *s, int special_index) w += get_string_width(s); *p = SPECIAL_CHAR; - if (specials[special_index].type == BAR - || specials[special_index].type == GAUGE - || specials[special_index].type == GRAPH) { - w += specials[special_index].width; - if (specials[special_index].height > last_font_height) { - last_font_height = specials[special_index].height; + if (current->type == BAR + || current->type == GAUGE + || current->type == GRAPH) { + w += current->width; + if (current->height > last_font_height) { + last_font_height = current->height; last_font_height += font_height(); } - } else if (specials[special_index].type == OFFSET) { - if (specials[special_index].arg > 0) { - w += specials[special_index].arg; + } else if (current->type == OFFSET) { + if (current->arg > 0) { + w += current->arg; } - } else if (specials[special_index].type == VOFFSET) { - last_font_height += specials[special_index].arg; - } else if (specials[special_index].type == GOTO) { - if (specials[special_index].arg > cur_x) { - w = (int) specials[special_index].arg; + } else if (current->type == VOFFSET) { + last_font_height += current->arg; + } else if (current->type == GOTO) { + if (current->arg > cur_x) { + w = (int) current->arg; } - } else if (specials[special_index].type == TAB) { - int start = specials[special_index].arg; - int step = specials[special_index].width; + } else if (current->type == TAB) { + int start = current->arg; + int step = current->width; if (!step || step < 0) { step = 10; } w += step - (cur_x - text_start_x - start) % step; - } else if (specials[special_index].type == FONT) { - selected_font = specials[special_index].font_added; + } else if (current->type == FONT) { + selected_font = current->font_added; if (font_height() > last_font_height) { last_font_height = font_height(); } } special_index++; + current = current->next; s = p + 1; } else if (*p == SECRIT_MULTILINE_CHAR) { contain_SECRIT_MULTILINE_CHAR = 1; @@ -1288,11 +1294,14 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) s = p + 1; } /* draw special */ - switch (specials[special_index].type) { + special_t *current = specials; + for(int i = 0; i < special_index; i++) + current = current->next; + switch (current->type) { #ifdef BUILD_X11 case HORIZONTAL_LINE: { - int h = specials[special_index].height; + int h = current->height; int mid = font_ascent() / 2; w = text_start_x + text_width - cur_x; @@ -1306,8 +1315,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) case STIPPLED_HR: { - int h = specials[special_index].height; - char tmp_s = specials[special_index].arg; + int h = current->height; + char tmp_s = current->arg; int mid = font_ascent() / 2; char ss[2] = { tmp_s, tmp_s }; @@ -1328,15 +1337,15 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) && maximum_width > 0) { break; } - h = specials[special_index].height; - bar_usage = specials[special_index].arg; - scale = specials[special_index].scale; + h = current->height; + bar_usage = current->arg; + scale = current->scale; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = specials[special_index].width; + w = current->width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1372,13 +1381,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) break; } - h = specials[special_index].height; + h = current->height; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = specials[special_index].width; + w = current->width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1393,8 +1402,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_x, by, w, h * 2, 0, 180*64); #ifdef MATH - usage = specials[special_index].arg; - scale = specials[special_index].scale; + usage = current->arg; + scale = current->scale; angle = M_PI * usage / scale; px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle); py = (float)(by+(h))-(float)(h)*sin(angle); @@ -1424,13 +1433,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) && maximum_width > 0) { break; } - h = specials[special_index].height; + h = current->height; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = specials[special_index].width; + w = current->width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1446,37 +1455,37 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); - if (specials[special_index].last_colour != 0 - || specials[special_index].first_colour != 0) { - tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour); + if (current->last_colour != 0 + || current->first_colour != 0) { + tmpcolour = do_gradient(w - 1, current->last_colour, current->first_colour); } colour_idx = 0; for (i = w - 2; i > -1; i--) { - if (specials[special_index].last_colour != 0 - || specials[special_index].first_colour != 0) { - if (specials[special_index].tempgrad) { + if (current->last_colour != 0 + || current->first_colour != 0) { + if (current->tempgrad) { #ifdef DEBUG_lol assert( - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) < w - 1 ); assert( - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) > -1 ); - if (specials[special_index].graph[j] == specials[special_index].scale) { + if (current->graph[j] == current->scale) { assert( - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) == 0 ); } #endif /* DEBUG_lol */ XSetForeground(display, window.gc, tmpcolour[ - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) ]); } else { XSetForeground(display, window.gc, tmpcolour[colour_idx++]); @@ -1485,10 +1494,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* this is mugfugly, but it works */ XDrawLine(display, window.drawable, window.gc, cur_x + i + 1, by + h, cur_x + i + 1, - round_to_int((double)by + h - specials[special_index].graph[j] * - (h - 1) / specials[special_index].scale)); + round_to_int((double)by + h - current->graph[j] * + (h - 1) / current->scale)); if ((w - i) / ((float) (w - 2) / - (specials[special_index].graph_width)) > j + (current->graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) { j++; } @@ -1549,16 +1558,16 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_y = tmp_y; } #ifdef MATH - if (show_graph_scale && (specials[special_index].show_scale == 1)) { + if (show_graph_scale && (current->show_scale == 1)) { int tmp_x = cur_x; int tmp_y = cur_y; char *tmp_str; cur_x += font_ascent() / 2; cur_y += font_h / 2; tmp_str = (char *) - calloc(log10(floor(specials[special_index].scale)) + 4, + calloc(log10(floor(current->scale)) + 4, sizeof(char)); - sprintf(tmp_str, "%.1f", specials[special_index].scale); + sprintf(tmp_str, "%.1f", current->scale); draw_string(tmp_str); free(tmp_str); cur_x = tmp_x; @@ -1574,7 +1583,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) int old = font_ascent(); cur_y -= font_ascent(); - selected_font = specials[special_index].font_added; + selected_font = current->font_added; set_font(); if (cur_y + font_ascent() < cur_y + old) { cur_y += old; @@ -1587,43 +1596,43 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) #endif /* BUILD_X11 */ case FG: if (draw_mode == FG) { - set_foreground_color(specials[special_index].arg); + set_foreground_color(current->arg); } break; #ifdef BUILD_X11 case BG: if (draw_mode == BG) { - set_foreground_color(specials[special_index].arg); + set_foreground_color(current->arg); } break; case OUTLINE: if (draw_mode == OUTLINE) { - set_foreground_color(specials[special_index].arg); + set_foreground_color(current->arg); } break; case OFFSET: - w += specials[special_index].arg; + w += current->arg; last_special_needed = special_index; break; case VOFFSET: - cur_y += specials[special_index].arg; + cur_y += current->arg; break; case GOTO: - if (specials[special_index].arg >= 0) { - cur_x = (int) specials[special_index].arg; + if (current->arg >= 0) { + cur_x = (int) current->arg; } last_special_needed = special_index; break; case TAB: { - int start = specials[special_index].arg; - int step = specials[special_index].width; + int start = current->arg; + int step = current->width; if (!step || step < 0) { step = 10; @@ -1642,13 +1651,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* printf("pos_x %i text_start_x %i text_width %i cur_x %i " "get_string_width(p) %i gap_x %i " - "specials[special_index].arg %i window.border_inner_margin %i " + "current->arg %i window.border_inner_margin %i " "window.border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, - specials[special_index].arg, window.border_inner_margin, + current->arg, window.border_inner_margin, window.border_width); */ - if (pos_x > specials[special_index].arg && pos_x > cur_x) { - cur_x = pos_x - specials[special_index].arg; + if (pos_x > current->arg && pos_x > cur_x) { + cur_x = pos_x - current->arg; } last_special_needed = special_index; break; @@ -1664,11 +1673,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* printf("pos_x %i text_start_x %i text_width %i cur_x %i " "get_string_width(p) %i gap_x %i " - "specials[special_index].arg %i\n", pos_x, text_start_x, + "current->arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, - specials[special_index].arg); */ - if (pos_x > specials[special_index].arg) { - w = pos_x - specials[special_index].arg; + current->arg); */ + if (pos_x > current->arg) { + w = pos_x - current->arg; } last_special_needed = special_index; break; @@ -2371,10 +2380,20 @@ static void reload_config(void) initialisation(argc_copy, argv_copy); } +void free_specials(special_t *current) { + if(current) { + free_specials(current->next); + if (current->type == GRAPH) + free(current->graph); + delete current; + } else { + specials = NULL; + last_specials = NULL; + } +} + void clean_up(void *memtofree1, void* memtofree2) { - int i; - free_update_callbacks(); #ifdef BUILD_NCURSES @@ -2457,15 +2476,7 @@ void clean_up(void *memtofree1, void* memtofree2) xmlCleanupParser(); #endif /* BUILD_WEATHER_XOAP */ - if (specials) { - for (i = 0; i < special_count; i++) { - if (specials[i].type == GRAPH) { - free(specials[i].graph); - } - } - free_and_zero(specials); - } - + free_specials(specials); clear_net_stats(); clear_diskio_stats(); free_and_zero(global_cpu); @@ -3483,13 +3494,6 @@ char load_config_file(const char *f) CONF("uppercase") { stuff_in_uppercase = string_to_bool(value); } - CONF("max_specials") { - if (value) { - max_specials = atoi(value); - } else { - CONF_ERR; - } - } CONF("max_user_text") { if (value) { max_user_text = atoi(value); @@ -4039,11 +4043,6 @@ void initialisation(int argc, char **argv) { currentconffile = conftree_add(currentconffile, current_config.c_str()); } - /* init specials array */ - if ((specials = (special_t*)calloc(sizeof(struct special_t), max_specials)) == 0) { - NORM_ERR("failed to create specials array"); - } - #ifdef MAIL_FILE if (current_mail_spool == NULL) { char buf[256]; diff --git a/src/specials.cc b/src/specials.cc index 60cc141f..f89246b1 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -40,14 +40,8 @@ #endif /* HAVE_SYS_PARAM_H */ #include -/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */ -int max_specials = MAX_SPECIALS_DEFAULT; - -/* create specials array on heap instead of stack with introduction of - * max_specials */ struct special_t *specials = NULL; - -int special_count; +struct special_t *last_specials = NULL; int default_bar_width = 0, default_bar_height = 6; #ifdef BUILD_X11 @@ -253,14 +247,20 @@ char *scan_graph(struct text_object *obj, const char *args, double defscale) struct special_t *new_special(char *buf, enum special_types t) { - if (special_count >= max_specials) { - CRIT_ERR(NULL, NULL, "too many special things in text"); - } - buf[0] = SPECIAL_CHAR; buf[1] = '\0'; - specials[special_count].type = t; - return &specials[special_count++]; + if(specials) { + last_specials->next = new special_t; + last_specials->next->prev = last_specials; + last_specials = last_specials->next; + } else { + specials = new special_t; + specials->prev = NULL; + last_specials = specials; + } + last_specials->next = NULL; + last_specials->type = t; + return last_specials; } void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, double usage) diff --git a/src/specials.h b/src/specials.h index a3d9783f..535e250b 100644 --- a/src/specials.h +++ b/src/specials.h @@ -73,11 +73,13 @@ struct special_t { unsigned long last_colour; short font_added; char tempgrad; + struct special_t *next; + struct special_t *prev; }; /* direct access to the registered specials (FIXME: bad encapsulation) */ extern struct special_t *specials; -extern int special_count; +extern struct special_t *last_specials; extern int default_bar_width; extern int default_bar_height; @@ -91,9 +93,6 @@ extern int default_gauge_height; /* forward declare to avoid mutual inclusion between specials.h and text_object.h */ struct text_object; -/* max number of specials allowed (TODO: use linked list instead) */ -extern int max_specials; - /* scanning special arguments */ const char *scan_bar(struct text_object *, const char *, double); const char *scan_gauge(struct text_object *, const char *, double); From f5c147b16073266fb949c483c7fb196cc9df5150 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 14 Apr 2010 18:41:25 +0200 Subject: [PATCH 19/41] Add support for $nodename_short This is different implementation (compared to 9e3156a4a6502d82c527d13474cca33c4441c2b9) because 1.8.1 was still regular c instead of c++ --- doc/variables.xml | 9 +++++++++ extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/common.cc | 12 ++++++++++++ src/common.h | 1 + src/core.cc | 2 ++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index e33b63dc..cc49454e 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2435,6 +2435,15 @@ Hostname + + + + + + + Short hostname (same as 'hostname -s' shell command). + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 1d315ea8..743e44fd 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alignment|append_file|background|border_inner_margin|border_oute color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index d02e1b00..df520a10 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/common.cc b/src/common.cc index 6528d6a2..d8b9b57b 100644 --- a/src/common.cc +++ b/src/common.cc @@ -567,6 +567,18 @@ void print_nodename(struct text_object *obj, char *p, int p_max_size) snprintf(p, p_max_size, "%s", info.uname_s.nodename); } +void print_nodename_short(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + snprintf(p, p_max_size, "%s", info.uname_s.nodename); + for(int i=0; p[i] != 0; i++) { + if(p[i] == '.') { + p[i] = 0; + break; + } + } +} + void print_sysname(struct text_object *obj, char *p, int p_max_size) { (void)obj; diff --git a/src/common.h b/src/common.h index dbae80cb..12bdbf37 100644 --- a/src/common.h +++ b/src/common.h @@ -113,6 +113,7 @@ double swap_barval(struct text_object *); void print_kernel(struct text_object *, char *, int); void print_machine(struct text_object *, char *, int); void print_nodename(struct text_object *, char *, int); +void print_nodename_short(struct text_object *, char *, int); void print_sysname(struct text_object *, char *, int); void print_uptime(struct text_object *, char *, int); diff --git a/src/core.cc b/src/core.cc index 975d90d3..ca248ba5 100644 --- a/src/core.cc +++ b/src/core.cc @@ -902,6 +902,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long obj->callbacks.print = &print_format_time; END OBJ(nodename, 0) obj->callbacks.print = &print_nodename; + END OBJ(nodename_short, 0) + obj->callbacks.print = &print_nodename_short; END OBJ_ARG(cmdline_to_pid, 0, "cmdline_to_pid needs a command line as argument") scan_cmdline_to_pid_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_cmdline_to_pid; From 5ddf7513456a52cfd6ce781b8bf60af1d42cb39b Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 14 Apr 2010 21:50:50 +0200 Subject: [PATCH 20/41] Bugfix: "out_to_x no" was ignored when in a file included with ${include path_to_file} --- src/conky.cc | 61 ++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 8826679a..5c9c61b0 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2392,6 +2392,31 @@ void free_specials(special_t *current) { } } +#ifdef BUILD_X11 +void clean_up_x11() { + if(window_created == 1) { + long border_total = window.border_inner_margin + + window.border_outer_margin + window.border_width; + XClearArea(display, window.window, text_start_x - border_total, + text_start_y - border_total, text_width + 2*border_total, + text_height + 2*border_total, 0); + } + destroy_window(); + free_fonts(); + if(x11_stuff.region) { + XDestroyRegion(x11_stuff.region); + x11_stuff.region = NULL; + } + if(display) { + XCloseDisplay(display); + display = NULL; + } + free_and_zero(info.x11.desktop.all_names); + free_and_zero(info.x11.desktop.name); + x_initialised = NO; +} +#endif + void clean_up(void *memtofree1, void* memtofree2) { free_update_callbacks(); @@ -2410,30 +2435,13 @@ void clean_up(void *memtofree1, void* memtofree2) free_and_zero(info.cpu_usage); #ifdef BUILD_X11 if (x_initialised == YES) { - if(window_created == 1) { - long border_total = window.border_inner_margin - + window.border_outer_margin + window.border_width; - XClearArea(display, window.window, text_start_x - border_total, - text_start_y - border_total, text_width + 2*border_total, - text_height + 2*border_total, 0); - } - destroy_window(); - free_fonts(); - if(x11_stuff.region) { - XDestroyRegion(x11_stuff.region); - x11_stuff.region = NULL; - } - XCloseDisplay(display); - display = NULL; - free_and_zero(info.x11.desktop.all_names); - free_and_zero(info.x11.desktop.name); - x_initialised = NO; + clean_up_x11(); }else{ free(fonts); //in set_default_configurations a font is set but not loaded font_count = -1; } -#endif /* BUILD_X11 */ +#endif free_templates(); @@ -2936,15 +2944,12 @@ char load_config_file(const char *f) #ifdef BUILD_X11 CONF2("out_to_x") { - /* don't listen if X is already initialised or - * if we already know we don't want it */ - if(x_initialised != YES) { - if (string_to_bool(value)) { - output_methods &= TO_X; - } else { - output_methods &= ~TO_X; - x_initialised = NEVER; - } + if (string_to_bool(value)) { + output_methods &= TO_X; + } else { + clean_up_x11(); + output_methods &= ~TO_X; + x_initialised = NEVER; } } CONF("display") { From a734f86071edf25d266c91fec11e649ac51d5724 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 13:00:54 +0200 Subject: [PATCH 21/41] Bugfix: memleak at crash caused by missing arg --- src/core.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.cc b/src/core.cc index ca248ba5..25ec2e42 100644 --- a/src/core.cc +++ b/src/core.cc @@ -148,7 +148,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long #define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \ add_update_callback(n); #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj) -#define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); } +#define __OBJ_ARG(...) if (!arg) { free(s); CRIT_ERR(obj, free_at_crash, __VA_ARGS__); } /* defines to be used below */ #define OBJ(a, n) __OBJ_HEAD(a, n) { From 5ef6de88222163da030a566ca308d1b9a5b4b9a7 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 16:05:42 +0200 Subject: [PATCH 22/41] Add support for $distribution --- src/common.h | 2 ++ src/core.cc | 2 ++ src/linux.cc | 30 ++++++++++++++++++++++++++++++ src/linux.h | 2 ++ src/proc.cc | 2 +- 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 12bdbf37..fe551272 100644 --- a/src/common.h +++ b/src/common.h @@ -33,6 +33,8 @@ #include #include "text_object.h" +char* readfile(const char* filename, int* total_read, char showerror); + void print_to_bytes(struct text_object *, char *, int); void add_update_callback(void (*func)(void)); diff --git a/src/core.cc b/src/core.cc index 25ec2e42..d4d97107 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1037,6 +1037,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long END OBJ(processes, &update_total_processes) obj->callbacks.print = &print_processes; #ifdef __linux__ + END OBJ(distribution, 0) + obj->callbacks.print = &print_distribution; END OBJ(running_processes, &update_top) top_running = 1; obj->callbacks.print = &print_running_processes; diff --git a/src/linux.cc b/src/linux.cc index 8994b7e9..18ccfff0 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -2371,3 +2371,33 @@ void update_diskio(void) update_diskio_values(&stats, total_reads, total_writes); fclose(fp); } + +void print_distribution(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + int i, bytes_read; + char* buf = readfile("/proc/version", &bytes_read, 1); + + snprintf(p, p_max_size, "Unknown"); + if(buf) { + /* I am assuming the distribution name is the first string in /proc/version that: + - is preceded by a '(' + - starts with a capital + - is followed by a space and a number + but i am not sure if this is always true... */ + for(i=1; i= 'A' && buf[i] <= 'Z') break; + } + if(i < bytes_read) { + snprintf(p, p_max_size, &buf[i]); + for(i=1; p[i]; i++) { + if(p[i-1] == ' ' && p[i] >= '0' && p[i] <= '9') { + p[i-1] = 0; + break; + } + } + } + free(buf); + } +} + diff --git a/src/linux.h b/src/linux.h index ef3d1837..71697821 100644 --- a/src/linux.h +++ b/src/linux.h @@ -53,4 +53,6 @@ int get_entropy_poolsize(unsigned int *); void update_stat(void); +void print_distribution(struct text_object *, char *, int); + #endif /* _LINUX_H */ diff --git a/src/proc.cc b/src/proc.cc index 27c7f24b..736a2c0e 100644 --- a/src/proc.cc +++ b/src/proc.cc @@ -37,7 +37,7 @@ #include #include -char* readfile(char* filename, int* total_read, char showerror) { +char* readfile(const char* filename, int* total_read, char showerror) { FILE* file; char* buf = NULL; int bytes_read; From 5ecb0f7030b116115e41fa0cd5a8b6f4616ed7b4 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 16:49:55 +0200 Subject: [PATCH 23/41] Add support for arch linux to $distribution --- src/linux.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/linux.cc b/src/linux.cc index 18ccfff0..dd7773d1 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -2376,9 +2376,15 @@ void print_distribution(struct text_object *obj, char *p, int p_max_size) { (void)obj; int i, bytes_read; - char* buf = readfile("/proc/version", &bytes_read, 1); + char* buf; + struct stat sb; + if(stat("/etc/arch-release", &sb) == 0) { + snprintf(p, p_max_size, "Arch Linux"); + return; + } snprintf(p, p_max_size, "Unknown"); + buf = readfile("/proc/version", &bytes_read, 1); if(buf) { /* I am assuming the distribution name is the first string in /proc/version that: - is preceded by a '(' From 95a2de734681db2482c6305bb48c6c0cc9cc9a5d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 17:30:14 +0200 Subject: [PATCH 24/41] Update docs and extras --- doc/variables.xml | 16 ++++++++++++++++ extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index cc49454e..25c663a1 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -811,6 +811,22 @@ particular graph value (try it and see). + + + + + + + The name of the distribution. It could be that some + of the untested distributions will show up wrong or as "unknown", + if that's the case post a bug on sourceforge, make sure it + contains the name of your distribution, the contents of + /proc/version and if there is a file that only exists on your + distribution, also add the path of that file in the bug. If there + is no such file, please add another way which we can use to identify + your distribution. + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 743e44fd..6a2b51e3 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alignment|append_file|background|border_inner_margin|border_oute color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index df520a10..d59e0a9f 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword From ae6810fbd5d203a81502828d94eb8aca6117352e Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 19:54:01 +0200 Subject: [PATCH 25/41] Bugfix: read_tcp treated a succesfull connection as failed and vice versa --- src/read_tcp.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/read_tcp.cc b/src/read_tcp.cc index 0577769d..15e47cc8 100644 --- a/src/read_tcp.cc +++ b/src/read_tcp.cc @@ -87,7 +87,7 @@ void print_read_tcp(struct text_object *obj, char *p, int p_max_size) addr.sin_family = AF_INET; addr.sin_port = rtd->port; memcpy(&addr.sin_addr, he->h_addr, he->h_length); - if (!connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr))) { + if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) != 0) { NORM_ERR("read_tcp: Couldn't create a connection"); return; } From 2e34a9e1c5260c0e49bcb7528234524190ad3de5 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 21:31:10 +0200 Subject: [PATCH 26/41] Bugfix: segfault --- src/specials.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/specials.cc b/src/specials.cc index f89246b1..f7575ad1 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -258,6 +258,7 @@ struct special_t *new_special(char *buf, enum special_types t) specials->prev = NULL; last_specials = specials; } + last_specials->graph = NULL; last_specials->next = NULL; last_specials->type = t; return last_specials; From 131ceb5ccf354b488be494c3160aed4d180a994a Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 15 Apr 2010 23:59:24 +0200 Subject: [PATCH 27/41] Bugfix: shifted bars --- src/conky.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conky.cc b/src/conky.cc index 5c9c61b0..4d0ea749 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -890,7 +890,7 @@ static int get_string_width_special(char *s, int special_index) p = strndup(s, text_buffer_size); final = p; - for(i = 0; i < special_index; i++) + for(i = 0; i <= special_index; i++) current = current->next; while (*p) { From 0ab87b40a5768b9c2090c51daa13bd9c69002f62 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Fri, 16 Apr 2010 00:20:08 +0200 Subject: [PATCH 28/41] Improve unknown var error --- src/core.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.cc b/src/core.cc index d4d97107..9b54b32b 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1631,7 +1631,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long END { char *buf = (char *)malloc(text_buffer_size); - NORM_ERR("unknown variable %s", s); + NORM_ERR("unknown variable '$%s'", s); snprintf(buf, text_buffer_size, "${%s}", s); obj_be_plain_text(obj, buf); free(buf); From 19ad7d2cc3520c768ff3027f03f77b293114fb19 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Fri, 16 Apr 2010 18:53:48 +0200 Subject: [PATCH 29/41] Add support for $read_udp --- doc/variables.xml | 14 ++++++++++- extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/core.cc | 4 ++++ src/read_tcp.cc | 44 +++++++++++++++++++++++++++++++++-- src/read_tcp.h | 1 + 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 25c663a1..4b9db61e 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -3051,7 +3051,19 @@ Connects to a tcp port on a host (default is localhost), reads every char available at the moment and - shows them. + shows them. + + + + + + + + + + Connects to a udp port on a host (default is + localhost), reads every char available at the moment and + shows them. diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 6a2b51e3..bfbbd9b6 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alignment|append_file|background|border_inner_margin|border_oute color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index d59e0a9f..ddaf7b49 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/core.cc b/src/core.cc index 9b54b32b..a88c6821 100644 --- a/src/core.cc +++ b/src/core.cc @@ -212,6 +212,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long parse_read_tcp_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_read_tcp; obj->callbacks.free = &free_read_tcp; + END OBJ_ARG(read_udp, 0, "read_udp: Needs \"(host) port\" as argument(s)") + parse_read_tcp_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_read_udp; + obj->callbacks.free = &free_read_tcp; #if defined(__linux__) END OBJ(voltage_mv, 0) get_cpu_count(); diff --git a/src/read_tcp.cc b/src/read_tcp.cc index 15e47cc8..c492035a 100644 --- a/src/read_tcp.cc +++ b/src/read_tcp.cc @@ -57,7 +57,7 @@ void parse_read_tcp_arg(struct text_object *obj, const char *arg, void *free_at_ strcpy(rtd->host,"localhost"); } if(rtd->port < 1 || rtd->port > 65535) - CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)"); + CRIT_ERR(obj, free_at_crash, "read_tcp and read_udp need a port from 1 to 65535 as argument"); rtd->port = htons(rtd->port); obj->data.opaque = rtd; @@ -79,7 +79,7 @@ void print_read_tcp(struct text_object *obj, char *p, int p_max_size) NORM_ERR("read_tcp: Problem with resolving the hostname"); return; } - if ((sock = socket(he->h_addrtype, SOCK_STREAM, 0)) == -1) { + if ((sock = socket(he->h_addrtype, SOCK_STREAM, IPPROTO_TCP)) == -1) { NORM_ERR("read_tcp: Couldn't create a socket"); return; } @@ -102,6 +102,46 @@ void print_read_tcp(struct text_object *obj, char *p, int p_max_size) close(sock); } +void print_read_udp(struct text_object *obj, char *p, int p_max_size) +{ + int sock, received; + struct sockaddr_in addr; + struct hostent* he; + fd_set readfds; + struct timeval tv; + struct read_tcp_data *rtd = (struct read_tcp_data *) obj->data.opaque; + + if (!rtd) + return; + + if (!(he = gethostbyname(rtd->host))) { + NORM_ERR("read_udp: Problem with resolving the hostname"); + return; + } + if ((sock = socket(he->h_addrtype, SOCK_DGRAM, IPPROTO_UDP)) == -1) { + NORM_ERR("read_udp: Couldn't create a socket"); + return; + } + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = rtd->port; + memcpy(&addr.sin_addr, he->h_addr, he->h_length); + if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) != 0) { + NORM_ERR("read_udp: Couldn't create a connection"); + return; + } + write(sock, NULL, 0); //when using UDP i have to start writing to the socket before i can read from it, even if i don't actually write anything + FD_ZERO(&readfds); + FD_SET(sock, &readfds); + tv.tv_sec = 1; + tv.tv_usec = 0; + if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){ + received = recv(sock, p, p_max_size, 0); + if(received != -1) p[received] = 0; else p[0] = 0; + } + close(sock); +} + void free_read_tcp(struct text_object *obj) { struct read_tcp_data *rtd = (struct read_tcp_data *) obj->data.opaque; diff --git a/src/read_tcp.h b/src/read_tcp.h index fec3923d..f06ed752 100644 --- a/src/read_tcp.h +++ b/src/read_tcp.h @@ -33,6 +33,7 @@ void parse_read_tcp_arg(struct text_object *, const char *, void *); void print_read_tcp(struct text_object *, char *, int); +void print_read_udp(struct text_object *, char *, int); void free_read_tcp(struct text_object *); #endif /* _READ_TCP_H */ From 0047a132abca632689c74462af2535bf6b63ea61 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sat, 17 Apr 2010 02:31:37 +0200 Subject: [PATCH 30/41] Merge read_tcp and read_udp as much as possible --- src/CMakeLists.txt | 2 +- src/core.cc | 10 ++-- src/{read_tcp.cc => read_tcpip.cc} | 82 +++++++++++------------------- src/{read_tcp.h => read_tcpip.h} | 4 +- 4 files changed, 37 insertions(+), 61 deletions(-) rename src/{read_tcp.cc => read_tcpip.cc} (60%) rename src/{read_tcp.h => read_tcpip.h} (92%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a1aa375..8154e1fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,7 @@ endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build.h) set(conky_sources colours.cc combine.cc common.cc conky.cc core.cc diskio.cc entropy.cc exec.cc fs.cc mail.cc mixer.cc net_stat.cc template.cc - mboxscan.cc read_tcp.cc scroll.cc specials.cc tailhead.cc + mboxscan.cc read_tcpip.cc scroll.cc specials.cc tailhead.cc temphelper.cc text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.cc proc.cc user.cc) diff --git a/src/core.cc b/src/core.cc index a88c6821..2dd3763e 100644 --- a/src/core.cc +++ b/src/core.cc @@ -64,7 +64,7 @@ #ifdef BUILD_NVIDIA #include "nvidia.h" #endif -#include "read_tcp.h" +#include "read_tcpip.h" #include "scroll.h" #include "specials.h" #include "temphelper.h" @@ -209,13 +209,13 @@ struct text_object *construct_text_object(char *s, const char *arg, long } obj->callbacks.print = &print_freq_g; END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)") - parse_read_tcp_arg(obj, arg, free_at_crash); + parse_read_tcpip_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_read_tcp; - obj->callbacks.free = &free_read_tcp; + obj->callbacks.free = &free_read_tcpip; END OBJ_ARG(read_udp, 0, "read_udp: Needs \"(host) port\" as argument(s)") - parse_read_tcp_arg(obj, arg, free_at_crash); + parse_read_tcpip_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_read_udp; - obj->callbacks.free = &free_read_tcp; + obj->callbacks.free = &free_read_tcpip; #if defined(__linux__) END OBJ(voltage_mv, 0) get_cpu_count(); diff --git a/src/read_tcp.cc b/src/read_tcpip.cc similarity index 60% rename from src/read_tcp.cc rename to src/read_tcpip.cc index c492035a..39258f13 100644 --- a/src/read_tcp.cc +++ b/src/read_tcpip.cc @@ -37,17 +37,17 @@ #include #include -struct read_tcp_data { +struct read_tcpip_data { char *host; unsigned int port; }; -void parse_read_tcp_arg(struct text_object *obj, const char *arg, void *free_at_crash) +void parse_read_tcpip_arg(struct text_object *obj, const char *arg, void *free_at_crash) { - struct read_tcp_data *rtd; + struct read_tcpip_data *rtd; - rtd = (struct read_tcp_data *) malloc(sizeof(struct read_tcp_data)); - memset(rtd, 0, sizeof(struct read_tcp_data)); + rtd = (struct read_tcpip_data *) malloc(sizeof(struct read_tcpip_data)); + memset(rtd, 0, sizeof(struct read_tcpip_data)); rtd->host = (char *) malloc(text_buffer_size); sscanf(arg, "%s", rtd->host); @@ -63,24 +63,24 @@ void parse_read_tcp_arg(struct text_object *obj, const char *arg, void *free_at_ obj->data.opaque = rtd; } -void print_read_tcp(struct text_object *obj, char *p, int p_max_size) +void print_read_tcpip(struct text_object *obj, char *p, int p_max_size, int protocol) { int sock, received; struct sockaddr_in addr; struct hostent* he; fd_set readfds; struct timeval tv; - struct read_tcp_data *rtd = (struct read_tcp_data *) obj->data.opaque; + struct read_tcpip_data *rtd = (struct read_tcpip_data *) obj->data.opaque; if (!rtd) return; if (!(he = gethostbyname(rtd->host))) { - NORM_ERR("read_tcp: Problem with resolving the hostname"); + NORM_ERR("%s: Problem with resolving the hostname", protocol == IPPROTO_TCP ? "read_tcp" : "read_udp"); return; } - if ((sock = socket(he->h_addrtype, SOCK_STREAM, IPPROTO_TCP)) == -1) { - NORM_ERR("read_tcp: Couldn't create a socket"); + if ((sock = socket(he->h_addrtype, protocol == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM, protocol)) == -1) { + NORM_ERR("%s: Couldn't create a socket", protocol == IPPROTO_TCP ? "read_tcp" : "read_udp"); return; } memset(&addr, 0, sizeof(addr)); @@ -88,49 +88,15 @@ void print_read_tcp(struct text_object *obj, char *p, int p_max_size) addr.sin_port = rtd->port; memcpy(&addr.sin_addr, he->h_addr, he->h_length); if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) != 0) { - NORM_ERR("read_tcp: Couldn't create a connection"); + if(protocol == IPPROTO_TCP) { + NORM_ERR("read_tcp: Couldn't create a connection"); + } else { + NORM_ERR("read_udp: Couldn't listen"); //other error because udp is connectionless + } return; } - FD_ZERO(&readfds); - FD_SET(sock, &readfds); - tv.tv_sec = 1; - tv.tv_usec = 0; - if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){ - received = recv(sock, p, p_max_size, 0); - p[received] = 0; - } - close(sock); -} - -void print_read_udp(struct text_object *obj, char *p, int p_max_size) -{ - int sock, received; - struct sockaddr_in addr; - struct hostent* he; - fd_set readfds; - struct timeval tv; - struct read_tcp_data *rtd = (struct read_tcp_data *) obj->data.opaque; - - if (!rtd) - return; - - if (!(he = gethostbyname(rtd->host))) { - NORM_ERR("read_udp: Problem with resolving the hostname"); - return; - } - if ((sock = socket(he->h_addrtype, SOCK_DGRAM, IPPROTO_UDP)) == -1) { - NORM_ERR("read_udp: Couldn't create a socket"); - return; - } - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = rtd->port; - memcpy(&addr.sin_addr, he->h_addr, he->h_length); - if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) != 0) { - NORM_ERR("read_udp: Couldn't create a connection"); - return; - } - write(sock, NULL, 0); //when using UDP i have to start writing to the socket before i can read from it, even if i don't actually write anything + if(protocol == IPPROTO_UDP) + write(sock, NULL, 0); //when using udp send a zero-length packet to let the other end know of our existence FD_ZERO(&readfds); FD_SET(sock, &readfds); tv.tv_sec = 1; @@ -142,9 +108,19 @@ void print_read_udp(struct text_object *obj, char *p, int p_max_size) close(sock); } -void free_read_tcp(struct text_object *obj) +void print_read_tcp(struct text_object *obj, char *p, int p_max_size) { - struct read_tcp_data *rtd = (struct read_tcp_data *) obj->data.opaque; + print_read_tcpip(obj, p, p_max_size, IPPROTO_TCP); +} + +void print_read_udp(struct text_object *obj, char *p, int p_max_size) +{ + print_read_tcpip(obj, p, p_max_size, IPPROTO_UDP); +} + +void free_read_tcpip(struct text_object *obj) +{ + struct read_tcpip_data *rtd = (struct read_tcpip_data *) obj->data.opaque; if (!rtd) return; diff --git a/src/read_tcp.h b/src/read_tcpip.h similarity index 92% rename from src/read_tcp.h rename to src/read_tcpip.h index f06ed752..44bcf932 100644 --- a/src/read_tcp.h +++ b/src/read_tcpip.h @@ -31,9 +31,9 @@ #ifndef _READ_TCP_H #define _READ_TCP_H -void parse_read_tcp_arg(struct text_object *, const char *, void *); +void parse_read_tcpip_arg(struct text_object *, const char *, void *); void print_read_tcp(struct text_object *, char *, int); void print_read_udp(struct text_object *, char *, int); -void free_read_tcp(struct text_object *); +void free_read_tcpip(struct text_object *); #endif /* _READ_TCP_H */ From 0ab2efc2b256a021db5641654dc256b55f187813 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sat, 17 Apr 2010 15:19:44 +0200 Subject: [PATCH 31/41] Add support for $no_update --- .gitignore | 1 + doc/variables.xml | 13 +++++++++++++ extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/common.cc | 20 ++++++++++++++++++++ src/common.h | 4 ++++ src/core.cc | 4 ++++ 7 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 888588cf..961d3bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ patches/ doc/conky.1 README build* +doc/*.html diff --git a/doc/variables.xml b/doc/variables.xml index 4b9db61e..9ee8b863 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2460,6 +2460,19 @@ Short hostname (same as 'hostname -s' shell command). + + + + + + + + Shows text and parses the vars in it, but doesn't + update them. Use this for things that do not change while conky + is running, like $machine, $conky_version,... By not updating + this you can save some resources. + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index bfbbd9b6..80af0492 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alignment|append_file|background|border_inner_margin|border_oute color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index ddaf7b49..6564dbe1 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/common.cc b/src/common.cc index d8b9b57b..a548ccac 100644 --- a/src/common.cc +++ b/src/common.cc @@ -30,6 +30,7 @@ #include "config.h" #include "conky.h" +#include "core.h" #include "fs.h" #include "logging.h" #include "net_stat.h" @@ -458,6 +459,25 @@ void print_loadavg(struct text_object *obj, char *p, int p_max_size) } } +void scan_no_update(struct text_object *obj, const char *arg) +{ + struct text_object subroot; + + obj->data.s = (char*) malloc(text_buffer_size); + parse_conky_vars(&subroot, arg, obj->data.s, text_buffer_size); + obj->data.s = (char*) realloc(obj->data.s, strlen(obj->data.s) + 1); + free_text_objects(&subroot); +} + +void free_no_update(struct text_object *obj) { + free(obj->data.s); +} + +void print_no_update(struct text_object *obj, char *p, int p_max_size) +{ + snprintf(p, p_max_size, "%s", obj->data.s); +} + #ifdef BUILD_X11 void scan_loadgraph_arg(struct text_object *obj, const char *arg) { diff --git a/src/common.h b/src/common.h index fe551272..1efb3574 100644 --- a/src/common.h +++ b/src/common.h @@ -88,6 +88,10 @@ int get_battery_perct(const char *bat); double get_battery_perct_bar(struct text_object *); void get_battery_short_status(char *buf, unsigned int n, const char *bat); +void scan_no_update(struct text_object *, const char *); +void print_no_update(struct text_object *, char *, int); +void free_no_update(struct text_object *); + void scan_loadavg_arg(struct text_object *, const char *); void print_loadavg(struct text_object *, char *, int); #ifdef BUILD_X11 diff --git a/src/core.cc b/src/core.cc index 2dd3763e..e2832d26 100644 --- a/src/core.cc +++ b/src/core.cc @@ -580,6 +580,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long obj->callbacks.print = &print_image_callback; obj->callbacks.free = &gen_free_opaque; #endif /* BUILD_IMLIB2 */ + END OBJ_ARG(no_update, 0, "no_update needs arguments") + scan_no_update(obj, arg); + obj->callbacks.print = &print_no_update; + obj->callbacks.free = &free_no_update; END OBJ(exec, 0) scan_exec_arg(obj, arg); obj->parse = false; From 15d9a95c95de72ee150ada4b78ff536c28c714de Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 18 Apr 2010 00:23:00 +0200 Subject: [PATCH 32/41] solve printf warning --- src/linux.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linux.cc b/src/linux.cc index dd7773d1..39ee545d 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -2395,7 +2395,7 @@ void print_distribution(struct text_object *obj, char *p, int p_max_size) if(buf[i-1] == '(' && buf[i] >= 'A' && buf[i] <= 'Z') break; } if(i < bytes_read) { - snprintf(p, p_max_size, &buf[i]); + snprintf(p, p_max_size, "%s", &buf[i]); for(i=1; p[i]; i++) { if(p[i-1] == ' ' && p[i] >= '0' && p[i] <= '9') { p[i-1] = 0; From a6e63bcaa025ca55700f3c9e87dc86884e8eb06d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 18 Apr 2010 17:52:41 +0200 Subject: [PATCH 33/41] Add support for MySQL Warning: Altough the current version works (for me), the syntax of the configoptions and vars will probably change over time. Contact me if you have ideas. The following is a example of how you can use it now: mysql_host someserver.com mysql_db my_database mysql_user loginname mysql_password "s3cr3t" TEXT ${mysql select var1 from some_table}${mysql select var2 from some_table} --- cmake/ConkyBuildOptions.cmake | 2 + cmake/ConkyPlatformChecks.cmake | 13 ++++ cmake/config.h.in | 2 + doc/config_settings.xml | 46 +++++++++++++ doc/variables.xml | 11 ++++ extras/nano/conky.nanorc | 4 +- extras/vim/syntax/conkyrc.vim | 4 +- src/CMakeLists.txt | 5 ++ src/conky.cc | 47 ++++++++++++++ src/conky.h | 4 ++ src/core.cc | 9 +++ src/mysql.cc | 110 ++++++++++++++++++++++++++++++++ src/mysql.h | 48 ++++++++++++++ 13 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 src/mysql.cc create mode 100644 src/mysql.h diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 827bdcee..541f919c 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -126,6 +126,8 @@ option(BUILD_BMPX "Build BMPx (music player) support" false) option(BUILD_MPD "Enable if you want MPD (music player) support" true) +option(BUILD_MYSQL "Enable if you want MySQL support" true) + option(BUILD_MOC "Enable if you want MOC (music player) support" true) option(BUILD_XMMS2 "Enable if you want XMMS2 (music player) support" false) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index e33284ad..e66f0c49 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -80,6 +80,19 @@ if(BUILD_NCURSES) set(conky_libs ${conky_libs} ${NCURSES_LIB}) endif(BUILD_NCURSES) +if(BUILD_MYSQL) + find_path(mysql_INCLUDE_PATH mysql.h ${INCLUDE_SEARCH_PATH}) + if(NOT mysql_INCLUDE_PATH) + message(FATAL_ERROR "Unable to find mysql.h") + endif(NOT mysql_INCLUDE_PATH) + set(conky_includes ${conky_includes} ${mysql_INCLUDE_PATH}) + find_library(MYSQLCLIENT_LIB NAMES mysqlclient) + if(NOT MYSQLCLIENT_LIB) + message(FATAL_ERROR "Unable to find mysqlclient library") + endif(NOT MYSQLCLIENT_LIB) + set(conky_libs ${conky_libs} ${MYSQLCLIENT_LIB}) +endif(BUILD_MYSQL) + if(BUILD_WLAN) check_include_file(iwlib.h IWLIB_H -D_GNU_SOURCE) if(NOT IWLIB_H) diff --git a/cmake/config.h.in b/cmake/config.h.in index f7b7dc17..3644a99d 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -51,6 +51,8 @@ #cmakedefine BUILD_MPD 1 +#cmakedefine BUILD_MYSQL 1 + #cmakedefine BUILD_MOC 1 #cmakedefine BUILD_NVIDIA 0 diff --git a/doc/config_settings.xml b/doc/config_settings.xml index 2f174ba7..efdd30ab 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -524,6 +524,52 @@ Port of MPD server + + + + + + + Host of MySQL server. Defaults to localhost + + + + + + + + + Port of MySQL server. Defaults to the default mysql port + + + + + + + + + MySQL user name to use when connecting to the server. Defaults to your username + + + + + + + + + Password of the MySQL user. Place it between "-chars. When this is not set there + is no password used + + + + + + + + + MySQL database to use. Defaults to mysql + + diff --git a/doc/variables.xml b/doc/variables.xml index 9ee8b863..f1d505a6 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2418,6 +2418,17 @@ MPD's volume + + + + + + + + Shows the first field of the first row of the + result of the query. + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 80af0492..3e7a9a96 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -5,13 +5,13 @@ syntax "conky" "(\.*conkyrc.*$|conky.conf)" ## Configuration items -color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_text_width|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" +color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|lua_startup_hook|mail_spool|max_port_monitor_connections|max_text_width|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|mysql_host|mysql_port|mysql_user|mysql_password|mysql_db|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|times_in_seconds|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" ## Configuration item constants color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|mysql|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index 6564dbe1..ad351ae2 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -12,7 +12,7 @@ endif syn region ConkyrcComment start=/^\s*#/ end=/$/ -syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook lua_startup_hook mail_spool max_port_monitor_connections max_text_width max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size times_in_seconds top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont +syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook lua_startup_hook mail_spool max_port_monitor_connections max_text_width max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval mysql_host mysql_port mysql_user mysql_password mysql_db net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size times_in_seconds top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont syn keyword ConkyrcConstant \ above @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol mysql nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8154e1fa..1dc8f00c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -93,6 +93,11 @@ if(BUILD_MPD) set(optional_sources ${optional_sources} ${mpd}) endif(BUILD_MPD) +if(BUILD_MYSQL) + set(mysql mysql.cc) + set(optional_sources ${optional_sources} ${mysql}) +endif(BUILD_MYSQL) + if(BUILD_MOC) set(moc moc.cc) set(optional_sources ${optional_sources} ${moc}) diff --git a/src/conky.cc b/src/conky.cc index 4d0ea749..0f786938 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -99,6 +99,9 @@ #include "template.h" #include "timeinfo.h" #include "top.h" +#ifdef BUILD_MYSQL +#include "mysql.h" +#endif /* BUILD_MYSQL */ /* check for OS and include appropriate headers */ #if defined(__linux__) @@ -2627,6 +2630,13 @@ static void set_default_configurations(void) mpd_set_port("6600"); } #endif /* BUILD_MPD */ +#ifdef BUILD_MYSQL + mysql_settings.host = NULL; + mysql_settings.port = 0; + mysql_settings.user = NULL; + mysql_settings.password = NULL; + mysql_settings.db = strdup("mysql"); +#endif /* BUILD_MYSQL */ #ifdef BUILD_XMMS2 info.xmms2.artist = NULL; info.xmms2.album = NULL; @@ -3094,6 +3104,43 @@ char load_config_file(const char *f) } } #endif /* BUILD_MPD */ +#ifdef BUILD_MYSQL + CONF("mysql_host") { + if (value) { + mysql_set_host(value); + } else { + CONF_ERR; + } + } + CONF("mysql_port") { + if (value) { + mysql_set_port(value); + } else { + CONF_ERR; + } + } + CONF("mysql_user") { + if (value) { + mysql_set_user(value); + } else { + CONF_ERR; + } + } + CONF("mysql_password") { + if (value) { + mysql_set_password(value); + } else { + CONF_ERR; + } + } + CONF("mysql_db") { + if (value) { + mysql_set_db(value); + } else { + CONF_ERR; + } + } +#endif /* BUILD_MYSQL */ CONF("music_player_interval") { if (value) { info.music_player_interval = strtod(value, 0); diff --git a/src/conky.h b/src/conky.h index 331775df..2be10e7d 100644 --- a/src/conky.h +++ b/src/conky.h @@ -86,6 +86,10 @@ struct text_object; #include "mpd.h" #endif /* BUILD_MPD */ +#ifdef BUILD_MYSQL +#include "mysql.h" +#endif /* BUILD_MYSQL */ + /* C++ headers */ #ifdef BUILD_CURL #include "ccurl_thread.h" diff --git a/src/core.cc b/src/core.cc index e2832d26..c24b1b47 100644 --- a/src/core.cc +++ b/src/core.cc @@ -42,6 +42,9 @@ #include "i8k.h" #include "imlib2.h" #include "proc.h" +#ifdef BUILD_MYSQL +#include "mysql.h" +#endif #ifdef BUILD_X11 #include "fonts.h" #endif @@ -580,6 +583,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long obj->callbacks.print = &print_image_callback; obj->callbacks.free = &gen_free_opaque; #endif /* BUILD_IMLIB2 */ +#ifdef BUILD_MYSQL + END OBJ_ARG(mysql, 0, "mysql needs a query") + obj->data.s = strdup(arg); + obj->callbacks.print = &print_mysql; + obj->callbacks.free = &free_mysql; +#endif /* BUILD_MYSQL */ END OBJ_ARG(no_update, 0, "no_update needs arguments") scan_no_update(obj, arg); obj->callbacks.print = &print_no_update; diff --git a/src/mysql.cc b/src/mysql.cc new file mode 100644 index 00000000..983dc4eb --- /dev/null +++ b/src/mysql.cc @@ -0,0 +1,110 @@ +/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=cpp + * + * Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "conky.h" +#include "logging.h" +#include + +struct mysql_conn mysql_settings; + +void print_mysql(struct text_object *obj, char *p, int p_max_size) { + MYSQL *conn = mysql_init(NULL); + + if(conn == NULL) { + NORM_ERR("Can't initialize MySQL"); + mysql_library_end(); + return; + } + if (!mysql_real_connect(conn, mysql_settings.host, mysql_settings.user, mysql_settings.password, mysql_settings.db, mysql_settings.port, NULL, 0)) { + NORM_ERR("MySQL: %s", mysql_error(conn)); + mysql_close(conn); + mysql_library_end(); + return; + } + if(mysql_query(conn, obj->data.s)) { + NORM_ERR("MySQL: %s", mysql_error(conn)); + mysql_close(conn); + mysql_library_end(); + return; + } + MYSQL_RES *res = mysql_use_result(conn); + if(res == NULL) { + NORM_ERR("MySQL: %s", mysql_error(conn)); + mysql_close(conn); + mysql_library_end(); + return; + } + MYSQL_ROW row = mysql_fetch_row(res); + if(row) { + snprintf(p, p_max_size, "%s", row[0]); + } else { + NORM_ERR("MySQL: '%s' returned no results", obj->data.s); + } + mysql_free_result(res); + mysql_close(conn); + mysql_library_end(); +} + +void free_mysql(struct text_object *obj) { + free(mysql_settings.host); + free(mysql_settings.user); + if(mysql_settings.password) free(mysql_settings.password); + free(mysql_settings.db); + free(obj->data.s); +} + +void mysql_set_host(const char *host) { + free(mysql_settings.host); + mysql_settings.host = strdup(host); +} + +void mysql_set_port(const char *port) { + mysql_settings.port = strtol(port, 0, 0); + if(mysql_settings.port < 1 || mysql_settings.port > 0xffff) + mysql_settings.port = 0; +} + +void mysql_set_user(const char *user) { + free(mysql_settings.user); + mysql_settings.user = strdup(user); +} + +void mysql_set_password(const char *password) { + free_and_zero(mysql_settings.password); + if(password && strlen(password) > 2 && password[0] == '"' && password[strlen(password)-1] == '"') { + mysql_settings.password = strdup(password+1); + mysql_settings.password[strlen(password)-2] = 0; + } else + mysql_settings.password = NULL; +} + +void mysql_set_db(const char *db) { + free(mysql_settings.db); + mysql_settings.db = strdup(db); +} diff --git a/src/mysql.h b/src/mysql.h new file mode 100644 index 00000000..14b06ed7 --- /dev/null +++ b/src/mysql.h @@ -0,0 +1,48 @@ +/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=cpp + * + * Conky, a system monitor, based on torsmo + * + * Please see COPYING for details + * + * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef MYSQL_H_ +#define MYSQL_H_ + +struct mysql_conn { + char *host; + int port; + char *user; + char *password; + char *db; +}; + +extern struct mysql_conn mysql_settings; + +void mysql_set_host(const char *); +void mysql_set_port(const char *); +void mysql_set_user(const char *); +void mysql_set_password(const char *); +void mysql_set_db(const char *); + +void print_mysql(struct text_object *, char *, int); +void free_mysql(struct text_object *); + +#endif /*MYSQL_H_*/ From 7065ba251e584f4dd77ac632f652811e26757835 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 18 Apr 2010 20:30:10 +0200 Subject: [PATCH 34/41] Make it possible for cmake to find mysql.h --- cmake/ConkyPlatformChecks.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index e66f0c49..1341e015 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -81,7 +81,7 @@ if(BUILD_NCURSES) endif(BUILD_NCURSES) if(BUILD_MYSQL) - find_path(mysql_INCLUDE_PATH mysql.h ${INCLUDE_SEARCH_PATH}) + find_path(mysql_INCLUDE_PATH mysql.h ${INCLUDE_SEARCH_PATH} /usr/include/mysql /usr/local/include/mysql) if(NOT mysql_INCLUDE_PATH) message(FATAL_ERROR "Unable to find mysql.h") endif(NOT mysql_INCLUDE_PATH) From d9930744dec809dc7a19a4649a1b09e478361b2e Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 18 Apr 2010 20:49:14 +0200 Subject: [PATCH 35/41] fix memleak --- src/conky.cc | 2 +- src/mysql.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/conky.cc b/src/conky.cc index 0f786938..faf3624a 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2635,7 +2635,7 @@ static void set_default_configurations(void) mysql_settings.port = 0; mysql_settings.user = NULL; mysql_settings.password = NULL; - mysql_settings.db = strdup("mysql"); + mysql_settings.db = NULL; #endif /* BUILD_MYSQL */ #ifdef BUILD_XMMS2 info.xmms2.artist = NULL; diff --git a/src/mysql.cc b/src/mysql.cc index 983dc4eb..98100447 100644 --- a/src/mysql.cc +++ b/src/mysql.cc @@ -36,6 +36,8 @@ struct mysql_conn mysql_settings; void print_mysql(struct text_object *obj, char *p, int p_max_size) { MYSQL *conn = mysql_init(NULL); + if(mysql_settings.db == NULL) + mysql_settings.db = strdup("mysql"); if(conn == NULL) { NORM_ERR("Can't initialize MySQL"); mysql_library_end(); From d6537aa6787b9bbed78bf37d7db0a0babd3cd6d5 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 19 Apr 2010 14:45:05 +0200 Subject: [PATCH 36/41] Add support for $stock --- doc/variables.xml | 11 +++++++++++ extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/common.cc | 14 ++++++++++++++ src/common.h | 2 ++ src/core.cc | 27 +++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index f1d505a6..c7ac6ffe 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -3273,6 +3273,17 @@ Stippled (dashed) horizontal line + + + + + + + + Displays the data of a stock symbol. The following data + is supported: adv(Average Daily Volume),ask,asksize,bid + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 3e7a9a96..9ffca656 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alignment|append_file|background|border_inner_margin|border_oute color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|mysql|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|mysql|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|stock|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index ad351ae2..27f7c3f0 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol mysql nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol mysql nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr stock swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/common.cc b/src/common.cc index a548ccac..1cdb8d4f 100644 --- a/src/common.cc +++ b/src/common.cc @@ -819,6 +819,20 @@ void print_include(struct text_object *obj, char *p, int p_max_size) snprintf(p, p_max_size, "%s", &(buf[0])); } +void print_stock(struct text_object *obj, char *p, int p_max_size) +{ + if( ! obj->data.s) { + p[0] = 0; + return; + } + ccurl_process_info(p, p_max_size, obj->data.s, 0); +} + +void free_stock(struct text_object *obj) +{ + free(obj->data.s); +} + void print_to_bytes(struct text_object *obj, char *p, int p_max_size) { std::vector buf(max_user_text); diff --git a/src/common.h b/src/common.h index 1efb3574..790a7560 100644 --- a/src/common.h +++ b/src/common.h @@ -162,4 +162,6 @@ void print_include(struct text_object *, char *, int); void print_updates(struct text_object *, char *, int); int updatenr_iftest(struct text_object *); +void print_stock(struct text_object *, char *, int); +void free_stock(struct text_object *); #endif /* _COMMON_H */ diff --git a/src/core.cc b/src/core.cc index c24b1b47..722abaaa 100644 --- a/src/core.cc +++ b/src/core.cc @@ -138,6 +138,29 @@ static struct text_object *create_plain_text(const char *s) return obj; } +void stock_parse_arg(struct text_object *obj, const char *arg) +{ + char stock[8]; + char data[8]; + + obj->data.s = NULL; + if(sscanf(arg, "%7s %7s", stock, data) != 2) { + NORM_ERR("wrong number of arguments for $stock"); + return; + } + if(!strcasecmp("ask", data)) strcpy(data, "a"); + else if(!strcasecmp("adv", data)) strcpy(data, "a2"); + else if(!strcasecmp("asksize", data)) strcpy(data, "a5"); + else if(!strcasecmp("bid", data)) strcpy(data, "b"); + else { + NORM_ERR("\"%s\" is not supported by $stock. Supported: adv,ask,asksize,bid", data); + return; + } +#define MAX_FINYAH_URL_LENGTH 64 + obj->data.s = (char*) malloc(MAX_FINYAH_URL_LENGTH); + snprintf(obj->data.s, MAX_FINYAH_URL_LENGTH, "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=%s", stock, data); +} + /* construct_text_object() creates a new text_object */ struct text_object *construct_text_object(char *s, const char *arg, long line, void **ifblock_opaque, void *free_at_crash) @@ -1583,6 +1606,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long obj->sub = (text_object*)malloc(sizeof(struct text_object)); extract_variable_text_internal(obj->sub, arg); obj->callbacks.print = &print_to_bytes; + END OBJ_ARG(stock, 0, "stock needs arguments") + stock_parse_arg(obj, arg); + obj->callbacks.print = &print_stock; + obj->callbacks.free = &free_stock; END OBJ(scroll, 0) #ifdef BUILD_X11 /* allocate a follower to reset any color changes */ From 89c2d4ecdd45c090a06ede0ad198fea3316669a8 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 19 Apr 2010 14:54:03 +0200 Subject: [PATCH 37/41] curl --- src/common.cc | 2 ++ src/common.h | 2 ++ src/core.cc | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/common.cc b/src/common.cc index 1cdb8d4f..5a184748 100644 --- a/src/common.cc +++ b/src/common.cc @@ -819,6 +819,7 @@ void print_include(struct text_object *obj, char *p, int p_max_size) snprintf(p, p_max_size, "%s", &(buf[0])); } +#ifdef BUILD_CURL void print_stock(struct text_object *obj, char *p, int p_max_size) { if( ! obj->data.s) { @@ -832,6 +833,7 @@ void free_stock(struct text_object *obj) { free(obj->data.s); } +#endif /* BUILD_CURL */ void print_to_bytes(struct text_object *obj, char *p, int p_max_size) { diff --git a/src/common.h b/src/common.h index 790a7560..d543a3c2 100644 --- a/src/common.h +++ b/src/common.h @@ -162,6 +162,8 @@ void print_include(struct text_object *, char *, int); void print_updates(struct text_object *, char *, int); int updatenr_iftest(struct text_object *); +#ifdef BUILD_CURL void print_stock(struct text_object *, char *, int); void free_stock(struct text_object *); +#endif /* BUILD_CURL */ #endif /* _COMMON_H */ diff --git a/src/core.cc b/src/core.cc index 722abaaa..34d7f77b 100644 --- a/src/core.cc +++ b/src/core.cc @@ -138,6 +138,7 @@ static struct text_object *create_plain_text(const char *s) return obj; } +#ifdef BUILD_CURL void stock_parse_arg(struct text_object *obj, const char *arg) { char stock[8]; @@ -160,6 +161,7 @@ void stock_parse_arg(struct text_object *obj, const char *arg) obj->data.s = (char*) malloc(MAX_FINYAH_URL_LENGTH); snprintf(obj->data.s, MAX_FINYAH_URL_LENGTH, "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=%s", stock, data); } +#endif /* BUILD_CURL */ /* construct_text_object() creates a new text_object */ struct text_object *construct_text_object(char *s, const char *arg, long @@ -1606,10 +1608,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long obj->sub = (text_object*)malloc(sizeof(struct text_object)); extract_variable_text_internal(obj->sub, arg); obj->callbacks.print = &print_to_bytes; +#ifdef BUILD_CURL END OBJ_ARG(stock, 0, "stock needs arguments") stock_parse_arg(obj, arg); obj->callbacks.print = &print_stock; obj->callbacks.free = &free_stock; +#endif /* BUILD_CURL */ END OBJ(scroll, 0) #ifdef BUILD_X11 /* allocate a follower to reset any color changes */ From bc5a414594716310d5d814c7d08d347fff45b7f2 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 19 Apr 2010 17:19:56 +0200 Subject: [PATCH 38/41] $curl can now use 0 (immediately) as interval --- doc/variables.xml | 4 ++-- src/ccurl_thread.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index c7ac6ffe..96b8b4e6 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -675,8 +675,8 @@ Download data from URI using Curl at the - specified interval. The interval may be a floating - point value greater than 0, otherwise defaults to 15 + specified interval. The interval may be a positive floating + point value (0 is allowed), otherwise defaults to 15 minutes. Most useful when used in conjunction with Lua and the Lua API. This object is threaded, and once a thread is created it can't be explicitly destroyed. diff --git a/src/ccurl_thread.cc b/src/ccurl_thread.cc index 82401dde..fdd0f14b 100644 --- a/src/ccurl_thread.cc +++ b/src/ccurl_thread.cc @@ -222,7 +222,7 @@ void curl_parse_arg(struct text_object *obj, const char *arg) NORM_ERR("wrong number of arguments for $curl"); return; } - cd->interval = interval > 0 ? interval * 60 : 15*60; + cd->interval = (argc == 2 && interval >= 0) ? interval * 60 : 15*60; obj->data.opaque = cd; } From 93de6a179832bdae592d6b225a0dca8a09a5ed0d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 19 Apr 2010 22:25:50 +0200 Subject: [PATCH 39/41] Fix bug in previous commit and a old memleak in curl --- src/ccurl_thread.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ccurl_thread.cc b/src/ccurl_thread.cc index fdd0f14b..8ed04e99 100644 --- a/src/ccurl_thread.cc +++ b/src/ccurl_thread.cc @@ -72,6 +72,7 @@ void ccurl_free_locations(ccurl_location_list &locations) i != locations.end(); i++) { free_and_zero((*i)->uri); free_and_zero((*i)->result); + (*i)->p_timed_thread.reset(); } locations.clear(); } @@ -222,7 +223,10 @@ void curl_parse_arg(struct text_object *obj, const char *arg) NORM_ERR("wrong number of arguments for $curl"); return; } - cd->interval = (argc == 2 && interval >= 0) ? interval * 60 : 15*60; + if (argc == 1) + cd->interval = 15*60; + else + cd->interval = interval > 0 ? interval * 60 : update_interval; obj->data.opaque = cd; } From f603fbfd88e27b8e681b95f0f36536cb3c8d5fc1 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 21 Apr 2010 14:54:45 +0200 Subject: [PATCH 40/41] change specials back into a normal array until i fix the only-1-line-graph-bug --- src/conky.cc | 207 ++++++++++++++++++++++++------------------------ src/specials.cc | 27 +++---- src/specials.h | 7 +- 3 files changed, 121 insertions(+), 120 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index faf3624a..b2e73afa 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -815,6 +815,8 @@ static void generate_text(void) char *p; unsigned int i, j, k; + special_count = 0; + /* update info */ current_update_time = get_time(); @@ -880,7 +882,7 @@ int get_string_width(const char *s) static int get_string_width_special(char *s, int special_index) { char *p, *final; - special_t *current = specials; + int idx = 1; int width = 0; long i; @@ -893,9 +895,6 @@ static int get_string_width_special(char *s, int special_index) p = strndup(s, text_buffer_size); final = p; - for(i = 0; i <= special_index; i++) - current = current->next; - while (*p) { if (*p == SPECIAL_CHAR) { /* shift everything over by 1 so that the special char @@ -903,12 +902,12 @@ static int get_string_width_special(char *s, int special_index) for (i = 0; i < (long)strlen(p); i++) { *(p + i) = *(p + i + 1); } - if (current->type == GRAPH - || current->type == GAUGE - || current->type == BAR) { - width += current->width; + if (specials[special_index + idx].type == GRAPH + || specials[special_index + idx].type == GAUGE + || specials[special_index + idx].type == BAR) { + width += specials[special_index + idx].width; } - current = current->next; + idx++; } else if (*p == SECRIT_MULTILINE_CHAR) { *p = 0; break; @@ -1032,10 +1031,6 @@ static int text_size_updater(char *s, int special_index) int lw; int contain_SECRIT_MULTILINE_CHAR = 0; char *p; - special_t *current = specials; - - for(int i = 0; i < special_index; i++) - current = current->next; if ((output_methods & TO_X) == 0) return 0; @@ -1047,41 +1042,40 @@ static int text_size_updater(char *s, int special_index) w += get_string_width(s); *p = SPECIAL_CHAR; - if (current->type == BAR - || current->type == GAUGE - || current->type == GRAPH) { - w += current->width; - if (current->height > last_font_height) { - last_font_height = current->height; + if (specials[special_index].type == BAR + || specials[special_index].type == GAUGE + || specials[special_index].type == GRAPH) { + w += specials[special_index].width; + if (specials[special_index].height > last_font_height) { + last_font_height = specials[special_index].height; last_font_height += font_height(); } - } else if (current->type == OFFSET) { - if (current->arg > 0) { - w += current->arg; + } else if (specials[special_index].type == OFFSET) { + if (specials[special_index].arg > 0) { + w += specials[special_index].arg; } - } else if (current->type == VOFFSET) { - last_font_height += current->arg; - } else if (current->type == GOTO) { - if (current->arg > cur_x) { - w = (int) current->arg; + } else if (specials[special_index].type == VOFFSET) { + last_font_height += specials[special_index].arg; + } else if (specials[special_index].type == GOTO) { + if (specials[special_index].arg > cur_x) { + w = (int) specials[special_index].arg; } - } else if (current->type == TAB) { - int start = current->arg; - int step = current->width; + } else if (specials[special_index].type == TAB) { + int start = specials[special_index].arg; + int step = specials[special_index].width; if (!step || step < 0) { step = 10; } w += step - (cur_x - text_start_x - start) % step; - } else if (current->type == FONT) { - selected_font = current->font_added; + } else if (specials[special_index].type == FONT) { + selected_font = specials[special_index].font_added; if (font_height() > last_font_height) { last_font_height = font_height(); } } special_index++; - current = current->next; s = p + 1; } else if (*p == SECRIT_MULTILINE_CHAR) { contain_SECRIT_MULTILINE_CHAR = 1; @@ -1297,14 +1291,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) s = p + 1; } /* draw special */ - special_t *current = specials; - for(int i = 0; i < special_index; i++) - current = current->next; - switch (current->type) { + switch (specials[special_index].type) { #ifdef BUILD_X11 case HORIZONTAL_LINE: { - int h = current->height; + int h = specials[special_index].height; int mid = font_ascent() / 2; w = text_start_x + text_width - cur_x; @@ -1318,8 +1309,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) case STIPPLED_HR: { - int h = current->height; - char tmp_s = current->arg; + int h = specials[special_index].height; + char tmp_s = specials[special_index].arg; int mid = font_ascent() / 2; char ss[2] = { tmp_s, tmp_s }; @@ -1340,15 +1331,15 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) && maximum_width > 0) { break; } - h = current->height; - bar_usage = current->arg; - scale = current->scale; + h = specials[special_index].height; + bar_usage = specials[special_index].arg; + scale = specials[special_index].scale; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = current->width; + w = specials[special_index].width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1384,13 +1375,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) break; } - h = current->height; + h = specials[special_index].height; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = current->width; + w = specials[special_index].width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1405,8 +1396,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_x, by, w, h * 2, 0, 180*64); #ifdef MATH - usage = current->arg; - scale = current->scale; + usage = specials[special_index].arg; + scale = specials[special_index].scale; angle = M_PI * usage / scale; px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle); py = (float)(by+(h))-(float)(h)*sin(angle); @@ -1436,13 +1427,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) && maximum_width > 0) { break; } - h = current->height; + h = specials[special_index].height; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = current->width; + w = specials[special_index].width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1458,37 +1449,37 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); - if (current->last_colour != 0 - || current->first_colour != 0) { - tmpcolour = do_gradient(w - 1, current->last_colour, current->first_colour); + if (specials[special_index].last_colour != 0 + || specials[special_index].first_colour != 0) { + tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour); } colour_idx = 0; for (i = w - 2; i > -1; i--) { - if (current->last_colour != 0 - || current->first_colour != 0) { - if (current->tempgrad) { + if (specials[special_index].last_colour != 0 + || specials[special_index].first_colour != 0) { + if (specials[special_index].tempgrad) { #ifdef DEBUG_lol assert( - (int)((float)(w - 2) - current->graph[j] * - (w - 2) / (float)current->scale) + (int)((float)(w - 2) - specials[special_index].graph[j] * + (w - 2) / (float)specials[special_index].scale) < w - 1 ); assert( - (int)((float)(w - 2) - current->graph[j] * - (w - 2) / (float)current->scale) + (int)((float)(w - 2) - specials[special_index].graph[j] * + (w - 2) / (float)specials[special_index].scale) > -1 ); - if (current->graph[j] == current->scale) { + if (specials[special_index].graph[j] == specials[special_index].scale) { assert( - (int)((float)(w - 2) - current->graph[j] * - (w - 2) / (float)current->scale) + (int)((float)(w - 2) - specials[special_index].graph[j] * + (w - 2) / (float)specials[special_index].scale) == 0 ); } #endif /* DEBUG_lol */ XSetForeground(display, window.gc, tmpcolour[ - (int)((float)(w - 2) - current->graph[j] * - (w - 2) / (float)current->scale) + (int)((float)(w - 2) - specials[special_index].graph[j] * + (w - 2) / (float)specials[special_index].scale) ]); } else { XSetForeground(display, window.gc, tmpcolour[colour_idx++]); @@ -1497,10 +1488,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* this is mugfugly, but it works */ XDrawLine(display, window.drawable, window.gc, cur_x + i + 1, by + h, cur_x + i + 1, - round_to_int((double)by + h - current->graph[j] * - (h - 1) / current->scale)); + round_to_int((double)by + h - specials[special_index].graph[j] * + (h - 1) / specials[special_index].scale)); if ((w - i) / ((float) (w - 2) / - (current->graph_width)) > j + (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) { j++; } @@ -1561,16 +1552,16 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_y = tmp_y; } #ifdef MATH - if (show_graph_scale && (current->show_scale == 1)) { + if (show_graph_scale && (specials[special_index].show_scale == 1)) { int tmp_x = cur_x; int tmp_y = cur_y; char *tmp_str; cur_x += font_ascent() / 2; cur_y += font_h / 2; tmp_str = (char *) - calloc(log10(floor(current->scale)) + 4, + calloc(log10(floor(specials[special_index].scale)) + 4, sizeof(char)); - sprintf(tmp_str, "%.1f", current->scale); + sprintf(tmp_str, "%.1f", specials[special_index].scale); draw_string(tmp_str); free(tmp_str); cur_x = tmp_x; @@ -1586,7 +1577,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) int old = font_ascent(); cur_y -= font_ascent(); - selected_font = current->font_added; + selected_font = specials[special_index].font_added; set_font(); if (cur_y + font_ascent() < cur_y + old) { cur_y += old; @@ -1599,43 +1590,43 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) #endif /* BUILD_X11 */ case FG: if (draw_mode == FG) { - set_foreground_color(current->arg); + set_foreground_color(specials[special_index].arg); } break; #ifdef BUILD_X11 case BG: if (draw_mode == BG) { - set_foreground_color(current->arg); + set_foreground_color(specials[special_index].arg); } break; case OUTLINE: if (draw_mode == OUTLINE) { - set_foreground_color(current->arg); + set_foreground_color(specials[special_index].arg); } break; case OFFSET: - w += current->arg; + w += specials[special_index].arg; last_special_needed = special_index; break; case VOFFSET: - cur_y += current->arg; + cur_y += specials[special_index].arg; break; case GOTO: - if (current->arg >= 0) { - cur_x = (int) current->arg; + if (specials[special_index].arg >= 0) { + cur_x = (int) specials[special_index].arg; } last_special_needed = special_index; break; case TAB: { - int start = current->arg; - int step = current->width; + int start = specials[special_index].arg; + int step = specials[special_index].width; if (!step || step < 0) { step = 10; @@ -1654,13 +1645,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* printf("pos_x %i text_start_x %i text_width %i cur_x %i " "get_string_width(p) %i gap_x %i " - "current->arg %i window.border_inner_margin %i " + "specials[special_index].arg %i window.border_inner_margin %i " "window.border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, - current->arg, window.border_inner_margin, + specials[special_index].arg, window.border_inner_margin, window.border_width); */ - if (pos_x > current->arg && pos_x > cur_x) { - cur_x = pos_x - current->arg; + if (pos_x > specials[special_index].arg && pos_x > cur_x) { + cur_x = pos_x - specials[special_index].arg; } last_special_needed = special_index; break; @@ -1676,11 +1667,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* printf("pos_x %i text_start_x %i text_width %i cur_x %i " "get_string_width(p) %i gap_x %i " - "current->arg %i\n", pos_x, text_start_x, + "specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, - current->arg); */ - if (pos_x > current->arg) { - w = pos_x - current->arg; + specials[special_index].arg); */ + if (pos_x > specials[special_index].arg) { + w = pos_x - specials[special_index].arg; } last_special_needed = special_index; break; @@ -2383,18 +2374,6 @@ static void reload_config(void) initialisation(argc_copy, argv_copy); } -void free_specials(special_t *current) { - if(current) { - free_specials(current->next); - if (current->type == GRAPH) - free(current->graph); - delete current; - } else { - specials = NULL; - last_specials = NULL; - } -} - #ifdef BUILD_X11 void clean_up_x11() { if(window_created == 1) { @@ -2422,6 +2401,8 @@ void clean_up_x11() { void clean_up(void *memtofree1, void* memtofree2) { + int i; + free_update_callbacks(); #ifdef BUILD_NCURSES @@ -2444,7 +2425,7 @@ void clean_up(void *memtofree1, void* memtofree2) font_count = -1; } -#endif +#endif /* BUILD_X11 */ free_templates(); @@ -2487,7 +2468,15 @@ void clean_up(void *memtofree1, void* memtofree2) xmlCleanupParser(); #endif /* BUILD_WEATHER_XOAP */ - free_specials(specials); + if (specials) { + for (i = 0; i < special_count; i++) { + if (specials[i].type == GRAPH) { + free(specials[i].graph); + } + } + free_and_zero(specials); + } + clear_net_stats(); clear_diskio_stats(); free_and_zero(global_cpu); @@ -3546,6 +3535,13 @@ char load_config_file(const char *f) CONF("uppercase") { stuff_in_uppercase = string_to_bool(value); } + CONF("max_specials") { + if (value) { + max_specials = atoi(value); + } else { + CONF_ERR; + } + } CONF("max_user_text") { if (value) { max_user_text = atoi(value); @@ -4095,6 +4091,11 @@ void initialisation(int argc, char **argv) { currentconffile = conftree_add(currentconffile, current_config.c_str()); } + /* init specials array */ + if ((specials = (special_t*)calloc(sizeof(struct special_t), max_specials)) == 0) { + NORM_ERR("failed to create specials array"); + } + #ifdef MAIL_FILE if (current_mail_spool == NULL) { char buf[256]; diff --git a/src/specials.cc b/src/specials.cc index f7575ad1..e60c26b7 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -40,8 +40,14 @@ #endif /* HAVE_SYS_PARAM_H */ #include +/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */ +int max_specials = 512; + +/* create specials array on heap instead of stack with introduction of + * max_specials */ struct special_t *specials = NULL; -struct special_t *last_specials = NULL; + +int special_count; int default_bar_width = 0, default_bar_height = 6; #ifdef BUILD_X11 @@ -247,21 +253,14 @@ char *scan_graph(struct text_object *obj, const char *args, double defscale) struct special_t *new_special(char *buf, enum special_types t) { + if (special_count >= max_specials) { + CRIT_ERR(NULL, NULL, "too many special things in text"); + } + buf[0] = SPECIAL_CHAR; buf[1] = '\0'; - if(specials) { - last_specials->next = new special_t; - last_specials->next->prev = last_specials; - last_specials = last_specials->next; - } else { - specials = new special_t; - specials->prev = NULL; - last_specials = specials; - } - last_specials->graph = NULL; - last_specials->next = NULL; - last_specials->type = t; - return last_specials; + specials[special_count].type = t; + return &specials[special_count++]; } void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, double usage) diff --git a/src/specials.h b/src/specials.h index 535e250b..a3d9783f 100644 --- a/src/specials.h +++ b/src/specials.h @@ -73,13 +73,11 @@ struct special_t { unsigned long last_colour; short font_added; char tempgrad; - struct special_t *next; - struct special_t *prev; }; /* direct access to the registered specials (FIXME: bad encapsulation) */ extern struct special_t *specials; -extern struct special_t *last_specials; +extern int special_count; extern int default_bar_width; extern int default_bar_height; @@ -93,6 +91,9 @@ extern int default_gauge_height; /* forward declare to avoid mutual inclusion between specials.h and text_object.h */ struct text_object; +/* max number of specials allowed (TODO: use linked list instead) */ +extern int max_specials; + /* scanning special arguments */ const char *scan_bar(struct text_object *, const char *, double); const char *scan_gauge(struct text_object *, const char *, double); From 2f838fe6768e0976930a6142d16edcd221a77536 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 21 Apr 2010 18:03:53 +0200 Subject: [PATCH 41/41] change specials back to ll (fixed bug mentioned in previous commit) --- src/conky.cc | 200 ++++++++++++++++++++++++------------------------ src/specials.cc | 31 +++++--- src/specials.h | 4 +- 3 files changed, 124 insertions(+), 111 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index b2e73afa..420c8d54 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -882,6 +882,7 @@ int get_string_width(const char *s) static int get_string_width_special(char *s, int special_index) { char *p, *final; + special_t *current = specials; int idx = 1; int width = 0; long i; @@ -895,6 +896,11 @@ static int get_string_width_special(char *s, int special_index) p = strndup(s, text_buffer_size); final = p; + for(i = 0; i < special_index; i++) + current = current->next; + for(i = 0; i < idx; i++) + current = current->next; + while (*p) { if (*p == SPECIAL_CHAR) { /* shift everything over by 1 so that the special char @@ -902,12 +908,13 @@ static int get_string_width_special(char *s, int special_index) for (i = 0; i < (long)strlen(p); i++) { *(p + i) = *(p + i + 1); } - if (specials[special_index + idx].type == GRAPH - || specials[special_index + idx].type == GAUGE - || specials[special_index + idx].type == BAR) { - width += specials[special_index + idx].width; + if (current->type == GRAPH + || current->type == GAUGE + || current->type == BAR) { + width += current->width; } idx++; + current = current->next; } else if (*p == SECRIT_MULTILINE_CHAR) { *p = 0; break; @@ -1031,6 +1038,10 @@ static int text_size_updater(char *s, int special_index) int lw; int contain_SECRIT_MULTILINE_CHAR = 0; char *p; + special_t *current = specials; + + for(int i = 0; i < special_index; i++) + current = current->next; if ((output_methods & TO_X) == 0) return 0; @@ -1042,40 +1053,41 @@ static int text_size_updater(char *s, int special_index) w += get_string_width(s); *p = SPECIAL_CHAR; - if (specials[special_index].type == BAR - || specials[special_index].type == GAUGE - || specials[special_index].type == GRAPH) { - w += specials[special_index].width; - if (specials[special_index].height > last_font_height) { - last_font_height = specials[special_index].height; + if (current->type == BAR + || current->type == GAUGE + || current->type == GRAPH) { + w += current->width; + if (current->height > last_font_height) { + last_font_height = current->height; last_font_height += font_height(); } - } else if (specials[special_index].type == OFFSET) { - if (specials[special_index].arg > 0) { - w += specials[special_index].arg; + } else if (current->type == OFFSET) { + if (current->arg > 0) { + w += current->arg; } - } else if (specials[special_index].type == VOFFSET) { - last_font_height += specials[special_index].arg; - } else if (specials[special_index].type == GOTO) { - if (specials[special_index].arg > cur_x) { - w = (int) specials[special_index].arg; + } else if (current->type == VOFFSET) { + last_font_height += current->arg; + } else if (current->type == GOTO) { + if (current->arg > cur_x) { + w = (int) current->arg; } - } else if (specials[special_index].type == TAB) { - int start = specials[special_index].arg; - int step = specials[special_index].width; + } else if (current->type == TAB) { + int start = current->arg; + int step = current->width; if (!step || step < 0) { step = 10; } w += step - (cur_x - text_start_x - start) % step; - } else if (specials[special_index].type == FONT) { - selected_font = specials[special_index].font_added; + } else if (current->type == FONT) { + selected_font = current->font_added; if (font_height() > last_font_height) { last_font_height = font_height(); } } special_index++; + current = current->next; s = p + 1; } else if (*p == SECRIT_MULTILINE_CHAR) { contain_SECRIT_MULTILINE_CHAR = 1; @@ -1291,11 +1303,14 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) s = p + 1; } /* draw special */ - switch (specials[special_index].type) { + special_t *current = specials; + for(int i = 0; i < special_index; i++) + current = current->next; + switch (current->type) { #ifdef BUILD_X11 case HORIZONTAL_LINE: { - int h = specials[special_index].height; + int h = current->height; int mid = font_ascent() / 2; w = text_start_x + text_width - cur_x; @@ -1309,8 +1324,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) case STIPPLED_HR: { - int h = specials[special_index].height; - char tmp_s = specials[special_index].arg; + int h = current->height; + char tmp_s = current->arg; int mid = font_ascent() / 2; char ss[2] = { tmp_s, tmp_s }; @@ -1331,15 +1346,15 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) && maximum_width > 0) { break; } - h = specials[special_index].height; - bar_usage = specials[special_index].arg; - scale = specials[special_index].scale; + h = current->height; + bar_usage = current->arg; + scale = current->scale; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = specials[special_index].width; + w = current->width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1375,13 +1390,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) break; } - h = specials[special_index].height; + h = current->height; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = specials[special_index].width; + w = current->width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1396,8 +1411,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_x, by, w, h * 2, 0, 180*64); #ifdef MATH - usage = specials[special_index].arg; - scale = specials[special_index].scale; + usage = current->arg; + scale = current->scale; angle = M_PI * usage / scale; px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle); py = (float)(by+(h))-(float)(h)*sin(angle); @@ -1427,13 +1442,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) && maximum_width > 0) { break; } - h = specials[special_index].height; + h = current->height; by = cur_y - (font_ascent() / 2) - 1; if (h < font_h) { by -= h / 2 - 1; } - w = specials[special_index].width; + w = current->width; if (w == 0) { w = text_start_x + text_width - cur_x - 1; } @@ -1449,37 +1464,37 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); - if (specials[special_index].last_colour != 0 - || specials[special_index].first_colour != 0) { - tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour); + if (current->last_colour != 0 + || current->first_colour != 0) { + tmpcolour = do_gradient(w - 1, current->last_colour, current->first_colour); } colour_idx = 0; for (i = w - 2; i > -1; i--) { - if (specials[special_index].last_colour != 0 - || specials[special_index].first_colour != 0) { - if (specials[special_index].tempgrad) { + if (current->last_colour != 0 + || current->first_colour != 0) { + if (current->tempgrad) { #ifdef DEBUG_lol assert( - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) < w - 1 ); assert( - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) > -1 ); - if (specials[special_index].graph[j] == specials[special_index].scale) { + if (current->graph[j] == current->scale) { assert( - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) == 0 ); } #endif /* DEBUG_lol */ XSetForeground(display, window.gc, tmpcolour[ - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].scale) + (int)((float)(w - 2) - current->graph[j] * + (w - 2) / (float)current->scale) ]); } else { XSetForeground(display, window.gc, tmpcolour[colour_idx++]); @@ -1488,10 +1503,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* this is mugfugly, but it works */ XDrawLine(display, window.drawable, window.gc, cur_x + i + 1, by + h, cur_x + i + 1, - round_to_int((double)by + h - specials[special_index].graph[j] * - (h - 1) / specials[special_index].scale)); + round_to_int((double)by + h - current->graph[j] * + (h - 1) / current->scale)); if ((w - i) / ((float) (w - 2) / - (specials[special_index].graph_width)) > j + (current->graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) { j++; } @@ -1552,16 +1567,16 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_y = tmp_y; } #ifdef MATH - if (show_graph_scale && (specials[special_index].show_scale == 1)) { + if (show_graph_scale && (current->show_scale == 1)) { int tmp_x = cur_x; int tmp_y = cur_y; char *tmp_str; cur_x += font_ascent() / 2; cur_y += font_h / 2; tmp_str = (char *) - calloc(log10(floor(specials[special_index].scale)) + 4, + calloc(log10(floor(current->scale)) + 4, sizeof(char)); - sprintf(tmp_str, "%.1f", specials[special_index].scale); + sprintf(tmp_str, "%.1f", current->scale); draw_string(tmp_str); free(tmp_str); cur_x = tmp_x; @@ -1577,7 +1592,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) int old = font_ascent(); cur_y -= font_ascent(); - selected_font = specials[special_index].font_added; + selected_font = current->font_added; set_font(); if (cur_y + font_ascent() < cur_y + old) { cur_y += old; @@ -1590,43 +1605,43 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) #endif /* BUILD_X11 */ case FG: if (draw_mode == FG) { - set_foreground_color(specials[special_index].arg); + set_foreground_color(current->arg); } break; #ifdef BUILD_X11 case BG: if (draw_mode == BG) { - set_foreground_color(specials[special_index].arg); + set_foreground_color(current->arg); } break; case OUTLINE: if (draw_mode == OUTLINE) { - set_foreground_color(specials[special_index].arg); + set_foreground_color(current->arg); } break; case OFFSET: - w += specials[special_index].arg; + w += current->arg; last_special_needed = special_index; break; case VOFFSET: - cur_y += specials[special_index].arg; + cur_y += current->arg; break; case GOTO: - if (specials[special_index].arg >= 0) { - cur_x = (int) specials[special_index].arg; + if (current->arg >= 0) { + cur_x = (int) current->arg; } last_special_needed = special_index; break; case TAB: { - int start = specials[special_index].arg; - int step = specials[special_index].width; + int start = current->arg; + int step = current->width; if (!step || step < 0) { step = 10; @@ -1645,13 +1660,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* printf("pos_x %i text_start_x %i text_width %i cur_x %i " "get_string_width(p) %i gap_x %i " - "specials[special_index].arg %i window.border_inner_margin %i " + "current->arg %i window.border_inner_margin %i " "window.border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, - specials[special_index].arg, window.border_inner_margin, + current->arg, window.border_inner_margin, window.border_width); */ - if (pos_x > specials[special_index].arg && pos_x > cur_x) { - cur_x = pos_x - specials[special_index].arg; + if (pos_x > current->arg && pos_x > cur_x) { + cur_x = pos_x - current->arg; } last_special_needed = special_index; break; @@ -1667,11 +1682,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) /* printf("pos_x %i text_start_x %i text_width %i cur_x %i " "get_string_width(p) %i gap_x %i " - "specials[special_index].arg %i\n", pos_x, text_start_x, + "current->arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, - specials[special_index].arg); */ - if (pos_x > specials[special_index].arg) { - w = pos_x - specials[special_index].arg; + current->arg); */ + if (pos_x > current->arg) { + w = pos_x - current->arg; } last_special_needed = special_index; break; @@ -2399,10 +2414,18 @@ void clean_up_x11() { } #endif +void free_specials(special_t *current) { + if (current) { + free_specials(current->next); + if(current->type == GRAPH) + free(current->graph); + delete current; + current = NULL; + } +} + void clean_up(void *memtofree1, void* memtofree2) { - int i; - free_update_callbacks(); #ifdef BUILD_NCURSES @@ -2468,14 +2491,7 @@ void clean_up(void *memtofree1, void* memtofree2) xmlCleanupParser(); #endif /* BUILD_WEATHER_XOAP */ - if (specials) { - for (i = 0; i < special_count; i++) { - if (specials[i].type == GRAPH) { - free(specials[i].graph); - } - } - free_and_zero(specials); - } + free_specials(specials); clear_net_stats(); clear_diskio_stats(); @@ -3535,13 +3551,6 @@ char load_config_file(const char *f) CONF("uppercase") { stuff_in_uppercase = string_to_bool(value); } - CONF("max_specials") { - if (value) { - max_specials = atoi(value); - } else { - CONF_ERR; - } - } CONF("max_user_text") { if (value) { max_user_text = atoi(value); @@ -4091,11 +4100,6 @@ void initialisation(int argc, char **argv) { currentconffile = conftree_add(currentconffile, current_config.c_str()); } - /* init specials array */ - if ((specials = (special_t*)calloc(sizeof(struct special_t), max_specials)) == 0) { - NORM_ERR("failed to create specials array"); - } - #ifdef MAIL_FILE if (current_mail_spool == NULL) { char buf[256]; diff --git a/src/specials.cc b/src/specials.cc index e60c26b7..1e65deab 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -40,11 +40,6 @@ #endif /* HAVE_SYS_PARAM_H */ #include -/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */ -int max_specials = 512; - -/* create specials array on heap instead of stack with introduction of - * max_specials */ struct special_t *specials = NULL; int special_count; @@ -251,16 +246,32 @@ char *scan_graph(struct text_object *obj, const char *args, double defscale) * Printing various special text objects */ +struct special_t *new_special_t_node() +{ + special_t *newnode = new special_t; + + newnode->graph = NULL; + newnode->next = NULL; + return newnode; +} + struct special_t *new_special(char *buf, enum special_types t) { - if (special_count >= max_specials) { - CRIT_ERR(NULL, NULL, "too many special things in text"); - } + special_t* current; buf[0] = SPECIAL_CHAR; buf[1] = '\0'; - specials[special_count].type = t; - return &specials[special_count++]; + if(!specials) + specials = new_special_t_node(); + current = specials; + for(int i=0; i < special_count; i++) { + if(current->next == NULL) + current->next = new_special_t_node(); + current = current->next; + } + current->type = t; + special_count++; + return current; } void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, double usage) diff --git a/src/specials.h b/src/specials.h index a3d9783f..38b8d6ad 100644 --- a/src/specials.h +++ b/src/specials.h @@ -73,6 +73,7 @@ struct special_t { unsigned long last_colour; short font_added; char tempgrad; + struct special_t *next; }; /* direct access to the registered specials (FIXME: bad encapsulation) */ @@ -91,9 +92,6 @@ extern int default_gauge_height; /* forward declare to avoid mutual inclusion between specials.h and text_object.h */ struct text_object; -/* max number of specials allowed (TODO: use linked list instead) */ -extern int max_specials; - /* scanning special arguments */ const char *scan_bar(struct text_object *, const char *, double); const char *scan_gauge(struct text_object *, const char *, double);