From aa9609b5cfdfa7492449c1fde074572ca7b51150 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 28 Mar 2010 15:41:54 +0200 Subject: [PATCH] Draw: Replace statustext_image by parse_color_block, remove image stuff in status.c (draw_text image stuff is sufficient) and update version --- CMakeLists.txt | 2 +- src/draw.c | 8 ++++---- src/status.c | 17 ++--------------- src/structs.h | 2 +- src/util.c | 26 ++++++++++++++++++++++++++ src/wmfs.h | 10 +++++----- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0824df..957292b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ set(wmfs_src add_executable(wmfs ${wmfs_src}) # Set the version -set(VERSION "WMFS-201002") +set(VERSION "WMFS-201003") # FLAGS set(CFLAGS "-g -Wall -ansi") diff --git a/src/draw.c b/src/draw.c index 6067ac5..a1fb357 100644 --- a/src/draw.c +++ b/src/draw.c @@ -53,11 +53,11 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str) #ifdef HAVE_IMLIB char *ostr = NULL; int i, ni; - StatusImage im[56]; + ImageAttr im[128]; ostr = _strdup(str); - ni = statustext_image(im, str); + ni = parse_image_block(im, str); for(i = 0; i < ni; ++i) draw_image(d, im[i].x, im[i].y, im[i].w, im[i].h, im[i].name); @@ -161,11 +161,11 @@ textw(char *text) #ifdef HAVE_IMLIB char *ostr = NULL; - StatusImage im[56]; + ImageAttr im[128]; ostr = _strdup(text); - statustext_image(im, text); + parse_image_block(im, text); #endif /* HAVE_IMLIB */ XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl); diff --git a/src/status.c b/src/status.c index f35cfff..4367e09 100644 --- a/src/status.c +++ b/src/status.c @@ -83,12 +83,12 @@ statustext_text(StatusText *s, char *str) #ifdef HAVE_IMLIB /** Check images blocks in str and return properties * --> \i[x;y;w;h;name]\ - *\param im StatusImage pointer, image properties + *\param im ImageAttr pointer, image properties *\param str String *\return n Lenght of i */ int -statustext_image(StatusImage *im, char *str) +statustext_image(ImageAttr *im, char *str) { char as; int n, i, j, k; @@ -188,13 +188,6 @@ statustext_handle(int sc, char *str) nr = statustext_rectangle(r, str); ns = statustext_text(s, str); -#ifdef HAVE_IMLIB - int ni; - StatusImage im[128]; - - ni = statustext_image(im, str); -#endif /* HAVE_IMLIB */ - /* Draw normal text (and possibly colored with \#color\ blocks) */ statustext_normal(sc, str); @@ -206,12 +199,6 @@ statustext_handle(int sc, char *str) for(i = 0; i < ns; ++i) draw_text(infobar[sc].bar->dr, s[i].x, s[i].y, s[i].color, 0, s[i].text); -#ifdef HAVE_IMLIB - /* Draw images with stored properties. */ - for(i = 0; i < ni; ++i) - draw_image(infobar[sc].bar->dr, im[i].x, im[i].y, im[i].w, im[i].h, im[i].name); -#endif /* HAVE_IMLIB */ - barwin_refresh(infobar[sc].bar); free(lastst); diff --git a/src/structs.h b/src/structs.h index 870f16c..e43a151 100644 --- a/src/structs.h +++ b/src/structs.h @@ -423,7 +423,7 @@ typedef struct { uint x, y, w, h; char name[512]; -} StatusImage; +} ImageAttr; /* Config.c struct */ typedef struct diff --git a/src/util.c b/src/util.c index 657d61b..4d334dc 100644 --- a/src/util.c +++ b/src/util.c @@ -264,3 +264,29 @@ uicb_spawn(uicb_t cmd) spawn("%s", cmd); } +#ifdef HAVE_IMLIB +/** Check images blocks in str and return properties + * --> \i[x;y;w;h;name]\ + *\param im ImageAttr pointer, image properties + *\param str String + *\return n Lenght of i + */ +int +parse_image_block(ImageAttr *im, char *str) +{ + char as; + int n, i, j, k; + + for(i = j = n = 0; i < strlen(str); ++i, ++j) + if(sscanf(&str[i], "\\i[%d;%d;%d;%d;%512[^]]]%c", &im[n].x, &im[n].y, &im[n].w, &im[n].h, im[n].name, &as) == 6 + && as == '\\') + for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i); + else if(j != i) + str[j] = str[i]; + + for(k = j; k < i; str[k++] = 0); + + return n; +} +#endif /* HAVE_IMLIB */ + diff --git a/src/wmfs.h b/src/wmfs.h index 069f213..a4ed4e8 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -273,6 +273,11 @@ void spawn(const char *str, ...); void swap_ptr(void **x, void **y); void uicb_spawn(uicb_t); +#ifdef HAVE_IMLIB +int parse_image_block(ImageAttr *im, char *str); +#endif /* HAVE_IMLIB */ + + /* tag.c */ void tag_set(int tag); void tag_transfert(Client *c, int tag); @@ -299,11 +304,6 @@ void uicb_screen_prev_sel(uicb_t); /* status.c */ int statustext_rectangle(StatusRec *r, char *str); int statustext_text(StatusText *s, char *str); - -#ifdef HAVE_IMLIB -int statustext_image(StatusImage *im, char *str); -#endif /* HAVE_IMLIB */ - void statustext_normal(int sc, char *str); void statustext_handle(int sc, char *str);