X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fconky.c;h=20f2f67e588eb5c66cf70561bff59b145db9abac;hb=30295b672d7d3c2dd228dbebdff10a9fcbf49ee8;hp=869e9d333b3e6b6436d1b729b7e005e673987ed5;hpb=df5de28d17386d48654c47b1f8521bccaf706468;p=monky diff --git a/src/conky.c b/src/conky.c index 869e9d3..20f2f67 100644 --- a/src/conky.c +++ b/src/conky.c @@ -70,6 +70,9 @@ #ifdef XOAP #include #endif /* XOAP */ +#ifdef HAVE_CURL +#include +#endif /* local headers */ #include "core.h" @@ -166,9 +169,7 @@ int top_cpu, top_mem, top_time; #ifdef IOSTATS int top_io; #endif -#ifdef __linux__ int top_running; -#endif int output_methods; static int extra_newline; enum x_initialiser_state x_initialised = NO; @@ -509,6 +510,7 @@ static inline void for_each_line(char *b, int f(char *, int)) char *ps, *pe; int special_index = 0; /* specials index */ + if(! b) return; for (ps = b, pe = b; *pe; pe++) { if (*pe == '\n') { *pe = '\0'; @@ -604,7 +606,7 @@ void human_readable(long long num, char *buf, int size) spaced_print(buf, size, "%d", 6, round_to_int(num)); return; } - if (short_units) { + if (short_units || llabs(num) < 1000LL) { width = 5; format = "%.*f%.1s"; } else { @@ -631,11 +633,11 @@ void human_readable(long long num, char *buf, int size) * adjusting the decimal part of the number. Sample output: * 123MiB * 23.4GiB - * 5.12B + * 5.12B * so the point of alignment resides between number and unit. The * upside of this is that there is minimal padding necessary, though * there should be a way to make alignment take place at the decimal - * dot (then with fixed width decimal part). + * dot (then with fixed width decimal part). * * Note the repdigits below: when given a precision value, printf() * rounds the float to it, not just cuts off the remaining digits. So @@ -762,6 +764,8 @@ void generate_text_internal(char *p, int p_max_size, buff_in[0] = 0; #endif /* HAVE_ICONV */ + if(! p) return; + p[0] = 0; obj = root.next; while (obj && p_max_size > 0) { @@ -1500,6 +1504,15 @@ void generate_text_internal(char *p, int p_max_size, OBJ(nodename) { snprintf(p, p_max_size, "%s", cur->uname_s.nodename); } + OBJ(nodename_short) { + char *pos; + pos = strstr(cur->uname_s.nodename, "."); + if(pos != NULL) { + snprintf(p, MIN(pos-cur->uname_s.nodename+1, p_max_size), "%s", cur->uname_s.nodename); + } else { + snprintf(p, p_max_size, "%s", cur->uname_s.nodename); + } + } OBJ(outlinecolor) { new_outline(p, obj->data.l); } @@ -2170,7 +2183,6 @@ void generate_text_internal(char *p, int p_max_size, /* we have four different types of top (top, top_mem, * top_time and top_io). To avoid having almost-same code four * times, we have this special handler. */ -#ifdef __linux__ break; case OBJ_top: case OBJ_top_mem: @@ -2179,7 +2191,6 @@ void generate_text_internal(char *p, int p_max_size, case OBJ_top_io: #endif print_top(obj, p, p_max_size); -#endif /* __linux__ */ OBJ(tail) { print_tailhead("tail", obj, p, p_max_size); } @@ -2292,7 +2303,7 @@ void generate_text_internal(char *p, int p_max_size, } #ifdef NVIDIA OBJ(nvidia) { - print_nvidia_value(obj, display, p, p_max_size); + print_nvidia_value(obj, p, p_max_size); } #endif /* NVIDIA */ #ifdef APCUPSD @@ -2372,9 +2383,10 @@ void generate_text_internal(char *p, int p_max_size, #ifdef HAVE_ICONV iconv_convert(&a, buff_in, p, p_max_size); #endif /* HAVE_ICONV */ - if (obj->type != OBJ_text && obj->type != OBJ_execp && obj->type != OBJ_execpi + if (obj->type == OBJ_execp || obj->type == OBJ_execpi || obj->type + == OBJ_exec #ifdef HAVE_LUA - && obj->type != OBJ_lua && obj->type != OBJ_lua_parse + || obj->type == OBJ_lua || obj->type == OBJ_lua_parse #endif /* HAVE_LUA */ ) { substitute_newlines(p, a - 2); @@ -3072,12 +3084,14 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) ); } #endif /* DEBUG_lol */ - XSetForeground(display, window.gc, tmpcolour[ - (int)((float)(w - 2) - specials[special_index].graph[j] * - (w - 2) / (float)specials[special_index].graph_scale) - ]); + set_foreground_color(tmpcolour[ + (int)((float)(w - 2) - + specials[special_index].graph[j] + * (w - 2) / + (float)specials[special_index].graph_scale) + ]); } else { - XSetForeground(display, window.gc, tmpcolour[colour_idx++]); + set_foreground_color(tmpcolour[colour_idx++]); } } /* this is mugfugly, but it works */ @@ -3984,11 +3998,40 @@ static void reload_config(void) initialisation(argc_copy, argv_copy); } -void clean_up(void *memtofree1, void* memtofree2) +#ifdef X11 +void clean_up_x11(void) { - int i; + 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); + } + destroy_window(); + free_fonts(); + fonts = NULL; + if(x11_stuff.region) { + XDestroyRegion(x11_stuff.region); + x11_stuff.region = NULL; + } + if(display) { + XCloseDisplay(display); + display = NULL; + } + if(info.x11.desktop.all_names) { + free(info.x11.desktop.all_names); + info.x11.desktop.all_names = NULL; + } + if (info.x11.desktop.name) { + free(info.x11.desktop.name); + info.x11.desktop.name = NULL; + } + x_initialised = NO; +} +#endif - free_update_callbacks(); +void clean_up_without_threads(void *memtofree1, void* memtofree2) { + int i; #ifdef NCURSES if(output_methods & TO_NCURSES) { @@ -4011,34 +4054,15 @@ void clean_up(void *memtofree1, void* memtofree2) } #ifdef 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); - } - destroy_window(); - free_fonts(); - if(x11_stuff.region) { - XDestroyRegion(x11_stuff.region); - x11_stuff.region = NULL; - } - XCloseDisplay(display); - display = NULL; - if(info.x11.desktop.all_names) { - free(info.x11.desktop.all_names); - info.x11.desktop.all_names = NULL; - } - if (info.x11.desktop.name) { - free(info.x11.desktop.name); - info.x11.desktop.name = NULL; - } - x_initialised = NO; + clean_up_x11(); }else{ free(fonts); //in set_default_configurations a font is set but not loaded font_count = -1; } +#ifdef NVIDIA + set_nvidia_display(NULL); +#endif #endif /* X11 */ free_templates(); @@ -4107,6 +4131,12 @@ void clean_up(void *memtofree1, void* memtofree2) } } +void clean_up(void *memtofree1, void* memtofree2) +{ + free_update_callbacks(); + clean_up_without_threads(memtofree1, memtofree2); +} + static int string_to_bool(const char *s) { if (!s) { @@ -4210,9 +4240,7 @@ static void set_default_configurations(void) #ifdef IOSTATS top_io = 0; #endif -#ifdef __linux__ top_running = 0; -#endif #ifdef MPD mpd_env_host = getenv("MPD_HOST"); mpd_env_port = getenv("MPD_PORT"); @@ -4565,15 +4593,12 @@ char load_config_file(const char *f) #ifdef 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") { @@ -4585,6 +4610,12 @@ char load_config_file(const char *f) disp = strdup(value); } } +#ifdef NVIDIA + CONF("nvidia_display") { + if(value) + set_nvidia_display(value); + } +#endif CONF("alignment") { setalignment(&text_alignment, window.type, value, f, line, 1); } @@ -5868,6 +5899,11 @@ int main(int argc, char **argv) tcp_portmon_set_max_connections(0); #endif +#ifdef HAVE_CURL + if(curl_global_init(CURL_GLOBAL_ALL)) + NORM_ERR("curl_global_init() failed, you may not be able to use curl variables"); +#endif + /* handle command line parameters that don't change configs */ #ifdef X11 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s) @@ -5959,6 +5995,10 @@ int main(int argc, char **argv) main_loop(); +#ifdef HAVE_CURL + curl_global_cleanup(); +#endif + #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) kvm_close(kd); #endif