Sfoglia il codice sorgente

Draw: Replace statustext_image by parse_color_block, remove image stuff in status.c (draw_text image stuff is sufficient) and update version

Martin Duquesnoy 14 anni fa
parent
commit
aa9609b5cf
6 ha cambiato i file con 39 aggiunte e 26 eliminazioni
  1. 1 1
      CMakeLists.txt
  2. 4 4
      src/draw.c
  3. 2 15
      src/status.c
  4. 1 1
      src/structs.h
  5. 26 0
      src/util.c
  6. 5 5
      src/wmfs.h

+ 1 - 1
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")

+ 4 - 4
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);

+ 2 - 15
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);

+ 1 - 1
src/structs.h

@@ -423,7 +423,7 @@ typedef struct
 {
      uint x, y, w, h;
      char name[512];
-} StatusImage;
+} ImageAttr;
 
 /* Config.c struct */
 typedef struct

+ 26 - 0
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 */
+

+ 5 - 5
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);