diff --git a/src/conky-imlib2.cc b/src/conky-imlib2.cc index f07ebe751..0cc9d948e 100644 --- a/src/conky-imlib2.cc +++ b/src/conky-imlib2.cc @@ -48,22 +48,24 @@ struct image_list_s { }; struct image_list_s *image_list_start, *image_list_end; +std::array, 100> saved_coordinates; /* areas to update */ Imlib_Updates updates, current_update; /* our virtual framebuffer image we draw into */ Imlib_Image buffer, image; -namespace { -Imlib_Context context; - conky::range_config_setting imlib_cache_flush_interval( "imlib_cache_flush_interval", 0, std::numeric_limits::max(), 0, true); -unsigned int cimlib_cache_flush_last = 0; +conky::simple_config_setting imlib_draw_blended("draw_blended", true, + true); -conky::simple_config_setting draw_blended("draw_blended", true, true); +namespace { +Imlib_Context context; + +unsigned int cimlib_cache_flush_last = 0; } // namespace void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) { @@ -160,8 +162,9 @@ void cimlib_add_image(const char *args) { tmp += 3; int i; if (sscanf(tmp, "%d", &i) == 1) { - cur->x = get_saved_coordinates_x(i); - cur->y = get_saved_coordinates_y(i); + const auto &coordinates = saved_coordinates.at(static_cast(i)); + cur->x = coordinates[0]; + cur->y = coordinates[1]; } } if (cur->flush_interval < 0) { @@ -235,7 +238,8 @@ static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2, } } -void cimlib_render(int x, int y, int width, int height) { +void cimlib_render(int x, int y, int width, int height, uint32_t flush_interval, + bool draw_blended) { int clip_x = INT_MAX, clip_y = INT_MAX; int clip_x2 = 0, clip_y2 = 0; time_t now; @@ -246,8 +250,8 @@ void cimlib_render(int x, int y, int width, int height) { /* cheque if it's time to flush our cache */ now = time(nullptr); - if ((imlib_cache_flush_interval.get(*state) != 0u) && - now - imlib_cache_flush_interval.get(*state) > cimlib_cache_flush_last) { + if ((flush_interval != 0u) && + now - flush_interval > cimlib_cache_flush_last) { int size = imlib_get_cache_size(); imlib_set_cache_size(0); imlib_set_cache_size(size); @@ -263,7 +267,7 @@ void cimlib_render(int x, int y, int width, int height) { imlib_image_clear(); /* check if we should blend when rendering */ - if (draw_blended.get(*state)) { + if (draw_blended) { /* we can blend stuff now */ imlib_context_set_blend(1); } else { diff --git a/src/conky-imlib2.h b/src/conky-imlib2.h index 18336f6c1..11a166979 100644 --- a/src/conky-imlib2.h +++ b/src/conky-imlib2.h @@ -27,15 +27,21 @@ #include "setting.hh" #include "text_object.h" +#include + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvariadic-macros" #include #pragma GCC diagnostic pop +using saved_coordinates_t = std::array, 100>; +extern saved_coordinates_t saved_coordinates; + void cimlib_add_image(const char *args); void cimlib_set_cache_size(long size); void cimlib_set_cache_flush_interval(long interval); -void cimlib_render(int x, int y, int width, int height); +void cimlib_render(int x, int y, int width, int height, uint32_t flush_interval, + bool draw_blended); void cimlib_cleanup(void); void print_image_callback(struct text_object *, char *, unsigned int); @@ -54,4 +60,7 @@ class imlib_cache_size_setting 4096 * 1024, true) {} }; +extern conky::range_config_setting imlib_cache_flush_interval; +extern conky::simple_config_setting imlib_draw_blended; + #endif /* _CONKY_IMBLI2_H_ */ diff --git a/src/conky.cc b/src/conky.cc index 2ebeff94a..0681782b6 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -932,12 +932,6 @@ static draw_mode_t draw_mode; /* FG, BG or OUTLINE */ #ifdef BUILD_GUI /*static*/ Colour current_color; -static int saved_coordinates_x[100]; -static int saved_coordinates_y[100]; - -int get_saved_coordinates_x(int i) { return saved_coordinates_x[i]; } -int get_saved_coordinates_y(int i) { return saved_coordinates_y[i]; } - static int text_size_updater(char *s, int special_index) { int w = 0; char *p; @@ -1447,10 +1441,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { break; case text_node_t::SAVE_COORDINATES: - saved_coordinates_x[static_cast(current->arg)] = - cur_x - text_start_x; - saved_coordinates_y[static_cast(current->arg)] = - cur_y - text_start_y - last_font_height; +#ifdef BUILD_IMLIB2 + saved_coordinates[static_cast(current->arg)] = + std::array{cur_x - text_start_x, + cur_y - text_start_y - last_font_height}; +#endif /* BUILD_IMLIB2 */ break; case text_node_t::TAB: { @@ -1590,7 +1585,9 @@ void draw_stuff() { #ifdef BUILD_IMLIB2 text_offset_x = text_offset_y = 0; - cimlib_render(text_start_x, text_start_y, window.width, window.height); + cimlib_render(text_start_x, text_start_y, window.width, window.height, + imlib_cache_flush_interval.get(*state), + imlib_draw_blended.get(*state)); #endif /* BUILD_IMLIB2 */ for (auto output : display_outputs()) { diff --git a/src/conky.h b/src/conky.h index bd2059a8f..c7a357248 100644 --- a/src/conky.h +++ b/src/conky.h @@ -314,9 +314,6 @@ void set_updatereset(int); int get_updatereset(void); int get_total_updates(void); -int get_saved_coordinates_x(int); -int get_saved_coordinates_y(int); - /* defined in conky.c */ int spaced_print(char *, int, const char *, int, ...) __attribute__((format(printf, 3, 5)));