Skip to content

Commit

Permalink
Move saved_coordinates to imlib
Browse files Browse the repository at this point in the history
Hide lua state from conky-imlib2.cc

Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Apr 23, 2024
1 parent 3093cdd commit 8e07629
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
26 changes: 15 additions & 11 deletions src/conky-imlib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ 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;
/* our virtual framebuffer image we draw into */
Imlib_Image buffer, image;

namespace {
Imlib_Context context;

conky::range_config_setting<unsigned int> imlib_cache_flush_interval(
"imlib_cache_flush_interval", 0, std::numeric_limits<unsigned int>::max(),
0, true);

unsigned int cimlib_cache_flush_last = 0;
conky::simple_config_setting<bool> imlib_draw_blended("draw_blended", true,
true);

conky::simple_config_setting<bool> 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) {
Expand Down Expand Up @@ -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<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,
bool draw_blended) {
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 All @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion src/conky-imlib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
#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,
bool draw_blended);
void cimlib_cleanup(void);

void print_image_callback(struct text_object *, char *, unsigned int);
Expand All @@ -54,4 +60,7 @@ class imlib_cache_size_setting
4096 * 1024, true) {}
};

extern conky::range_config_setting<unsigned int> imlib_cache_flush_interval;
extern conky::simple_config_setting<bool> imlib_draw_blended;

#endif /* _CONKY_IMBLI2_H_ */
19 changes: 8 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,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<int>(current->arg)] =
cur_x - text_start_x;
saved_coordinates_y[static_cast<int>(current->arg)] =
cur_y - text_start_y - last_font_height;
#ifdef BUILD_IMLIB2
saved_coordinates[static_cast<int>(current->arg)] =
std::array<int, 2>{cur_x - text_start_x,
cur_y - text_start_y - last_font_height};
#endif /* BUILD_IMLIB2 */
break;

case text_node_t::TAB: {
Expand Down Expand Up @@ -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()) {
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 8e07629

Please sign in to comment.