From: Brenden Matthews Date: Fri, 7 Aug 2009 07:21:56 +0000 (-0600) Subject: Revert "auesnthaeou" X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=098e28598f92a2b91951ea1cce0c2d35f65b7462;p=monky Revert "auesnthaeou" This reverts commit 70adc04fc28cd92c976301aa36b0dcb8d719389b. Oops, didn't mean to push this. I'll start a new branch now (so I don't do this again...). --- diff --git a/src/colours.c b/src/colours.c index 17c51d7..6872c5b 100644 --- a/src/colours.c +++ b/src/colours.c @@ -53,7 +53,7 @@ static void set_up_gradient(conky_context *ctx) } if (ctx->colour_depth != 24 && ctx->colour_depth != 16) { NORM_ERR("using non-standard colour depth, gradients may look like a " - "lollipop"); + "lolly-pop"); } ctx->redmask = 0; diff --git a/src/common.c b/src/common.c index 83bf0fe..4202303 100644 --- a/src/common.c +++ b/src/common.c @@ -33,7 +33,6 @@ #include "common.h" #include "fs.h" #include "logging.h" -#include "core.h" #include #include #include @@ -219,7 +218,7 @@ void variable_substitute(const char *s, char *dest, unsigned int n) static struct net_stat netstats[16]; -struct net_stat *get_net_stat(conky_context *ctx, const char *dev, void *free_at_crash1, void *free_at_crash2) +struct net_stat *get_net_stat(const char *dev, void *free_at_crash1, void *free_at_crash2) { unsigned int i; @@ -242,7 +241,7 @@ struct net_stat *get_net_stat(conky_context *ctx, const char *dev, void *free_at } } - CRIT_ERR(ctx, free_at_crash1, free_at_crash2, "too many interfaces used (limit is 16)"); + CRIT_ERR(free_at_crash1, free_at_crash2, "too many interfaces used (limit is 16)"); return 0; } @@ -258,13 +257,13 @@ void clear_net_stats(void) } /* We should check if this is ok with OpenBSD and NetBSD as well. */ -int interface_up(conky_context *ctx, const char *dev) +int interface_up(const char *dev) { int fd; struct ifreq ifr; if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - CRIT_ERR(ctx, NULL, NULL, "could not create sockfd"); + CRIT_ERR(NULL, NULL, "could not create sockfd"); return 0; } strncpy(ifr.ifr_name, dev, IFNAMSIZ); diff --git a/src/common.h b/src/common.h index f2f38da..da91d60 100644 --- a/src/common.h +++ b/src/common.h @@ -77,8 +77,8 @@ struct net_stat { }; void clear_net_stats(void); void clear_cpu_stats(void); -struct net_stat *get_net_stat(conky_context *ctx, const char *dev, void *free_at_crash1, void *free_at_crash2); -int interface_up(conky_context *ctx, const char *dev); +struct net_stat *get_net_stat(const char *dev, void *free_at_crash1, void *free_at_crash2); +int interface_up(const char *dev); void get_adt746x_cpu(char *, size_t); void get_adt746x_fan(char *, size_t); diff --git a/src/conky.c b/src/conky.c index ac4b226..d47af06 100644 --- a/src/conky.c +++ b/src/conky.c @@ -55,6 +55,9 @@ #ifdef HAVE_XDAMAGE #include #endif /* HAVE_XDAMAGE */ +#ifdef IMLIB2 +#include "imlib2.h" +#endif /* IMLIB2 */ #endif /* X11 */ #include #include @@ -73,6 +76,7 @@ #include "algebra.h" #include "build.h" #include "colours.h" +#include "diskio.h" #ifdef X11 #include "fonts.h" #endif @@ -117,6 +121,7 @@ char *get_apm_battery_time(void); #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK) #endif +#define MAIL_FILE "$MAIL" #define MAX_IF_BLOCK_DEPTH 5 //#define SIGNAL_BLOCKING @@ -133,6 +138,7 @@ char** argv_copy; /* prototypes for internally used functions */ static void signal_handler(int); static void print_version(void) __attribute__((noreturn)); +static void reload_config(void); static void print_version(void) { @@ -608,7 +614,7 @@ static void main_loop(conky_context *ctx) case SIGHUP: case SIGUSR1: NORM_ERR("received SIGHUP or SIGUSR1. reloading the config file."); - reload_config(ctx); + reload_config(); break; case SIGINT: case SIGTERM: @@ -673,7 +679,7 @@ static void main_loop(conky_context *ctx) if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) { /* ctx->current_config should be reloaded */ NORM_ERR("'%s' modified, reloading...", ctx->current_config); - reload_config(ctx); + reload_config(); if (ev->mask & IN_IGNORED) { /* for some reason we get IN_IGNORED here * sometimes, so we need to re-add the watch */ @@ -698,7 +704,7 @@ static void main_loop(conky_context *ctx) #endif /* HAVE_LUA */ g_signal_pending = 0; } - clean_up(ctx, NULL, NULL); + clean_up(NULL, NULL); #ifdef HAVE_SYS_INOTIFY_H if (inotify_fd != -1) { @@ -844,7 +850,7 @@ void initialisation(conky_context *ctx, int argc, char **argv) break; #ifdef X11 case 'f': - set_first_font(ctx, optarg); + set_first_font(optarg); break; case 'a': ctx->text_alignment = string_to_alignment(optarg); diff --git a/src/conky.h b/src/conky.h index 8d4fbe0..d3e3c07 100644 --- a/src/conky.h +++ b/src/conky.h @@ -250,14 +250,10 @@ enum { #define KFLAG_FLIP(a) ctx->info.kflags ^= a #define KFLAG_ISSET(a) ctx->info.kflags & a -#define MAIL_FILE "$MAIL" - /* defined in users.c */ void update_users(void); extern int inotify_fd; -extern int argc_copy; -extern char** argv_copy; #define NOBATTERY 0 diff --git a/src/core.c b/src/core.c index a7d3df7..3d7b5f9 100644 --- a/src/core.c +++ b/src/core.c @@ -34,24 +34,15 @@ #include "core.h" #include "text_object.h" -#include "obj_create.h" -#include "obj_display.h" #include "obj_destroy.h" #include "common.h" #include "specials.h" #include "logging.h" -#include "fonts.h" -#include "colours.h" -#include "diskio.h" #include #include -#include #ifdef X11 -#ifdef IMLIB2 -#include "imlib2.h" -#endif /* IMLIB2 */ static void X11_initialisation(conky_context *ctx); @@ -218,7 +209,7 @@ static inline int calc_text_width(conky_context *ctx, const char *s, int l) /* quite boring functions */ -static inline void for_each_line(conky_context *ctx, char *b, int f(conky_context *, char *, int)) +static inline void for_each_line(char *b, int f(char *, int)) { char *ps, *pe; int special_index = 0; /* specials index */ @@ -226,14 +217,14 @@ static inline void for_each_line(conky_context *ctx, char *b, int f(conky_contex for (ps = b, pe = b; *pe; pe++) { if (*pe == '\n') { *pe = '\0'; - special_index = f(ctx, ps, special_index); + special_index = f(ps, special_index); *pe = '\n'; ps = pe + 1; } } if (ps < pe) { - f(ctx, ps, special_index); + f(ps, special_index); } } @@ -424,17 +415,64 @@ void extract_variable_text(conky_context *ctx, const char *p) ctx->text_buffer = 0; } - extract_variable_text_internal(&global_root_object, p); + extract_variable_text_internal(ctx, &global_root_object, p); } -void parse_conky_vars(conky_context *ctx, struct text_object *root, const char *txt, char *p) +void parse_conky_vars(ctx, struct text_object *root, const char *txt, char *p) { - extract_variable_text_internal(root, txt); + extract_variable_text_internal(ctx, root, txt); generate_text_internal(ctx, p, max_user_text, *root); } -static void generate_text(conky_context *ctx) +static inline struct mail_s *ensure_mail_thread(struct text_object *obj, + void *thread(void *), const char *text) +{ + if (obj->char_b && ctx->info.mail) { + /* this means we use ctx->info */ + if (!ctx->info.mail->p_timed_thread) { + ctx->info.mail->p_timed_thread = + timed_thread_create(thread, + (void *) ctx->info.mail, ctx->info.mail->interval * 1000000); + if (!ctx->info.mail->p_timed_thread) { + NORM_ERR("Error creating %s timed thread", text); + } + timed_thread_register(ctx->info.mail->p_timed_thread, + &ctx->info.mail->p_timed_thread); + if (timed_thread_run(ctx->info.mail->p_timed_thread)) { + NORM_ERR("Error running %s timed thread", text); + } + } + return ctx->info.mail; + } else if (obj->data.mail) { + // this means we use obj + if (!obj->data.mail->p_timed_thread) { + obj->data.mail->p_timed_thread = + timed_thread_create(thread, + (void *) obj->data.mail, + obj->data.mail->interval * 1000000); + if (!obj->data.mail->p_timed_thread) { + NORM_ERR("Error creating %s timed thread", text); + } + timed_thread_register(obj->data.mail->p_timed_thread, + &obj->data.mail->p_timed_thread); + if (timed_thread_run(obj->data.mail->p_timed_thread)) { + NORM_ERR("Error running %s timed thread", text); + } + } + return obj->data.mail; + } else if (!obj->a) { + // something is wrong, warn once then stop + NORM_ERR("There's a problem with your mail settings. " + "Check that the global mail settings are properly defined" + " (line %li).", obj->line); + obj->a++; + } + return NULL; +} + +static void generate_text(void) { + struct information *cur = &ctx->info; char *p; special_count = 0; @@ -443,7 +481,7 @@ static void generate_text(conky_context *ctx) ctx->current_update_time = get_time(); - update_stuff(ctx); + update_stuff(); /* add things to the buffer */ @@ -479,18 +517,18 @@ void set_update_interval(conky_context *ctx, double interval) ctx->update_interval_old = interval; } -static inline int get_string_width(conky_context *ctx, const char *s) +static inline int get_string_width(const char *s) { #ifdef X11 if (ctx->output_methods & TO_X) { - return *s ? calc_text_width(ctx, s, strlen(s)) : 0; + return *s ? calc_text_width(s, strlen(s)) : 0; } #endif /* X11 */ return strlen(s); } #ifdef X11 -static int get_string_width_special(conky_context *ctx, char *s, int special_index) +static int get_string_width_special(char *s, int special_index) { char *p, *final; int idx = 1; @@ -529,13 +567,13 @@ static int get_string_width_special(conky_context *ctx, char *s, int special_ind } } if (strlen(final) > 1) { - width += calc_text_width(ctx, final, strlen(final)); + width += calc_text_width(final, strlen(final)); } free(final); return width; } -static int text_size_updater(conky_context *ctx, char *s, int special_index); +static int text_size_updater(char *s, int special_index); void update_text_area(conky_context *ctx) { @@ -548,16 +586,16 @@ void update_text_area(conky_context *ctx) if (!fixed_size) #endif { - ctx->text_width = minimum_width; - ctx->text_height = 0; - ctx->last_font_height = font_height(); - for_each_line(ctx, ctx->text_buffer, text_size_updater); - ctx->text_width += 1; - if (ctx->text_height < minimum_height) { - ctx->text_height = minimum_height; + text_width = minimum_width; + text_height = 0; + last_font_height = font_height(); + for_each_line(ctx->text_buffer, text_size_updater); + text_width += 1; + if (text_height < minimum_height) { + text_height = minimum_height; } - if (ctx->text_width > maximum_width && maximum_width > 0) { - ctx->text_width = maximum_width; + if (text_width > maximum_width && maximum_width > 0) { + text_width = maximum_width; } } @@ -569,45 +607,45 @@ void update_text_area(conky_context *ctx) break; case TOP_RIGHT: - x = workarea[2] - ctx->text_width - gap_x; + x = workarea[2] - text_width - gap_x; y = gap_y; break; case TOP_MIDDLE: - x = workarea[2] / 2 - ctx->text_width / 2 - gap_x; + x = workarea[2] / 2 - text_width / 2 - gap_x; y = gap_y; break; default: case BOTTOM_LEFT: x = gap_x; - y = workarea[3] - ctx->text_height - gap_y; + y = workarea[3] - text_height - gap_y; break; case BOTTOM_RIGHT: - x = workarea[2] - ctx->text_width - gap_x; - y = workarea[3] - ctx->text_height - gap_y; + x = workarea[2] - text_width - gap_x; + y = workarea[3] - text_height - gap_y; break; case BOTTOM_MIDDLE: - x = workarea[2] / 2 - ctx->text_width / 2 - gap_x; - y = workarea[3] - ctx->text_height - gap_y; + x = workarea[2] / 2 - text_width / 2 - gap_x; + y = workarea[3] - text_height - gap_y; break; case MIDDLE_LEFT: x = gap_x; - y = workarea[3] / 2 - ctx->text_height / 2 - gap_y; + y = workarea[3] / 2 - text_height / 2 - gap_y; break; case MIDDLE_RIGHT: - x = workarea[2] - ctx->text_width - gap_x; - y = workarea[3] / 2 - ctx->text_height / 2 - gap_y; + x = workarea[2] - text_width - gap_x; + y = workarea[3] / 2 - text_height / 2 - gap_y; break; #ifdef OWN_WINDOW case NONE: // Let the WM manage the window - x = ctx->window.x; - y = ctx->window.y; + x = window.x; + y = window.y; fixed_pos = 1; fixed_size = 1; @@ -619,27 +657,27 @@ void update_text_area(conky_context *ctx) if (own_window && !fixed_pos) { x += workarea[0]; y += workarea[1]; - ctx->text_start_x = ctx->window.border_inner_margin + ctx->window.border_outer_margin + ctx->window.border_width; - ctx->text_start_y = ctx->window.border_inner_margin + ctx->window.border_outer_margin + ctx->window.border_width; - ctx->window.x = x - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width; - ctx->window.y = y - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width; + 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; } else #endif { /* If window size doesn't match to workarea's size, * then window probably includes panels (gnome). * Blah, doesn't work on KDE. */ - if (workarea[2] != ctx->window.width || workarea[3] != ctx->window.height) { + if (workarea[2] != window.width || workarea[3] != window.height) { y += workarea[1]; x += workarea[0]; } - ctx->text_start_x = x; - ctx->text_start_y = y; + text_start_x = x; + text_start_y = y; } #ifdef HAVE_LUA /* update lua window globals */ - llua_update_window_table(ctx->text_start_x, ctx->text_start_y, ctx->text_width, ctx->text_height); + llua_update_window_table(text_start_x, text_start_y, text_width, text_height); #endif /* HAVE_LUA */ } @@ -652,7 +690,7 @@ static int draw_mode; /* FG, BG or OUTLINE */ #ifdef X11 static long current_color; -static int text_size_updater(conky_context *ctx, char *s, int special_index) +static int text_size_updater(char *s, int special_index) { int w = 0; char *p; @@ -664,23 +702,23 @@ static int text_size_updater(conky_context *ctx, char *s, int special_index) while (*p) { if (*p == SPECIAL_CHAR) { *p = '\0'; - w += get_string_width(ctx, s); + 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 > ctx->last_font_height) { - ctx->last_font_height = specials[special_index].height; - ctx->last_font_height += font_height(); + if (specials[special_index].height > last_font_height) { + last_font_height = specials[special_index].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 (specials[special_index].type == VOFFSET) { - ctx->last_font_height += specials[special_index].arg; + 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; @@ -692,11 +730,11 @@ static int text_size_updater(conky_context *ctx, char *s, int special_index) if (!step || step < 0) { step = 10; } - w += step - (cur_x - ctx->text_start_x - start) % step; + w += step - (cur_x - text_start_x - start) % step; } else if (specials[special_index].type == FONT) { ctx->selected_font = specials[special_index].font_added; - if (font_height() > ctx->last_font_height) { - ctx->last_font_height = font_height(); + if (font_height() > last_font_height) { + last_font_height = font_height(); } } @@ -705,34 +743,34 @@ static int text_size_updater(conky_context *ctx, char *s, int special_index) } else if (*p == SECRIT_MULTILINE_CHAR) { int lw; *p = '\0'; - lw = get_string_width(ctx, s); + lw = get_string_width(s); *p = SECRIT_MULTILINE_CHAR; s = p + 1; w = lw > w ? lw : w; - ctx->text_height += ctx->last_font_height; + text_height += last_font_height; } p++; } - w += get_string_width(ctx, s); - if (w > ctx->text_width) { - ctx->text_width = w; + w += get_string_width(s); + if (w > text_width) { + text_width = w; } - if (ctx->text_width > maximum_width && maximum_width) { - ctx->text_width = maximum_width; + if (text_width > maximum_width && maximum_width) { + text_width = maximum_width; } - ctx->text_height += ctx->last_font_height; - ctx->last_font_height = font_height(); + text_height += last_font_height; + last_font_height = font_height(); return special_index; } #endif /* X11 */ -static inline void set_foreground_color(conky_context *ctx, long c) +static inline void set_foreground_color(long c) { #ifdef X11 if (ctx->output_methods & TO_X) { current_color = c; - XSetForeground(display, ctx->window.gc, c); + XSetForeground(display, window.gc, c); } #endif /* X11 */ #ifdef NCURSES @@ -744,7 +782,7 @@ static inline void set_foreground_color(conky_context *ctx, long c) return; } -static void draw_string(conky_context *ctx, const char *s) +static void draw_string(const char *s) { int i, i2, pos, width_of_s; int max = 0; @@ -755,7 +793,7 @@ static void draw_string(conky_context *ctx, const char *s) return; } - width_of_s = get_string_width(ctx, s); + width_of_s = get_string_width(s); s_with_newlines = strdup(s); for(i = 0; i < (int) strlen(s_with_newlines); i++) { if(s_with_newlines[i] == SECRIT_MULTILINE_CHAR) { @@ -764,7 +802,7 @@ static void draw_string(conky_context *ctx, const char *s) } if ((ctx->output_methods & TO_STDOUT) && draw_mode == FG) { printf("%s\n", s_with_newlines); - if (ctx->extra_newline) fputc('\n', stdout); + if (extra_newline) fputc('\n', stdout); fflush(stdout); /* output immediately, don't buffer */ } if ((ctx->output_methods & TO_STDERR) && draw_mode == FG) { @@ -791,7 +829,7 @@ static void draw_string(conky_context *ctx, const char *s) #ifdef X11 if (ctx->output_methods & TO_X) { - max = ((ctx->text_width - width_of_s) / get_string_width(ctx, " ")); + max = ((text_width - width_of_s) / get_string_width(" ")); } #endif /* X11 */ /* This code looks for tabs in the text and coverts them to spaces. @@ -814,10 +852,10 @@ static void draw_string(conky_context *ctx, const char *s) } #ifdef X11 if (ctx->output_methods & TO_X) { - if (ctx->text_width == maximum_width) { + if (text_width == maximum_width) { /* this means the text is probably pushing the limit, * so we'll chop it */ - while (cur_x + get_string_width(ctx, ctx->tmpstring2) - ctx->text_start_x + while (cur_x + get_string_width(ctx->tmpstring2) - text_start_x > maximum_width && strlen(ctx->tmpstring2) > 0) { ctx->tmpstring2[strlen(ctx->tmpstring2) - 1] = '\0'; } @@ -841,16 +879,16 @@ static void draw_string(conky_context *ctx, const char *s) c2.color.blue = c.blue; c2.color.alpha = ctx->fonts[ctx->selected_font].font_alpha; if (utf8_mode) { - XftDrawStringUtf8(ctx->window.xftdraw, &c2, ctx->fonts[ctx->selected_font].xftfont, + XftDrawStringUtf8(window.xftdraw, &c2, ctx->fonts[ctx->selected_font].xftfont, cur_x, cur_y, (const XftChar8 *) s, strlen(s)); } else { - XftDrawString8(ctx->window.xftdraw, &c2, ctx->fonts[ctx->selected_font].xftfont, + XftDrawString8(window.xftdraw, &c2, ctx->fonts[ctx->selected_font].xftfont, cur_x, cur_y, (const XftChar8 *) s, strlen(s)); } } else #endif { - XDrawString(display, ctx->window.drawable, ctx->window.gc, cur_x, cur_y, s, + XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s, strlen(s)); } cur_x += width_of_s; @@ -859,7 +897,7 @@ static void draw_string(conky_context *ctx, const char *s) memcpy(ctx->tmpstring1, s, text_buffer_size); } -static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, int last_special_applied) +int draw_each_line_inner(char *s, int special_index, int last_special_applied) { #ifdef X11 int font_h = font_height(); @@ -871,7 +909,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, int orig_special_index = special_index; #ifdef X11 - cur_x = ctx->text_start_x; + cur_x = text_start_x; cur_y += font_ascent(); #endif /* X11 */ @@ -893,7 +931,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, special_index = last_special_applied; } else { *p = '\0'; - draw_string(ctx, s); + draw_string(s); *p = SPECIAL_CHAR; s = p + 1; } @@ -905,11 +943,11 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, int h = specials[special_index].height; int mid = font_ascent() / 2; - w = ctx->text_start_x + ctx->text_width - cur_x; + w = text_start_x + text_width - cur_x; - XSetLineAttributes(display, ctx->window.gc, h, LineSolid, + XSetLineAttributes(display, window.gc, h, LineSolid, CapButt, JoinMiter); - XDrawLine(display, ctx->window.drawable, ctx->window.gc, cur_x, + XDrawLine(display, window.drawable, window.gc, cur_x, cur_y - mid / 2, cur_x + w, cur_y - mid / 2); break; } @@ -921,11 +959,11 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, int mid = font_ascent() / 2; char ss[2] = { tmp_s, tmp_s }; - w = ctx->text_start_x + ctx->text_width - cur_x - 1; - XSetLineAttributes(display, ctx->window.gc, h, LineOnOffDash, + w = text_start_x + text_width - cur_x - 1; + XSetLineAttributes(display, window.gc, h, LineOnOffDash, CapButt, JoinMiter); - XSetDashes(display, ctx->window.gc, 0, ss, 2); - XDrawLine(display, ctx->window.drawable, ctx->window.gc, cur_x, + XSetDashes(display, window.gc, 0, ss, 2); + XDrawLine(display, window.drawable, window.gc, cur_x, cur_y - mid / 2, cur_x + w, cur_y - mid / 2); break; } @@ -933,7 +971,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, case BAR: { int h, bar_usage, by; - if (cur_x - ctx->text_start_x > maximum_width + if (cur_x - text_start_x > maximum_width && maximum_width > 0) { break; } @@ -946,18 +984,18 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, } w = specials[special_index].width; if (w == 0) { - w = ctx->text_start_x + ctx->text_width - cur_x - 1; + w = text_start_x + text_width - cur_x - 1; } if (w < 0) { w = 0; } - XSetLineAttributes(display, ctx->window.gc, 1, LineSolid, + XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); - XDrawRectangle(display, ctx->window.drawable, ctx->window.gc, cur_x, + XDrawRectangle(display, window.drawable, window.gc, cur_x, by, w, h); - XFillRectangle(display, ctx->window.drawable, ctx->window.gc, cur_x, + XFillRectangle(display, window.drawable, window.gc, cur_x, by, w * bar_usage / 255, h); if (h > cur_y_add && h > font_h) { @@ -975,7 +1013,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, int usage; #endif /* MATH */ - if (cur_x - ctx->text_start_x > maximum_width + if (cur_x - text_start_x > maximum_width && maximum_width > 0) { break; } @@ -988,16 +1026,16 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, } w = specials[special_index].width; if (w == 0) { - w = ctx->text_start_x + ctx->text_width - cur_x - 1; + w = text_start_x + text_width - cur_x - 1; } if (w < 0) { w = 0; } - XSetLineAttributes(display, ctx->window.gc, 1, LineSolid, + XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); - XDrawArc(display, ctx->window.drawable, ctx->window.gc, + XDrawArc(display, window.drawable, window.gc, cur_x, by, w, h * 2, 0, 180*64); #ifdef MATH @@ -1006,7 +1044,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle); py = (float)(by+(h))-(float)(h)*sin(angle); - XDrawLine(display, ctx->window.drawable, ctx->window.gc, + XDrawLine(display, window.drawable, window.gc, cur_x + (w/2.), by+(h), (int)(px), (int)(py)); #endif /* MATH */ @@ -1015,7 +1053,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, cur_y_add = h; } - set_foreground_color(ctx, last_colour); + set_foreground_color(last_colour); break; @@ -1027,7 +1065,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, int colour_idx = 0; unsigned long last_colour = current_color; unsigned long *tmpcolour = 0; - if (cur_x - ctx->text_start_x > maximum_width + if (cur_x - text_start_x > maximum_width && maximum_width > 0) { break; } @@ -1039,23 +1077,23 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, } w = specials[special_index].width; if (w == 0) { - w = ctx->text_start_x + ctx->text_width - cur_x - 1; + w = text_start_x + text_width - cur_x - 1; } if (w < 0) { w = 0; } if (draw_graph_borders) { - XSetLineAttributes(display, ctx->window.gc, 1, LineSolid, + XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); - XDrawRectangle(display, ctx->window.drawable, ctx->window.gc, + XDrawRectangle(display, window.drawable, window.gc, cur_x, by, w, h); } - XSetLineAttributes(display, ctx->window.gc, 1, LineSolid, + XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter); if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) { - tmpcolour = do_gradient(ctx, w - 1, specials[special_index].last_colour, specials[special_index].first_colour); + 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--) { @@ -1081,16 +1119,16 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, ); } #endif /* DEBUG_lol */ - XSetForeground(display, ctx->window.gc, tmpcolour[ + XSetForeground(display, window.gc, tmpcolour[ (int)((float)(w - 2) - specials[special_index].graph[j] * (w - 2) / (float)specials[special_index].graph_scale) ]); } else { - XSetForeground(display, ctx->window.gc, tmpcolour[colour_idx++]); + XSetForeground(display, window.gc, tmpcolour[colour_idx++]); } } /* this is mugfugly, but it works */ - XDrawLine(display, ctx->window.drawable, ctx->window.gc, + 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].graph_scale)); @@ -1106,16 +1144,16 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, cur_y_add = h; } /* if (draw_mode == BG) { - set_foreground_color(ctx, default_bg_color); + set_foreground_color(default_bg_color); } else if (draw_mode == OUTLINE) { - set_foreground_color(ctx, default_out_color); + set_foreground_color(default_out_color); } else { - set_foreground_color(ctx, default_fg_color); + set_foreground_color(default_fg_color); } */ if (show_graph_range) { int tmp_x = cur_x; int tmp_y = cur_y; - unsigned short int seconds = ctx->update_interval * w; + unsigned short int seconds = update_interval * w; char *tmp_day_str; char *tmp_hour_str; char *tmp_min_str; @@ -1153,7 +1191,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, } cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2)); cur_y += font_h / 2; - draw_string(ctx, tmp_str); + draw_string(tmp_str); free(tmp_str); cur_x = tmp_x; cur_y = tmp_y; @@ -1169,13 +1207,13 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, calloc(log10(floor(specials[special_index].graph_scale)) + 4, sizeof(char)); sprintf(tmp_str, "%.1f", specials[special_index].graph_scale); - draw_string(ctx, tmp_str); + draw_string(tmp_str); free(tmp_str); cur_x = tmp_x; cur_y = tmp_y; } #endif - set_foreground_color(ctx, last_colour); + set_foreground_color(last_colour); break; } @@ -1197,20 +1235,20 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, #endif /* X11 */ case FG: if (draw_mode == FG) { - set_foreground_color(ctx, specials[special_index].arg); + set_foreground_color(specials[special_index].arg); } break; #ifdef X11 case BG: if (draw_mode == BG) { - set_foreground_color(ctx, specials[special_index].arg); + set_foreground_color(specials[special_index].arg); } break; case OUTLINE: if (draw_mode == OUTLINE) { - set_foreground_color(ctx, specials[special_index].arg); + set_foreground_color(specials[special_index].arg); } break; @@ -1238,25 +1276,25 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, if (!step || step < 0) { step = 10; } - w = step - (cur_x - ctx->text_start_x - start) % step; + w = step - (cur_x - text_start_x - start) % step; last_special_needed = special_index; break; } case ALIGNR: { - /* TODO: add back in "+ ctx->window.border_inner_margin" to the end of + /* TODO: add back in "+ window.border_inner_margin" to the end of * this line? */ - int pos_x = ctx->text_start_x + ctx->text_width - - get_string_width_special(ctx, s, special_index); + int pos_x = text_start_x + text_width - + get_string_width_special(s, special_index); - /* printf("pos_x %i ctx->text_start_x %i ctx->text_width %i cur_x %i " + /* 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 ctx->window.border_inner_margin %i " - "ctx->window.border_width %i\n", pos_x, ctx->text_start_x, ctx->text_width, + "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, - specials[special_index].arg, ctx->window.border_inner_margin, - ctx->window.border_width); */ + specials[special_index].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; } @@ -1266,16 +1304,16 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, case ALIGNC: { - int pos_x = (ctx->text_width) / 2 - - get_string_width_special(ctx, s, special_index) / 2 - - (cur_x - ctx->text_start_x); - /* int pos_x = ctx->text_start_x + ctx->text_width / 2 - + int pos_x = (text_width) / 2 - get_string_width_special(s, + special_index) / 2 - (cur_x - + text_start_x); + /* int pos_x = text_start_x + text_width / 2 - get_string_width_special(s) / 2; */ - /* printf("pos_x %i ctx->text_start_x %i ctx->text_width %i cur_x %i " + /* 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, ctx->text_start_x, - ctx->text_width, cur_x, get_string_width(s), gap_x, + "specials[special_index].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; @@ -1303,7 +1341,7 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, #ifdef X11 cur_y += cur_y_add; #endif /* X11 */ - draw_string(ctx, s); + draw_string(s); #ifdef NCURSES if (ctx->output_methods & TO_NCURSES) { printw("\n"); @@ -1313,55 +1351,55 @@ static int draw_each_line_inner(conky_context *ctx, char *s, int special_index, cur_y += font_descent(); #endif /* X11 */ if (recurse && *recurse) { - special_index = draw_each_line_inner(ctx, recurse, special_index, last_special_needed); + special_index = draw_each_line_inner(recurse, special_index, last_special_needed); *(recurse - 1) = SECRIT_MULTILINE_CHAR; } return special_index; } -static int draw_line(conky_context *ctx, char *s, int special_index) +static int draw_line(char *s, int special_index) { #ifdef X11 if (ctx->output_methods & TO_X) { - return draw_each_line_inner(ctx, s, special_index, -1); + return draw_each_line_inner(s, special_index, -1); } #endif /* X11 */ #ifdef NCURSES if (ctx->output_methods & TO_NCURSES) { - return draw_each_line_inner(ctx, s, special_index, -1); + return draw_each_line_inner(s, special_index, -1); } #endif /* NCURSES */ - draw_string(ctx, s); + draw_string(s); UNUSED(special_index); return 0; } -static void draw_text(conky_context *ctx) +static void draw_text(void) { #ifdef X11 #ifdef HAVE_LUA llua_draw_pre_hook(); #endif /* HAVE_LUA */ if (ctx->output_methods & TO_X) { - cur_y = ctx->text_start_y; + cur_y = text_start_y; /* draw borders */ - if (draw_borders && ctx->window.border_width > 0) { + if (draw_borders && window.border_width > 0) { if (stippled_borders) { char ss[2] = { stippled_borders, stippled_borders }; - XSetLineAttributes(display, ctx->window.gc, ctx->window.border_width, LineOnOffDash, + XSetLineAttributes(display, window.gc, window.border_width, LineOnOffDash, CapButt, JoinMiter); - XSetDashes(display, ctx->window.gc, 0, ss, 2); + XSetDashes(display, window.gc, 0, ss, 2); } else { - XSetLineAttributes(display, ctx->window.gc, ctx->window.border_width, LineSolid, + XSetLineAttributes(display, window.gc, window.border_width, LineSolid, CapButt, JoinMiter); } - XDrawRectangle(display, ctx->window.drawable, ctx->window.gc, - ctx->text_start_x - ctx->window.border_inner_margin - ctx->window.border_width, - ctx->text_start_y - ctx->window.border_inner_margin - ctx->window.border_width, - ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_width * 2, - ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_width * 2); + XDrawRectangle(display, window.drawable, window.gc, + text_start_x - window.border_inner_margin - window.border_width, + text_start_y - window.border_inner_margin - window.border_width, + text_width + window.border_inner_margin * 2 + window.border_width * 2, + text_height + window.border_inner_margin * 2 + window.border_width * 2); } /* draw text */ @@ -1372,7 +1410,7 @@ static void draw_text(conky_context *ctx) init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); attron(COLOR_PAIR(COLOR_WHITE)); #endif /* NCURSES */ - for_each_line(ctx, ctx->text_buffer, draw_line); + for_each_line(ctx->text_buffer, draw_line); #if defined(HAVE_LUA) && defined(X11) llua_draw_post_hook(); #endif /* HAVE_LUA */ @@ -1381,7 +1419,7 @@ static void draw_text(conky_context *ctx) void draw_stuff(conky_context *ctx) { #ifdef IMLIB2 - cimlib_render(ctx->text_start_x, ctx->text_start_y, ctx->window.width, ctx->window.height); + cimlib_render(text_start_x, text_start_y, window.width, window.height); #endif /* IMLIB2 */ if (overwrite_file) { overwrite_fpointer = fopen(overwrite_file, "w"); @@ -1397,13 +1435,13 @@ void draw_stuff(conky_context *ctx) if (ctx->output_methods & TO_X) { ctx->selected_font = 0; if (draw_shades && !draw_outline) { - ctx->text_start_x++; - ctx->text_start_y++; - set_foreground_color(ctx, default_bg_color); + text_start_x++; + text_start_y++; + set_foreground_color(default_bg_color); draw_mode = BG; - draw_text(ctx); - ctx->text_start_x--; - ctx->text_start_y--; + draw_text(); + text_start_x--; + text_start_y--; } if (draw_outline) { @@ -1415,22 +1453,22 @@ void draw_stuff(conky_context *ctx) if (i == 0 && j == 0) { continue; } - ctx->text_start_x += i; - ctx->text_start_y += j; - set_foreground_color(ctx, default_out_color); + text_start_x += i; + text_start_y += j; + set_foreground_color(default_out_color); draw_mode = OUTLINE; - draw_text(ctx); - ctx->text_start_x -= i; - ctx->text_start_y -= j; + draw_text(); + text_start_x -= i; + text_start_y -= j; } } } - set_foreground_color(ctx, default_fg_color); + set_foreground_color(default_fg_color); } #endif /* X11 */ draw_mode = FG; - draw_text(ctx); + draw_text(); #ifdef X11 xdbe_swap_buffers(); if (ctx->output_methods & TO_X) { @@ -1457,12 +1495,12 @@ void clear_text(conky_context *ctx, int exposures) return; } else #endif - if (display && ctx->window.window) { // make sure these are !null + if (display && window.window) { // make sure these are !null /* there is some extra space for borders and outlines */ - XClearArea(display, ctx->window.window, ctx->text_start_x - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width, - ctx->text_start_y - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width, - ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, - ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, exposures ? True : 0); + 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); } } #endif /* X11 */ @@ -1473,34 +1511,34 @@ void update_text(conky_context *ctx) #ifdef IMLIB2 cimlib_cleanup(); #endif /* IMLIB2 */ - generate_text(ctx); + generate_text(); #ifdef X11 if (ctx->output_methods & TO_X) - clear_text(ctx, 1); + clear_text(1); #endif /* X11 */ ctx->need_to_update = 1; #ifdef HAVE_LUA - llua_update_info(ctx, ctx->update_interval); + llua_update_info(&ctx->info, update_interval); #endif /* HAVE_LUA */ } void initialisation(conky_context *ctx, int argc, char** argv); -/* reload the config file */ -void reload_config(conky_context *ctx) + /* reload the config file */ +static void reload_config(conky_context *ctx) { char *current_config_copy = strdup(current_config); - clean_up(ctx, NULL, NULL); + clean_up(NULL, NULL); current_config = current_config_copy; initialisation(ctx, argc_copy, argv_copy); } -void clean_up(conky_context *ctx, void *memtofree1, void *memtofree2) +void clean_up(void *memtofree1, void *memtofree2) { int i; #ifdef NCURSES - if (ctx->output_methods & TO_NCURSES) { + if(ctx->output_methods & TO_NCURSES) { endwin(); } #endif @@ -1519,16 +1557,16 @@ void clean_up(conky_context *ctx, void *memtofree1, void *memtofree2) ctx->info.cpu_usage = NULL; } #ifdef X11 - if (ctx->x_initialised == YES) { - XClearArea(display, ctx->window.window, ctx->text_start_x - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width, - ctx->text_start_y - ctx->window.border_inner_margin - ctx->window.border_outer_margin - ctx->window.border_width, - ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, - ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, 0); + if (x_initialised == YES) { + 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(ctx->window.region) { - XDestroyRegion(ctx->window.region); - ctx->window.region = NULL; + if(x11_stuff.region) { + XDestroyRegion(x11_stuff.region); + x11_stuff.region = NULL; } XCloseDisplay(display); display = NULL; @@ -1540,10 +1578,10 @@ void clean_up(conky_context *ctx, void *memtofree1, void *memtofree2) free(ctx->info.x11.desktop.name); ctx->info.x11.desktop.name = NULL; } - ctx->x_initialised = NO; + x_initialised = NO; } else { free(ctx->fonts); //in set_default_configurations a font is set but not loaded - ctx->font_count = -1; + font_count = -1; } #endif /* X11 */ @@ -1700,11 +1738,11 @@ void set_default_configurations(conky_context *ctx) char *mpd_env_port; #endif ctx->text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE; - update_uname(ctx); + update_uname(); ctx->info.cpu_avg_samples = 2; ctx->info.net_avg_samples = 2; ctx->info.diskio_avg_samples = 2; - ctx->format_human_readable = 1; + format_human_readable = 1; #ifdef MPD mpd_env_host = getenv("MPD_HOST"); mpd_env_port = getenv("MPD_PORT"); @@ -1747,7 +1785,7 @@ void set_default_configurations(conky_context *ctx) ctx->info.xmms2.status = NULL; ctx->info.xmms2.playlist = NULL; #endif - ctx->use_spacer = NO_SPACER; + use_spacer = NO_SPACER; #ifdef X11 ctx->output_methods = TO_X; #else @@ -1768,23 +1806,23 @@ void set_default_configurations(conky_context *ctx) maximum_width = 0; #ifdef OWN_WINDOW own_window = 0; - ctx->window.type = TYPE_NORMAL; - ctx->window.hints = 0; - strcpy(ctx->window.class_name, PACKAGE_NAME); - sprintf(ctx->window.title, PACKAGE_NAME" (%s)", ctx->info.uname_s.nodename); + window.type = TYPE_NORMAL; + window.hints = 0; + strcpy(window.class_name, PACKAGE_NAME); + sprintf(window.title, PACKAGE_NAME" (%s)", ctx->info.uname_s.nodename); #endif stippled_borders = 0; - ctx->window.border_inner_margin = 3; - ctx->window.border_outer_margin = 1; - ctx->window.border_width = 1; + window.border_inner_margin = 3; + window.border_outer_margin = 1; + window.border_width = 1; text_alignment = BOTTOM_LEFT; ctx->info.x11.monitor.number = 1; ctx->info.x11.monitor.current = 0; - ctx->info.x11.desktop.current = 1; + ctx->info.x11.desktop.current = 1; ctx->info.x11.desktop.number = 1; ctx->info.x11.desktop.nitems = 0; - ctx->info.x11.desktop.all_names = NULL; - ctx->info.x11.desktop.name = NULL; + ctx->info.x11.desktop.all_names = NULL; + ctx->info.x11.desktop.name = NULL; #endif /* X11 */ for (i = 0; i < MAX_TEMPLATES; i++) { @@ -1804,8 +1842,8 @@ void set_default_configurations(conky_context *ctx) } no_buffers = 1; - set_update_interval(ctx, 3); - ctx->update_interval_bat = NOBATTERY; + set_update_interval(3); + update_interval_bat = NOBATTERY; ctx->info.music_player_interval = 1.0; stuff_in_uppercase = 0; ctx->info.users.number = 1; @@ -1871,11 +1909,11 @@ int x11_ioerror_handler(Display *d) static void X11_initialisation(conky_context *ctx) { - if (ctx->x_initialised == YES) return; + if (x_initialised == YES) return; ctx->output_methods |= TO_X; init_X11(disp); set_default_configurations_for_x(); - ctx->x_initialised = YES; + x_initialised = YES; #ifdef DEBUG _Xdebug = 1; /* WARNING, this type not in Xlib spec */ @@ -1888,25 +1926,25 @@ void X11_create_window(conky_context *ctx) { if (ctx->output_methods & TO_X) { #ifdef OWN_WINDOW - init_window(own_window, ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, - ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, set_transparent, background_colour, + 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, ctx->xargv, ctx->xargc); #else /* OWN_WINDOW */ - init_window(0, ctx->text_width + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, - ctx->text_height + ctx->window.border_inner_margin * 2 + ctx->window.border_outer_margin * 2 + ctx->window.border_width * 2, set_transparent, 0, + 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, ctx->xargv, ctx->xargc); #endif /* OWN_WINDOW */ - setup_fonts(ctx); - load_fonts(ctx); - update_text_area(ctx); /* to position text/window on screen */ + setup_fonts(); + load_fonts(); + update_text_area(); /* to position text/window on screen */ #ifdef OWN_WINDOW if (own_window && !fixed_pos) { - XMoveWindow(display, ctx->window.window, ctx->window.x, ctx->window.y); + XMoveWindow(display, window.window, window.x, window.y); } if (own_window) { - set_transparent_background(ctx->window.window); + set_transparent_background(window.window); } #endif @@ -1914,14 +1952,14 @@ void X11_create_window(conky_context *ctx) draw_stuff(); - ctx->window.region = XCreateRegion(); + x11_stuff.region = XCreateRegion(); #ifdef HAVE_XDAMAGE - if (!XDamageQueryExtension(display, &ctx->window.event_base, &ctx->window.error_base)) { + if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) { NORM_ERR("Xdamage extension unavailable"); } - ctx->window.damage = XDamageCreate(display, ctx->window.window, XDamageReportNonEmpty); - ctx->window.region2 = XFixesCreateRegionFromWindow(display, ctx->window.window, 0); - ctx->window.part = XFixesCreateRegionFromWindow(display, ctx->window.window, 0); + x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty); + x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0); + x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0); #endif /* HAVE_XDAMAGE */ ctx->selected_font = 0; @@ -1929,7 +1967,7 @@ void X11_create_window(conky_context *ctx) } #ifdef HAVE_LUA /* setup lua window globals */ - llua_setup_window_table(ctx->text_start_x, ctx->text_start_y, ctx->text_width, ctx->text_height); + llua_setup_window_table(text_start_x, text_start_y, text_width, text_height); #endif /* HAVE_LUA */ } #endif /* X11 */ @@ -2028,17 +2066,17 @@ char load_config_file(conky_context *ctx, const char *f) CONF2("out_to_x") { /* don't listen if X is already initialised or * if we already know we don't want it */ - if(ctx->x_initialised != YES) { + if(x_initialised != YES) { if (string_to_bool(value)) { ctx->output_methods &= TO_X; } else { ctx->output_methods &= ~TO_X; - ctx->x_initialised = NEVER; + x_initialised = NEVER; } } } CONF("display") { - if (!value || ctx->x_initialised == YES) { + if (!value || x_initialised == YES) { CONF_ERR; } else { if (disp) @@ -2048,7 +2086,7 @@ char load_config_file(conky_context *ctx, const char *f) } CONF("alignment") { #ifdef OWN_WINDOW - if (ctx->window.type == TYPE_DOCK) + if (window.type == TYPE_DOCK) ; else #endif /*OWN_WINDOW */ @@ -2081,24 +2119,24 @@ char load_config_file(conky_context *ctx, const char *f) } CONF("border_inner_margin") { if (value) { - ctx->window.border_inner_margin = strtol(value, 0, 0); - if (ctx->window.border_inner_margin < 0) ctx->window.border_inner_margin = 0; + window.border_inner_margin = strtol(value, 0, 0); + if (window.border_inner_margin < 0) window.border_inner_margin = 0; } else { CONF_ERR; } } CONF("border_outer_margin") { if (value) { - ctx->window.border_outer_margin = strtol(value, 0, 0); - if (ctx->window.border_outer_margin < 0) ctx->window.border_outer_margin = 0; + window.border_outer_margin = strtol(value, 0, 0); + if (window.border_outer_margin < 0) window.border_outer_margin = 0; } else { CONF_ERR; } } CONF("border_width") { if (value) { - ctx->window.border_width = strtol(value, 0, 0); - if (ctx->window.border_width < 0) ctx->window.border_width = 0; + window.border_width = strtol(value, 0, 0); + if (window.border_width < 0) window.border_width = 0; } else { CONF_ERR; } @@ -2282,7 +2320,7 @@ char load_config_file(conky_context *ctx, const char *f) } } CONF("extra_newline") { - ctx->extra_newline = string_to_bool(value); + extra_newline = string_to_bool(value); } CONF("out_to_stderr") { if(string_to_bool(value)) @@ -2322,27 +2360,27 @@ char load_config_file(conky_context *ctx, const char *f) CONF("use_spacer") { if (value) { if (strcasecmp(value, "left") == EQUAL) { - ctx->use_spacer = LEFT_SPACER; + use_spacer = LEFT_SPACER; } else if (strcasecmp(value, "right") == EQUAL) { - ctx->use_spacer = RIGHT_SPACER; + use_spacer = RIGHT_SPACER; } else if (strcasecmp(value, "none") == EQUAL) { - ctx->use_spacer = NO_SPACER; + use_spacer = NO_SPACER; } else { - ctx->use_spacer = string_to_bool(value); + use_spacer = string_to_bool(value); NORM_ERR("use_spacer should have an argument of left, right, or" " none. '%s' seems to be some form of '%s', so" " defaulting to %s.", value, - ctx->use_spacer ? "true" : "false", - ctx->use_spacer ? "right" : "none"); - if (ctx->use_spacer) { - ctx->use_spacer = RIGHT_SPACER; + use_spacer ? "true" : "false", + use_spacer ? "right" : "none"); + if (use_spacer) { + use_spacer = RIGHT_SPACER; } else { - ctx->use_spacer = NO_SPACER; + use_spacer = NO_SPACER; } } } else { NORM_ERR("use_spacer should have an argument. Defaulting to right."); - ctx->use_spacer = RIGHT_SPACER; + use_spacer = RIGHT_SPACER; } } #ifdef X11 @@ -2356,7 +2394,7 @@ char load_config_file(conky_context *ctx, const char *f) } } CONF("xftalpha") { - if (value && ctx->font_count >= 0) { + if (value && font_count >= 0) { ctx->fonts[0].font_alpha = atof(value) * 65535.0; } } @@ -2459,7 +2497,7 @@ char load_config_file(conky_context *ctx, const char *f) short_units = string_to_bool(value); } CONF("format_human_readable") { - ctx->format_human_readable = string_to_bool(value); + format_human_readable = string_to_bool(value); } CONF("pad_percents") { pad_percents = atoi(value); @@ -2473,15 +2511,15 @@ char load_config_file(conky_context *ctx, const char *f) } CONF("own_window_class") { if (value) { - memset(ctx->window.class_name, 0, sizeof(ctx->window.class_name)); - strncpy(ctx->window.class_name, value, - sizeof(ctx->window.class_name) - 1); + memset(window.class_name, 0, sizeof(window.class_name)); + strncpy(window.class_name, value, + sizeof(window.class_name) - 1); } } CONF("own_window_title") { if (value) { - memset(ctx->window.title, 0, sizeof(ctx->window.title)); - strncpy(ctx->window.title, value, sizeof(ctx->window.title) - 1); + memset(window.title, 0, sizeof(window.title)); + strncpy(window.title, value, sizeof(window.title) - 1); } } CONF("own_window_transparent") { @@ -2499,17 +2537,17 @@ char load_config_file(conky_context *ctx, const char *f) do { /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */ if (strncmp(p_hint, "undecorate", 10) == EQUAL) { - SET_HINT(ctx->window.hints, HINT_UNDECORATED); + SET_HINT(window.hints, HINT_UNDECORATED); } else if (strncmp(p_hint, "below", 5) == EQUAL) { - SET_HINT(ctx->window.hints, HINT_BELOW); + SET_HINT(window.hints, HINT_BELOW); } else if (strncmp(p_hint, "above", 5) == EQUAL) { - SET_HINT(ctx->window.hints, HINT_ABOVE); + SET_HINT(window.hints, HINT_ABOVE); } else if (strncmp(p_hint, "sticky", 6) == EQUAL) { - SET_HINT(ctx->window.hints, HINT_STICKY); + SET_HINT(window.hints, HINT_STICKY); } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) { - SET_HINT(ctx->window.hints, HINT_SKIP_TASKBAR); + SET_HINT(window.hints, HINT_SKIP_TASKBAR); } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) { - SET_HINT(ctx->window.hints, HINT_SKIP_PAGER); + SET_HINT(window.hints, HINT_SKIP_PAGER); } else { CONF_ERR; } @@ -2524,16 +2562,16 @@ char load_config_file(conky_context *ctx, const char *f) CONF("own_window_type") { if (value) { if (strncmp(value, "normal", 6) == EQUAL) { - ctx->window.type = TYPE_NORMAL; + window.type = TYPE_NORMAL; } else if (strncmp(value, "desktop", 7) == EQUAL) { - ctx->window.type = TYPE_DESKTOP; + window.type = TYPE_DESKTOP; } else if (strncmp(value, "dock", 4) == EQUAL) { - ctx->window.type = TYPE_DOCK; + window.type = TYPE_DOCK; text_alignment = TOP_LEFT; } else if (strncmp(value, "panel", 5) == EQUAL) { - ctx->window.type = TYPE_PANEL; + window.type = TYPE_PANEL; } else if (strncmp(value, "override", 8) == EQUAL) { - ctx->window.type = TYPE_OVERRIDE; + window.type = TYPE_OVERRIDE; } else { CONF_ERR; } @@ -2564,19 +2602,19 @@ char load_config_file(conky_context *ctx, const char *f) #endif /* X11 */ CONF("update_interval_on_battery") { if (value) { - ctx->update_interval_bat = strtod(value, 0); + update_interval_bat = strtod(value, 0); } else { CONF_ERR; } } CONF("update_interval") { if (value) { - set_update_interval(ctx, strtod(value, 0)); + set_update_interval(strtod(value, 0)); } else { CONF_ERR; } if (ctx->info.music_player_interval == 0) { - // default to ctx->update_interval + // default to update_interval ctx->info.music_player_interval = ctx->update_interval; } } @@ -2773,7 +2811,7 @@ char load_config_file(conky_context *ctx, const char *f) fclose(fp); if (ctx->info.music_player_interval == 0) { - // default to ctx->update_interval + // default to update_interval ctx->info.music_player_interval = ctx->update_interval; } if (!global_text) { // didn't supply any text @@ -2805,7 +2843,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) CONF2("color0") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color0 = get_x11_color(value); } else { @@ -2815,7 +2853,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color1") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color1 = get_x11_color(value); } else { @@ -2825,7 +2863,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color2") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color2 = get_x11_color(value); } else { @@ -2835,7 +2873,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color3") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color3 = get_x11_color(value); } else { @@ -2845,7 +2883,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color4") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color4 = get_x11_color(value); } else { @@ -2855,7 +2893,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color5") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color5 = get_x11_color(value); } else { @@ -2865,7 +2903,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color6") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color6 = get_x11_color(value); } else { @@ -2875,7 +2913,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color7") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color7 = get_x11_color(value); } else { @@ -2885,7 +2923,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color8") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color8 = get_x11_color(value); } else { @@ -2895,7 +2933,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("color9") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { color9 = get_x11_color(value); } else { @@ -2905,7 +2943,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF("default_color") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { default_fg_color = get_x11_color(value); } else { @@ -2915,7 +2953,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF3("default_shade_color", "default_shadecolor") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { default_bg_color = get_x11_color(value); } else { @@ -2925,7 +2963,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) } CONF3("default_outline_color", "default_outlinecolor") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { default_out_color = get_x11_color(value); } else { @@ -2936,7 +2974,7 @@ void load_config_file_x11(conky_context *ctx, const char *f) #ifdef OWN_WINDOW CONF("own_window_colour") { X11_initialisation(); - if (ctx->x_initialised == YES) { + if (x_initialised == YES) { if (value) { background_colour = get_x11_color(value); } else { diff --git a/src/core.h b/src/core.h index 7d246bb..436122b 100644 --- a/src/core.h +++ b/src/core.h @@ -60,7 +60,7 @@ enum alignment { void read_exec(const char *data, char *buf, const int size); void set_default_configurations(conky_context *ctx); -void set_update_interval(conky_context *ctx, double interval); +void set_update_interval(double interval); /* update_text() generates new text and clears old text area */ void update_text(conky_context *ctx); @@ -78,8 +78,4 @@ void X11_create_window(conky_context *ctx); void convert_escapes(char *buf); -void reload_config(conky_context *ctx); - -void clean_up(conky_context *ctx, void *memtofree1, void *memtofree2); - #endif /* _CONKY_CORE_H_ */ diff --git a/src/fonts.c b/src/fonts.c index 41e2b87..a31e563 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -29,26 +29,31 @@ * */ #include "conky.h" -#include "ctx->fonts.h" +#include "fonts.h" #include "logging.h" -void set_font(conky_context *ctx) +int selected_font = 0; +int font_count = -1; +struct font_list *fonts = NULL; +char fontloaded = 0; + +void set_font(void) { #ifdef XFT - if (use_xft->ctx) return; + if (use_xft) return; #endif /* XFT */ - if (ctx->font_count > -1 && ctx->fonts[selected_font].font) { - XSetFont(display, window.gc, ctx->fonts[selected_font].font->fid); + if (font_count > -1 && fonts[selected_font].font) { + XSetFont(display, window.gc, fonts[selected_font].font->fid); } } -void setup_fonts(conky_context *ctx) +void setup_fonts(void) { if ((output_methods & TO_X) == 0) { return; } #ifdef XFT - if (use_xft->ctx) { + if (use_xft) { if (window.xftdraw) { XftDrawDestroy(window.xftdraw); window.xftdraw = 0; @@ -60,89 +65,89 @@ void setup_fonts(conky_context *ctx) set_font(); } -int add_font(conky_context *ctx, const char *data_in) +int add_font(const char *data_in) { if ((output_methods & TO_X) == 0) { return 0; } - if (ctx->font_count > MAX_FONTS) { - CRIT_ERR(NULL, NULL, "you don't need that many ctx->fonts, sorry."); + if (font_count > MAX_FONTS) { + CRIT_ERR(NULL, NULL, "you don't need that many fonts, sorry."); } - ctx->font_count++; - if (ctx->font_count == 0) { - if (ctx->fonts != NULL) { - free(ctx->fonts); + font_count++; + if (font_count == 0) { + if (fonts != NULL) { + free(fonts); } - if ((ctx->fonts = (struct font_list *) malloc(sizeof(struct font_list))) + if ((fonts = (struct font_list *) malloc(sizeof(struct font_list))) == NULL) { CRIT_ERR(NULL, NULL, "malloc"); } - memset(ctx->fonts, 0, sizeof(struct font_list)); + memset(fonts, 0, sizeof(struct font_list)); } - ctx->fonts = realloc(ctx->fonts, (sizeof(struct font_list) * (ctx->font_count + 1))); - memset(&ctx->fonts[ctx->font_count], 0, sizeof(struct font_list)); - if (ctx->fonts == NULL) { + fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1))); + memset(&fonts[font_count], 0, sizeof(struct font_list)); + if (fonts == NULL) { CRIT_ERR(NULL, NULL, "realloc in add_font"); } // must account for null terminator if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) { - strncpy(ctx->fonts[ctx->font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE); + strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE); #ifdef XFT - ctx->fonts[ctx->font_count].font_alpha = 0xffff; + fonts[font_count].font_alpha = 0xffff; #endif } else { CRIT_ERR(NULL, NULL, "Oops...looks like something overflowed in add_font()."); } - return ctx->font_count; + return font_count; } -void set_first_font(conky_context *ctx, const char *data_in) +void set_first_font(const char *data_in) { if ((output_methods & TO_X) == 0) { return; } - if (ctx->font_count < 0) { - if ((ctx->fonts = (struct font_list *) malloc(sizeof(struct font_list))) + if (font_count < 0) { + if ((fonts = (struct font_list *) malloc(sizeof(struct font_list))) == NULL) { CRIT_ERR(NULL, NULL, "malloc"); } - memset(ctx->fonts, 0, sizeof(struct font_list)); - ctx->font_count++; + memset(fonts, 0, sizeof(struct font_list)); + font_count++; } if (strlen(data_in) > 1) { - strncpy(ctx->fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE); + strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE); #ifdef XFT - ctx->fonts[0].font_alpha = 0xffff; + fonts[0].font_alpha = 0xffff; #endif } } -void free_fonts(conky_context *ctx) +void free_fonts(void) { int i; if ((output_methods & TO_X) == 0) { return; } - if(ctx->fontloaded == 0) { - free(ctx->fonts); + if(fontloaded == 0) { + free(fonts); return; } - for (i = 0; i <= ctx->font_count; i++) { + for (i = 0; i <= font_count; i++) { #ifdef XFT - if (use_xft->ctx) { - XftFontClose(display, ctx->fonts[i].xftfont); - ctx->fonts[i].xftfont = 0; + if (use_xft) { + XftFontClose(display, fonts[i].xftfont); + fonts[i].xftfont = 0; } else #endif /* XFT */ { - XFreeFont(display, ctx->fonts[i].font); - ctx->fonts[i].font = 0; + XFreeFont(display, fonts[i].font); + fonts[i].font = 0; } } - free(ctx->fonts); - ctx->fonts = 0; - ctx->font_count = -1; + free(fonts); + fonts = 0; + font_count = -1; selected_font = 0; #ifdef XFT if (window.xftdraw) { @@ -152,47 +157,47 @@ void free_fonts(conky_context *ctx) #endif /* XFT */ } -void load_fonts(conky_context *ctx) +void load_fonts(void) { int i; if ((output_methods & TO_X) == 0) return; - for (i = 0; i <= ctx->font_count; i++) { + for (i = 0; i <= font_count; i++) { #ifdef XFT /* load Xft font */ - if (use_xft->ctx && ctx->fonts[i].xftfont) { + if (use_xft && fonts[i].xftfont) { continue; - } else if (use_xft->ctx) { - ctx->fonts[i].xftfont = XftFontOpenName(display, screen, - ctx->fonts[i].name); - if (ctx->fonts[i].xftfont) { + } else if (use_xft) { + fonts[i].xftfont = XftFontOpenName(display, screen, + fonts[i].name); + if (fonts[i].xftfont) { continue; } - NORM_ERR("can't load Xft font '%s'", ctx->fonts[i].name); - if ((ctx->fonts[i].xftfont = XftFontOpenName(display, screen, + NORM_ERR("can't load Xft font '%s'", fonts[i].name); + if ((fonts[i].xftfont = XftFontOpenName(display, screen, "courier-12")) != NULL) { continue; } NORM_ERR("can't load Xft font '%s'", "courier-12"); - if ((ctx->fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { + if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); } - use_xft->ctx = 0; + use_xft = 0; continue; } #endif /* load normal font */ - if (!ctx->fonts[i].font && (ctx->fonts[i].font = XLoadQueryFont(display, ctx->fonts[i].name)) == NULL) { - NORM_ERR("can't load font '%s'", ctx->fonts[i].name); - if ((ctx->fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { + if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) { + NORM_ERR("can't load font '%s'", fonts[i].name); + if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); } } } - ctx->fontloaded = 1; + fontloaded = 1; } diff --git a/src/fonts.h b/src/fonts.h index 01e222b..7de377c 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -34,33 +34,33 @@ #ifdef XFT -#define font_height() (use_xft ? (ctx->fonts[ctx->selected_font].xftfont->ascent + \ - ctx->fonts[ctx->selected_font].xftfont->descent) \ - : (ctx->fonts[ctx->selected_font].font->max_bounds.ascent + \ - ctx->fonts[ctx->selected_font].font->max_bounds.descent)) -#define font_ascent() (use_xft ? ctx->fonts[ctx->selected_font].xftfont->ascent \ - : ctx->fonts[ctx->selected_font].font->max_bounds.ascent) -#define font_descent() (use_xft ? ctx->fonts[ctx->selected_font].xftfont->descent \ - : ctx->fonts[ctx->selected_font].font->max_bounds.descent) +#define font_height() (use_xft ? (fonts[ctx->selected_font].xftfont->ascent + \ + fonts[ctx->selected_font].xftfont->descent) \ + : (fonts[ctx->selected_font].font->max_bounds.ascent + \ + fonts[ctx->selected_font].font->max_bounds.descent)) +#define font_ascent() (use_xft ? fonts[ctx->selected_font].xftfont->ascent \ + : fonts[ctx->selected_font].font->max_bounds.ascent) +#define font_descent() (use_xft ? fonts[ctx->selected_font].xftfont->descent \ + : fonts[ctx->selected_font].font->max_bounds.descent) #else -#define font_height() (ctx->fonts[ctx->selected_font].font->max_bounds.ascent + \ - ctx->fonts[ctx->selected_font].font->max_bounds.descent) -#define font_ascent() ctx->fonts[ctx->selected_font].font->max_bounds.ascent -#define font_descent() ctx->fonts[ctx->selected_font].font->max_bounds.descent +#define font_height() (fonts[ctx->selected_font].font->max_bounds.ascent + \ + fonts[ctx->selected_font].font->max_bounds.descent) +#define font_ascent() fonts[ctx->selected_font].font->max_bounds.ascent +#define font_descent() fonts[ctx->selected_font].font->max_bounds.descent #endif #define MAX_FONTS 256 -void setup_fonts(conky_context *ctx); -void set_font(conky_context *ctx); -int add_font(conky_context *ctx, const char *); -void set_first_font(conky_context *ctx, const char *); -void free_fonts(conky_context *ctx); -void load_fonts(conky_context *ctx); +void setup_fonts(void); +void set_font(void); +int add_font(const char *); +void set_first_font(const char *); +void free_fonts(void); +void load_fonts(void); #endif /* _FONTS_H */ #endif /* X11 */ diff --git a/src/logging.h b/src/logging.h index 392edf9..8916ff9 100644 --- a/src/logging.h +++ b/src/logging.h @@ -27,6 +27,8 @@ * */ +void clean_up(void *memtofree1, void* memtofree2); + #ifndef _LOGGING_H #define _LOGGING_H @@ -37,8 +39,8 @@ } /* critical error */ -#define CRIT_ERR(ctx, memtofree1, memtofree2, ...) \ - { NORM_ERR(__VA_ARGS__); clean_up(ctx, memtofree1, memtofree2); exit(EXIT_FAILURE); } +#define CRIT_ERR(memtofree1, memtofree2, ...) \ + { NORM_ERR(__VA_ARGS__); clean_up(memtofree1, memtofree2); exit(EXIT_FAILURE); } /* debugging output */ extern int global_debug_level; diff --git a/src/obj_create.h b/src/obj_create.h index 1bd0215..c1ac6e8 100644 --- a/src/obj_create.h +++ b/src/obj_create.h @@ -41,6 +41,8 @@ size_t remove_comments(char *string); int extract_variable_text_internal(struct text_object *retval, const char *const_p); +void free_text_objects(struct text_object *root, int internal); + #ifdef X11 void scan_mixer_bar(const char *arg, int *a, int *w, int *h); #endif /* X11 */ diff --git a/src/obj_display.c b/src/obj_display.c index 03d1677..adeb0c7 100644 --- a/src/obj_display.c +++ b/src/obj_display.c @@ -275,57 +275,10 @@ void evaluate(const char *text, char *buffer) free(tmp_info); } -static struct mail_s *ensure_mail_thread(conky_context *ctx, struct text_object *obj, - void *thread(void *), const char *text) -{ - if (obj->char_b && ctx->info.mail) { - /* this means we use ctx->info */ - if (!ctx->info.mail->p_timed_thread) { - ctx->info.mail->p_timed_thread = - timed_thread_create(thread, - (void *) ctx->info.mail, ctx->info.mail->interval * 1000000); - if (!ctx->info.mail->p_timed_thread) { - NORM_ERR("Error creating %s timed thread", text); - } - timed_thread_register(ctx->info.mail->p_timed_thread, - &ctx->info.mail->p_timed_thread); - if (timed_thread_run(ctx->info.mail->p_timed_thread)) { - NORM_ERR("Error running %s timed thread", text); - } - } - return ctx->info.mail; - } else if (obj->data.mail) { - // this means we use obj - if (!obj->data.mail->p_timed_thread) { - obj->data.mail->p_timed_thread = - timed_thread_create(thread, - (void *) obj->data.mail, - obj->data.mail->interval * 1000000); - if (!obj->data.mail->p_timed_thread) { - NORM_ERR("Error creating %s timed thread", text); - } - timed_thread_register(obj->data.mail->p_timed_thread, - &obj->data.mail->p_timed_thread); - if (timed_thread_run(obj->data.mail->p_timed_thread)) { - NORM_ERR("Error running %s timed thread", text); - } - } - return obj->data.mail; - } else if (!obj->a) { - // something is wrong, warn once then stop - NORM_ERR("There's a problem with your mail settings. " - "Check that the global mail settings are properly defined" - " (line %li).", obj->line); - obj->a++; - } - return NULL; -} - -void generate_text_internal(conky_context *ctx, char *p, int p_max_size, struct - text_object root) +void generate_text_internal(char *p, int p_max_size, struct text_object root, + struct information *cur) { struct text_object *obj; - struct information *cur = &ctx->info; #ifdef X11 int need_to_load_fonts = 0; #endif /* X11 */ @@ -1058,7 +1011,7 @@ void generate_text_internal(conky_context *ctx, char *p, int p_max_size, struct } } OBJ(imap_unseen) { - struct mail_s *mail = ensure_mail_thread(ctx, obj, imap_thread, "imap"); + struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap"); if (mail && mail->p_timed_thread) { timed_thread_lock(mail->p_timed_thread); @@ -1067,7 +1020,7 @@ void generate_text_internal(conky_context *ctx, char *p, int p_max_size, struct } } OBJ(imap_messages) { - struct mail_s *mail = ensure_mail_thread(ctx, obj, imap_thread, "imap"); + struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap"); if (mail && mail->p_timed_thread) { timed_thread_lock(mail->p_timed_thread); @@ -1076,7 +1029,7 @@ void generate_text_internal(conky_context *ctx, char *p, int p_max_size, struct } } OBJ(pop3_unseen) { - struct mail_s *mail = ensure_mail_thread(ctx, obj, pop3_thread, "pop3"); + struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3"); if (mail && mail->p_timed_thread) { timed_thread_lock(mail->p_timed_thread); @@ -1085,7 +1038,7 @@ void generate_text_internal(conky_context *ctx, char *p, int p_max_size, struct } } OBJ(pop3_used) { - struct mail_s *mail = ensure_mail_thread(ctx, obj, pop3_thread, "pop3"); + struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3"); if (mail && mail->p_timed_thread) { timed_thread_lock(mail->p_timed_thread); diff --git a/src/obj_display.h b/src/obj_display.h index 5860add..dd08a01 100644 --- a/src/obj_display.h +++ b/src/obj_display.h @@ -35,7 +35,7 @@ #include "conky.h" #include "text_object.h" -void generate_text_internal(conky_context *ctx, char *p, int p_max_size, struct - text_object root); +void generate_text_internal(char *p, int p_max_size, struct text_object root, + struct information *cur); #endif /* _CONKY_OBJ_DISPLAY_H_ */ diff --git a/src/structs.h b/src/structs.h index 2ec9762..b054aba 100644 --- a/src/structs.h +++ b/src/structs.h @@ -318,6 +318,7 @@ typedef struct _conky_context_s { short colour_depth; long redmask, greenmask, bluemask; + struct font_list *fonts; int font_count;