Ejemplo n.º 1
0
/** Draw a string in a Drawable
 * \param d Drawable
 * \param x X position
 * \param y Y position
 * \param fg Foreground text color
 * \param pad Text padding
 * \param str String that will be draw
*/
void
draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset)
{
     XftColor xftcolor;
     XftDraw *xftd;
#ifdef HAVE_IMLIB
     char *ostr = NULL;
     int i, ni, sw = 0;
     ImageAttr im[128];
     size_t textlen;
#else
     (void)x_image_ofset;
     (void)y_image_ofset;
#endif /* HAVE_IMLIB */

     if(!str)
          return;

     /* To draw image everywhere we can draw text */
#ifdef HAVE_IMLIB

     ostr = xstrdup(str);
     textlen = strlen(ostr);

     if(strstr(str, "i["))
     {
          ni = parse_image_block(im, str);

          if(infobar[conf.systray.screen].bar && d == infobar[conf.systray.screen].bar->dr)
               sw = systray_get_width();

          for(i = 0; i < ni; ++i)
               draw_image(d, x_image_ofset + im[i].x - sw, y_image_ofset + im[i].y, im[i].w, im[i].h, im[i].name);
     }
#endif /* HAVE_IMLIB */

     /* Transform X Drawable -> Xft Drawable */
     xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN));

     /* Alloc text color */
     XftColorAllocName(dpy, DefaultVisual(dpy, SCREEN),
                       DefaultColormap(dpy, SCREEN), fg, &xftcolor);

     XftDrawStringUtf8(xftd, &xftcolor, font, x, y, (FcChar8 *)str, strlen(str));

     /* Free the text color and XftDraw */
     XftColorFree(dpy, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN), &xftcolor);

     XftDrawDestroy(xftd);

#ifdef HAVE_IMLIB
     if(strstr(ostr, "i["))
          strncpy(str, ostr, textlen);

     free(ostr);
#endif /* HAVE_IMLIB */

     return;
}
Ejemplo n.º 2
0
/** Draw normal text and colored normal text
  * --> \#color\ text in color
  *\param sc Screen
  *\param str String
  */
static void
statustext_normal(int sc, char *str)
{
     char strwc[MAXSTATUS] = { 0 };
     char buf[MAXSTATUS] = { 0 };
     char col[8] = { 0 };
     int n, i, j, k, sw = 0;

     if(sc == conf.systray.screen)
          sw = systray_get_width();

     for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
          if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
          {
               ++n;
               i += 8;
               --j;
          }
          else
               strwc[j] = str[i];

     /* Draw normal text without any blocks */
     draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(strwc) + sw),
               FHINFOBAR, infobar[sc].bar->fg, strwc);

     if(n)
     {
          strncpy(buf, strwc, sizeof(buf));

          for(i = k = 0; i < (int)strlen(str); ++i, ++k)
               if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
               {
                    /* Store current color in col[] */
                    for(j = 0, ++i; str[i] != '\\'; col[j++] = str[i++]);

                    /* Draw a rectangle with the bar color to draw the text properly */
                    draw_rectangle(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(&buf[k]) + sw),
                                   0, INFOBARH - (sgeo[sc].width - SHADH) - textw(&buf[k]),
                                   INFOBARH, conf.colors.bar);

                    /* Draw text with its color */
                    draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(&buf[k]) + sw),
                              FHINFOBAR,  col, &buf[k]);

                    strncpy(buf, strwc, sizeof(buf));
                    ++i;
               }
     }

     return;
}
Ejemplo n.º 3
0
/** Handle statustext and draw all things in infobar of specified screen
  *\param sc Screen number
  *\param str String
  */
void
statustext_handle(int sc, char *str)
{
     char *lastst;
     int i, nr, ng, ns, sw = 0;
     StatusRec r[128];
     StatusGraph g[128];
     StatusText s[128];

     /* If the str == the current statustext, return (not needed) */
     if(!str)
          return;

     if(sc == conf.systray.screen)
          sw = systray_get_width();

     barwin_refresh_color(infobar[sc].bar);

     /* save last status text address (for free at the end) */
     lastst = infobar[sc].statustext;

     infobar[sc].statustext = xstrdup(str);

     /* Store rectangles, located text & images properties. */
     nr = statustext_rectangle(r, str);
     ng = statustext_graph(g, str);
     ns = statustext_text(s, str);

     /* Draw normal text (and possibly colored with \#color\ blocks) */
     statustext_normal(sc, str);

     /* Draw rectangles with stored properties. */
     for(i = 0; i < nr; ++i)
          draw_rectangle(infobar[sc].bar->dr, r[i].x - sw, r[i].y, r[i].w, r[i].h, r[i].color);

     /* Draw graphs with stored properties. */
     for(i = 0; i < ng; ++i)
          draw_graph(infobar[sc].bar->dr, g[i].x - sw, g[i].y, g[i].w, g[i].h, g[i].color, g[i].data);

     /* Draw located text with stored properties. */
     for(i = 0; i < ns; ++i)
          draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, s[i].text);

     barwin_refresh(infobar[sc].bar);

     free(lastst);

     return;
}