Skip to content

Commit

Permalink
Move saved_coordinates to imlib
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Apr 23, 2024
1 parent 3093cdd commit fecd1a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
14 changes: 9 additions & 5 deletions src/conky-imlib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct image_list_s {
};

struct image_list_s *image_list_start, *image_list_end;
std::array<std::array<int, 2>, 100> saved_coordinates;

/* areas to update */
Imlib_Updates updates, current_update;
Expand Down Expand Up @@ -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<size_t>(i));
cur->x = coordinates[0];
cur->y = coordinates[1];
}
}
if (cur->flush_interval < 0) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/conky-imlib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@
#include "setting.hh"
#include "text_object.h"

#include <array>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros"
#include <X11/Xlib.h>
#pragma GCC diagnostic pop

using saved_coordinates_t = std::array<std::array<int, 2>, 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);
Expand Down
16 changes: 5 additions & 11 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int>(current->arg)] =
cur_x - text_start_x;
saved_coordinates_y[static_cast<int>(current->arg)] =
cur_y - text_start_y - last_font_height;
saved_coordinates[static_cast<int>(current->arg)] =
std::array<int, 2>{cur_x - text_start_x,
cur_y - text_start_y - last_font_height};
break;

case text_node_t::TAB: {
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 0 additions & 3 deletions src/conky.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down

0 comments on commit fecd1a8

Please sign in to comment.