Status/Draw: Draw rec/img/str/graph block in status function, remove ofset draw functions

This commit is contained in:
Martin Duquesnoy
2011-06-14 17:51:01 +02:00
parent 74281424da
commit 134bb3add4
6 changed files with 111 additions and 149 deletions

View File

@@ -123,26 +123,6 @@ barwin_draw_text(BarWindow *bw, int x, int y, char *text)
return; return;
} }
/** Draw text in a Barwindow
*/
void
barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset)
{
if(!text)
return;
/* Background color of the text if there is stipple */
if(bw->flags & StippleFlag)
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */
draw_image_ofset_text(bw->dr, x, y, bw->fg, text, x_image_ofset, y_image_ofset);
barwin_refresh(bw);
return;
}
void void
barwin_color_set(BarWindow *bw, uint bg, char *fg) barwin_color_set(BarWindow *bw, uint bg, char *fg)
{ {

View File

@@ -44,10 +44,9 @@ draw_image(Drawable dr, int x, int y, int w, int h, char *name)
{ {
Imlib_Image image; Imlib_Image image;
if(!name) if(!name || !dr)
return; return;
imlib_set_cache_size(2048 << 10);
imlib_context_set_display(dpy); imlib_context_set_display(dpy);
imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy))); imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy)));
imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy))); imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy)));
@@ -63,23 +62,45 @@ draw_image(Drawable dr, int x, int y, int w, int h, char *name)
h = imlib_image_get_height(); h = imlib_image_get_height();
if(image) if(image)
{
imlib_render_image_on_drawable_at_size(x, y, w, h); imlib_render_image_on_drawable_at_size(x, y, w, h);
imlib_free_image();
}
else else
warnx("Can't draw image: '%s'", name); warnx("Can't draw image: '%s'", name);
imlib_free_image();
return;
}
/** 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
*/
static int
parse_image_block(Drawable dr, char *str)
{
ImageAttr im;
char as;
int i, j, k, sw = systray_get_width();
for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\i[%d;%d;%d;%d;%512[^]]]%c", &im.x, &im.y, &im.w, &im.h, im.name, &as) == 6
&& as == '\\')
{
draw_image(dr, im.x - sw, im.y, im.w, im.h, im.name);
for(++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; return;
} }
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */
void
draw_text(Drawable d, int x, int y, char* fg, char *str)
{
draw_image_ofset_text(d, x, y, fg, str, 0, 0);
}
/** Draw a string in a Drawable /** Draw a string in a Drawable
* \param d Drawable * \param d Drawable
* \param x X position * \param x X position
@@ -89,13 +110,13 @@ draw_text(Drawable d, int x, int y, char* fg, char *str)
* \param str String that will be draw * \param str String that will be draw
*/ */
void void
draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset) draw_text(Drawable d, int x, int y, char* fg, char *str)
{ {
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
char *ostr = NULL; char *ostr = NULL;
int i, ni, sw = 0; int i, ni, sw = 0;
ImageAttr im[128];
size_t textlen; size_t textlen;
bool ii = False;
#else #else
(void)x_image_ofset; (void)x_image_ofset;
(void)y_image_ofset; (void)y_image_ofset;
@@ -111,13 +132,8 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image
if(strstr(str, "i[")) if(strstr(str, "i["))
{ {
ni = parse_image_block(im, str); parse_image_block(d, str);
ii = True;
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 */ #endif /* HAVE_IMLIB */
@@ -151,7 +167,7 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
if(strstr(ostr, "i[")) if(ii)
strncpy(str, ostr, textlen); strncpy(str, ostr, textlen);
free(ostr); free(ostr);
@@ -212,11 +228,12 @@ draw_graph(Drawable dr, int x, int y, int w, int h, uint color, char *data)
ushort ushort
textw(char *text) textw(char *text)
{ {
Drawable d = 0;
ushort ret = 0; ushort ret = 0;
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
char *ostr = NULL; char *ostr = NULL;
ImageAttr im[128];
size_t textlen; size_t textlen;
bool ii = False;
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */
if(!text) if(!text)
@@ -227,7 +244,10 @@ textw(char *text)
textlen = strlen(ostr); textlen = strlen(ostr);
if(strstr(text, "i[")) if(strstr(text, "i["))
parse_image_block(im, text); {
parse_image_block(d, text);
ii = True;
}
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */
#ifdef HAVE_XFT #ifdef HAVE_XFT
@@ -248,7 +268,7 @@ textw(char *text)
} }
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
if(strstr(ostr, "i[")) if(ii)
strncpy(text, ostr, textlen); strncpy(text, ostr, textlen);
free(ostr); free(ostr);

View File

@@ -71,11 +71,11 @@ menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen)
x = (width - (chcklen + PAD / 3)) / 2 - textw(menu->item[item].name) / 2 + chcklen + PAD / 3; x = (width - (chcklen + PAD / 3)) / 2 - textw(menu->item[item].name) / 2 + chcklen + PAD / 3;
break; break;
} }
barwin_draw_image_ofset_text(winitem[item], x, FHINFOBAR, menu->item[item].name, chcklen + PAD / 2, 0); barwin_draw_text(winitem[item], x, FHINFOBAR, menu->item[item].name);
if(menu->item[item].check) if(menu->item[item].check)
if(menu->item[item].check(menu->item[item].cmd)) if(menu->item[item].check(menu->item[item].cmd))
barwin_draw_image_ofset_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol, PAD / 3, 0); barwin_draw_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol);
if(menu->item[item].submenu) if(menu->item[item].submenu)
barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">"); barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">");
@@ -147,7 +147,7 @@ static bool
menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]) menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[])
{ {
int i, c = 0; int i, c = 0;
KeySym ks; KeySym ks = 0;
bool quit = False; bool quit = False;
char acc = 0; char acc = 0;
@@ -349,6 +349,8 @@ menu_draw(Menu menu, int x, int y)
XGrabKeyboard(dpy, ROOT, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabKeyboard(dpy, ROOT, True, GrabModeAsync, GrabModeAsync, CurrentTime);
XNextEvent(dpy, &ev);
while(!menu_manage_event(&ev, &menu, item)); while(!menu_manage_event(&ev, &menu, item));
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);

View File

@@ -32,102 +32,112 @@
#include "wmfs.h" #include "wmfs.h"
/** Check rectangles blocks in str and return properties /* Systray width */
* --> \b[x;y;width;height;#color]\ int sw = 0;
*\param r StatusRec pointer, rectangles properties
*\param str String
*\return n Length of r
*/
static int
statustext_rectangle(StatusRec *r, char *str)
{
char as;
int n, i, j, k;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j) /** Check rectangles blocks in str and draw it
if(sscanf(&str[i], "\\b[%d;%d;%d;%d;#%x]%c", &r[n].x, &r[n].y, &r[n].w, &r[n].h, &r[n].color, &as) == 6 * --> \b[x;y;width;height;#color]\
*\param ib Infobar pointer
*\param str String
*/
static void
statustext_rectangle(InfoBar *ib, char *str)
{
StatusRec r;
char as;
int i, j, k;
for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\b[%d;%d;%d;%d;#%x]%c", &r.x, &r.y, &r.w, &r.h, &r.color, &as) == 6
&& as == '\\') && as == '\\')
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i); {
draw_rectangle(ib->bar->dr, r.x - sw, r.y, r.w, r.h, r.color);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
}
else if(j != i) else if(j != i)
str[j] = str[i]; str[j] = str[i];
for(k = j; k < i; str[k++] = 0); for(k = j; k < i; str[k++] = '\0');
return n; return;
} }
/** Check graphs blocks in str and return properties /** Check graphs blocks in str and draw it
* --> \g[x;y;width;height;#color;data]\ * --> \g[x;y;width;height;#color;data]\
*\param g StatusGraph pointer, graphs properties *\param ib Infobar pointer
*\param str String *\param str String
*\return n Length of g
*/ */
static int static void
statustext_graph(StatusGraph *g, char *str) statustext_graph(InfoBar *ib, char *str)
{ {
StatusGraph g;
char as, c, *p; char as, c, *p;
int n, i, j, k, m, w; int i, j, k, m, w;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j) for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\g[%d;%d;%d;%d;#%x;%512[^]]]%c", if(sscanf(&str[i], "\\g[%d;%d;%d;%d;#%x;%512[^]]]%c",
&g[n].x, &g[n].y, &g[n].w, &g[n].h, &g[n].color, g[n].data, &as) == 7 &g.x, &g.y, &g.w, &g.h, &g.color, g.data, &as) == 7
&& as == '\\') && as == '\\')
{ {
/* data is a list of numbers separated by ';' */ /* data is a list of numbers separated by ';' */
w = g[n].w; w = g.w;
p = strtok(g[n].data, ";"); p = strtok(g.data, ";");
m = 0; m = 0;
while(p && m < w) for(c = atoi(p); p && m < w; ++m)
{ {
c = atoi(p);
/* height limits */ /* height limits */
if(c < 0) if(c < 0)
c = 0; c = 0;
if(c > (char)g[n].h) if(c > (char)g.h)
c = g[n].h; c = g.h;
g[n].data[m] = c; g.data[m] = c;
p = strtok(NULL, ";"); p = strtok(NULL, ";");
++m;
} }
/* width limits */ /* width limits */
for(; m < w; ++m) for(; m < w; g.data[m++] = 0);
g[n].data[m] = 0;
/* data is a array[w] of bytes now */
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i); /* data is a array[w] of bytes now */
draw_graph(ib->bar->dr, g.x - sw, g.y, g.w, g.h, g.color, g.data);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
} }
else if(j != i) else if(j != i)
str[j] = str[i]; str[j] = str[i];
for(k = j; k < i; str[k++] = 0); for(k = j; k < i; str[k++] = 0);
return n; return;
} }
/** Check text blocks in str and return properties /** Check text blocks in str and draw it
* --> \s[x;y;#color;text]\ * --> \s[x;y;#color;text]\
*\param s StatusText pointer, text properties *\param ib Infobar pointer
*\param str String *\param str String
*\return n Length of s
*/ */
static int static void
statustext_text(StatusText *s, char *str) statustext_text(InfoBar *ib, char *str)
{ {
StatusText s;
char as; char as;
int n, i, j, k; int i, j, k;
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j) for(i = j = 0; i < (int)strlen(str); ++i, ++j)
if(sscanf(&str[i], "\\s[%d;%d;%7[^;];%512[^]]]%c", &s[n].x, &s[n].y, s[n].color, s[n].text, &as) == 5 if(sscanf(&str[i], "\\s[%d;%d;%7[^;];%512[^]]]%c", &s.x, &s.y, s.color, s.text, &as) == 5
&& as == '\\') && as == '\\')
for(++n, ++i, --j; str[i] != as || str[i - 1] != ']'; ++i); {
draw_text(ib->bar->dr, s.x - sw, s.y, s.color, s.text);
for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i);
}
else if(j != i) else if(j != i)
str[j] = str[i]; str[j] = str[i];
for(k = j; k < i; str[k++] = 0); for(k = j; k < i; str[k++] = 0);
return n; return;
} }
/** Draw normal text and colored normal text /** Draw normal text and colored normal text
@@ -141,10 +151,7 @@ statustext_normal(int sc, char *str)
char strwc[MAXSTATUS] = { 0 }; char strwc[MAXSTATUS] = { 0 };
char buf[MAXSTATUS] = { 0 }; char buf[MAXSTATUS] = { 0 };
char col[8] = { 0 }; char col[8] = { 0 };
int n, i, j, k, sw = 0; int n, i, j, k;
if(sc == conf.systray.screen)
sw = systray_get_width();
for(i = j = n = 0; i < (int)strlen(str); ++i, ++j) for(i = j = n = 0; i < (int)strlen(str); ++i, ++j)
if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\') if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
@@ -195,10 +202,7 @@ void
statustext_handle(int sc, char *str) statustext_handle(int sc, char *str)
{ {
char *lastst; char *lastst;
int i, nr, ng, ns, sw = 0; int i;
StatusRec r[128];
StatusGraph g[128];
StatusText s[128];
/* If the str == the current statustext, return (not needed) */ /* If the str == the current statustext, return (not needed) */
if(!str) if(!str)
@@ -215,25 +219,13 @@ statustext_handle(int sc, char *str)
infobar[sc].statustext = xstrdup(str); infobar[sc].statustext = xstrdup(str);
/* Store rectangles, located text & images properties. */ /* Store rectangles, located text & images properties. */
nr = statustext_rectangle(r, str); statustext_rectangle(&infobar[sc], str);
ng = statustext_graph(g, str); statustext_graph(&infobar[sc], str);
ns = statustext_text(s, str); statustext_text(&infobar[sc], str);
/* Draw normal text (and possibly colored with \#color\ blocks) */ /* Draw normal text (and possibly colored with \#color\ blocks) */
statustext_normal(sc, str); 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); barwin_refresh(infobar[sc].bar);
free(lastst); free(lastst);

