From c1ef8c5cd4d8189400a0bf3feff46d63ea374f2c Mon Sep 17 00:00:00 2001 From: Dan McCombs Date: Sun, 2 Dec 2018 11:29:33 -0500 Subject: [PATCH] Add config option to disable blending (#682) * Add config option to disable blending This is intended to work around issues with some images blending incorrectly with ARGB visuals. * Fix order of config documentation. * Update configuration variable name to simply "draw_blended". * Fix for SonarCloud malloc warning. * Update free to delete as part of malloc change. --- doc/config_settings.xml | 12 ++++++++++++ src/imlib2.cc | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/doc/config_settings.xml b/doc/config_settings.xml index feda906f..59ec4c47 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -254,6 +254,18 @@ double buffer won't be so big. + + + + + + + Boolean, blend when rendering drawn image? + Some images blend incorrectly breaking alpha with ARBG visuals. This + provides a possible work around by disabling blending. Defaults to + true. + + diff --git a/src/imlib2.cc b/src/imlib2.cc index c64bb53c..a92c7978 100644 --- a/src/imlib2.cc +++ b/src/imlib2.cc @@ -61,6 +61,9 @@ conky::range_config_setting imlib_cache_flush_interval( 0, true); unsigned int cimlib_cache_flush_last = 0; + +conky::simple_config_setting draw_blended( + "draw_blended", true, true); } // namespace void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) { @@ -112,7 +115,7 @@ void cimlib_add_image(const char *args) { struct image_list_s *cur = nullptr; const char *tmp; - cur = static_cast(malloc(sizeof(struct image_list_s))); + cur = new struct image_list_s[sizeof(struct image_list_s)]; memset(cur, 0, sizeof(struct image_list_s)); if (sscanf(args, "%1023s", cur->name) == 0) { @@ -120,7 +123,7 @@ void cimlib_add_image(const char *args) { "Invalid args for $image. Format is: ' (-p" "x,y) (-s WxH) (-n) (-f interval)' (got '%s')", args); - free(cur); + delete [] cur; return; } strncpy(cur->name, to_real_path(cur->name).c_str(), 1024); @@ -259,8 +262,15 @@ void cimlib_render(int x, int y, int width, int height) { /* clear our buffer */ imlib_context_set_image(buffer); imlib_image_clear(); - /* we can blend stuff now */ - imlib_context_set_blend(1); + + /* check if we should blend when rendering */ + if (draw_blended.get(*state)) { + /* we can blend stuff now */ + imlib_context_set_blend(1); + } else { + imlib_context_set_blend(0); + } + /* turn alpha channel on */ imlib_image_set_has_alpha(1);