diff --git a/src/conky-imlib2.cc b/src/conky-imlib2.cc index f07ebe7518..88e764fe70 100644 --- a/src/conky-imlib2.cc +++ b/src/conky-imlib2.cc @@ -48,6 +48,7 @@ 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; @@ -160,8 +161,10 @@ 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) { 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); diff --git a/src/conky-imlib2.h b/src/conky-imlib2.h index 18336f6c14..826d2be955 100644 --- a/src/conky-imlib2.h +++ b/src/conky-imlib2.h @@ -27,15 +27,20 @@ #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); void cimlib_cleanup(void); void print_image_callback(struct text_object *, char *, unsigned int); diff --git a/src/conky.cc b/src/conky.cc index 2ebeff94ab..d72bc7f28d 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,9 @@ 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; + saved_coordinates[static_cast(current->arg)] = + std::array{cur_x - text_start_x, + cur_y - text_start_y - last_font_height}; break; case text_node_t::TAB: { @@ -1590,7 +1583,8 @@ 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)); #endif /* BUILD_IMLIB2 */ for (auto output : display_outputs()) { diff --git a/src/conky.h b/src/conky.h index bd2059a8f5..c7a357248e 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)));