View File

@@ -279,32 +279,6 @@ uicb_spawn(uicb_t cmd)
return; return;
} }
#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 < (int)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 */
char* char*
clean_value(char *str) clean_value(char *str)
{ {

View File

@@ -136,7 +136,6 @@ BarWindow *barwin_create(Window parent,
bool stipple, bool stipple,
bool border); bool border);
void barwin_draw_text(BarWindow *bw, int x, int y, char *text); void barwin_draw_text(BarWindow *bw, int x, int y, char *text);
void barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset);
void barwin_color_set(BarWindow *bw, uint bg, char *fg); void barwin_color_set(BarWindow *bw, uint bg, char *fg);
void barwin_delete(BarWindow *bw); void barwin_delete(BarWindow *bw);
void barwin_delete_subwin(BarWindow *bw); void barwin_delete_subwin(BarWindow *bw);
@@ -151,7 +150,6 @@ void barwin_refresh(BarWindow *bw);
/* draw.c */ /* draw.c */
void draw_text(Drawable d, int x, int y, char* fg, char *str); void draw_text(Drawable d, int x, int y, char* fg, char *str);
void draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset);
void draw_rectangle(Drawable dr, int x, int y, int w, int h, uint color); void draw_rectangle(Drawable dr, int x, int y, int w, int h, uint color);
void draw_graph(Drawable dr, int x, int y, int w, int h, uint color, char *data); void draw_graph(Drawable dr, int x, int y, int w, int h, uint color, char *data);
@@ -318,10 +316,6 @@ char *clean_value(char *str);
char* patht(char *path); char* patht(char *path);
int qsort_string_compare (const void * a, const void * b); int qsort_string_compare (const void * a, const void * b);
#ifdef HAVE_IMLIB
int parse_image_block(ImageAttr *im, char *str);
#endif /* HAVE_IMLIB */
/* tag.c */ /* tag.c */
void tag_set(int tag); void tag_set(int tag);
void tag_transfert(Client *c, int tag); void tag_transfert(Client *c, int tag);