1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-19 11:35:12 +00:00

lua-imlib2: move to conky style logging

Unfortunately we can't use logging.h directly from conky as its
in C++ and lua bindings only have access to a C compiler.

Instead we now have a very simple C implementation of logging.h to
use within the bindings.

This change also adds NULL checks to catch some extra invalid
states
This commit is contained in:
Simon Lees 2024-02-23 12:45:14 +10:30 committed by Brenden Matthews
parent 78a38db342
commit b79d465ed3
2 changed files with 19 additions and 6 deletions

View File

@ -44,7 +44,7 @@ if(BUILD_X11)
endif(BUILD_LUA_CAIRO) endif(BUILD_LUA_CAIRO)
if(BUILD_LUA_IMLIB2) if(BUILD_LUA_IMLIB2)
include_directories(${luaimlib2_includes} ${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${luaimlib2_includes} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
if(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0") if(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")
wrap_tolua(luaimlib2_src imlib2.pkg) wrap_tolua(luaimlib2_src imlib2.pkg)

View File

@ -28,6 +28,8 @@
#include <Imlib2.h> #include <Imlib2.h>
#include <cairo.h> #include <cairo.h>
#include "logging.h"
void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y, void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
double scale_x, double scale_y, double *return_scale_w, double scale_x, double scale_y, double *return_scale_w,
double *return_scale_h) { double *return_scale_h) {
@ -36,14 +38,25 @@ void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
Imlib_Image alpha, premul; Imlib_Image alpha, premul;
cairo_surface_t *result; cairo_surface_t *result;
cairo_t *cr; cairo_t *cr;
if (!file) {
NORM_ERR("cairoimagehelper: File is NULL\n");
return;
}
if (!cs) {
NORM_ERR("cairoimagehelper: Surface is NULL\n");
return;
}
Imlib_Image *image = imlib_load_image(file); Imlib_Image *image = imlib_load_image(file);
if (!image) { if (!image) {
printf("Error: CairoImageHelper: Couldn't load %s\n", file); NORM_ERR("cairoimagehelper: Couldn't load %s\n", file);
return; return;
} }
if ((scale_x <= 0.0) && (scale_y <= 0.0)) { if ((scale_x <= 0.0) && (scale_y <= 0.0)) {
printf("Error: CairoImageHelper: Image Scale is 0, %s\n", file); NORM_ERR("cairoimagehelper: Image Scale is 0, %s\n", file);
return; return;
} }
@ -52,7 +65,7 @@ void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
h = imlib_image_get_height(); h = imlib_image_get_height();
if ((w <= 0) && (h <= 0)) { if ((w <= 0) && (h <= 0)) {
printf("Error: CairoImageHelper: %s has 0 size\n", file); NORM_ERR("cairoimagehelper: %s has 0 size\n", file);
return; return;
} }
@ -60,7 +73,7 @@ void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
scaled_h = *return_scale_h = scale_y * (double)h; scaled_h = *return_scale_h = scale_y * (double)h;
if ((scaled_w <= 0.0) && (scaled_h <= 0.0)) { if ((scaled_w <= 0.0) && (scaled_h <= 0.0)) {
printf("Error: CairoImageHelper: %s scaled image has 0 size\n", file); NORM_ERR("cairoimagehelper: %s scaled image has 0 size\n", file);
return; return;
} }
@ -70,7 +83,7 @@ void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
/* create temporary image */ /* create temporary image */
premul = imlib_create_image(scaled_w, scaled_h); premul = imlib_create_image(scaled_w, scaled_h);
if (!premul) { if (!premul) {
printf("Error: CairoImageHelper: Couldn't create premul image for %s\n", file); NORM_ERR("cairoimagehelper: Couldn't create premul image for %s\n", file);
return; return;
} }