statustext color parsing trial [UNSTABLE]
This commit is contained in:
parent
0b21569b3a
commit
ad0bedd285
24
src/draw.c
24
src/draw.c
@ -53,30 +53,6 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
|
||||
XftColorAllocName(dpy, DefaultVisual(dpy, SCREEN),
|
||||
DefaultColormap(dpy, SCREEN), fg, &xftcolor);
|
||||
|
||||
/* Draw the text */
|
||||
/* DEV
|
||||
int i, j;
|
||||
char s[2] = { 0 };
|
||||
char col[8] = { 0 };
|
||||
|
||||
for(i = 0; i < strlen(str); ++i)
|
||||
{
|
||||
if(str[i] == '\\' && str[i + 1] == '#' &&)
|
||||
{
|
||||
++i;
|
||||
for(j = 0; str[i + j] != '\\'; col[j++] = str[i + j]);
|
||||
i += j;
|
||||
printf("-> %s\n", col);
|
||||
}
|
||||
else
|
||||
{
|
||||
s[0] = str[i];
|
||||
XftDrawStringUtf8(xftd, &xftcolor, font, x, y, (FcChar8 *)s, strlen(s));
|
||||
x += textw(s);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
XftDrawStringUtf8(xftd, &xftcolor, font, x, y, (FcChar8 *)str, strlen(str));
|
||||
|
||||
/* Free the text color and XftDraw */
|
||||
|
||||
@ -198,11 +198,8 @@ clientmessageevent(XClientMessageEvent *ev)
|
||||
if(XGetWindowProperty(dpy, ROOT, net_atom[wmfs_statustext], 0, 4096,
|
||||
False, net_atom[utf8_string], &rt, &rf, &ir, &il, &ret) == Success)
|
||||
{
|
||||
statustext = _strdup((char*)ret);
|
||||
|
||||
for(i = 0; i < screen_count(); ++i)
|
||||
infobar_draw(i);
|
||||
|
||||
infobar_draw_statustext(i, _strdup((char*)ret));
|
||||
XFree(ret);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ infobar_draw(int sc)
|
||||
infobar_draw_taglist(sc);
|
||||
infobar_draw_layout(sc);
|
||||
barwin_refresh_color(infobar[sc].bar);
|
||||
barwin_draw_text(infobar[sc].bar, (sgeo[sc].width - SHADH) - textw(statustext), FHINFOBAR, statustext);
|
||||
infobar_draw_statustext(sc, statustext);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -163,6 +163,74 @@ infobar_draw_taglist(int sc)
|
||||
return;
|
||||
}
|
||||
|
||||
/** Draw text in the statustext and parse color format
|
||||
*\param sc Screen
|
||||
*\param str String
|
||||
*/
|
||||
void
|
||||
infobar_draw_statustext(int sc, char *str)
|
||||
{
|
||||
int i, j, k, c = 0;
|
||||
char col[8] = { 0 };
|
||||
char *buf = NULL;
|
||||
char *strwc = NULL;
|
||||
int pos = 0;
|
||||
|
||||
if(!str)
|
||||
return;
|
||||
|
||||
barwin_refresh_color(infobar[sc].bar);
|
||||
statustext = _strdup(str);
|
||||
strwc = _strdup(statustext);
|
||||
|
||||
/* Count how many color block there is */
|
||||
for(i = 0; i < strlen(str); ++i)
|
||||
if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
|
||||
++c;
|
||||
|
||||
|
||||
for(i = j = 0; i < strlen(str); ++i, ++j)
|
||||
if(strwc[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
|
||||
{
|
||||
i += 8;
|
||||
--j;
|
||||
}
|
||||
else
|
||||
strwc[j] = str[i];
|
||||
|
||||
strwc[j] = '\0';
|
||||
|
||||
if(c)
|
||||
{
|
||||
buf = _strdup(strwc);
|
||||
for(k = i = 0; k < c; ++k)
|
||||
{
|
||||
for(; i < strlen(str); ++i)
|
||||
if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
|
||||
{
|
||||
for(j = 0, ++i; str[i + j] != '\\'; col[j] = str[i + j], ++j);
|
||||
printf("%s, i: %d\n", buf, i);
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
|
||||
draw_text(infobar[sc].bar->dr,
|
||||
(sgeo[sc].width - SHADH) - textw(buf),
|
||||
FHINFOBAR, ((col[0]) ? col : infobar[sc].bar->fg), 0, buf);
|
||||
|
||||
buf += 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
draw_text(infobar[sc].bar->dr,
|
||||
(sgeo[sc].width - SHADH) - textw(strwc),
|
||||
FHINFOBAR, infobar[sc].bar->fg, 0, strwc);
|
||||
|
||||
barwin_refresh(infobar[sc].bar);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** Destroy the InfoBar
|
||||
*/
|
||||
void
|
||||
|
||||
14
src/util.c
14
src/util.c
@ -199,6 +199,20 @@ get_mouse_pos(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Transform one character to string
|
||||
*\param ch The character that will be tranforming
|
||||
*\return The string.
|
||||
*/
|
||||
char*
|
||||
char_to_str(const char c)
|
||||
{
|
||||
static char s[2];
|
||||
|
||||
s[0] = c;
|
||||
s[1] = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/** Execute a sh command
|
||||
* \param cmd Command
|
||||
|
||||
@ -120,6 +120,7 @@ void infobar_init(void);
|
||||
void infobar_draw(int sc);
|
||||
void infobar_draw_layout(int sc);
|
||||
void infobar_draw_taglist(int sc);
|
||||
void infobar_draw_statustext(int sc, char *str);
|
||||
void infobar_destroy(void);
|
||||
void infobar_set_position(int pos);
|
||||
void uicb_infobar_togglepos(uicb_t);
|
||||
@ -239,6 +240,7 @@ Layout layout_name_to_struct(Layout lt[], char *name, int n, func_name_list_t ll
|
||||
char* alias_to_str(char *conf_choice);
|
||||
/* }}} */
|
||||
XRectangle get_mouse_pos(void);
|
||||
char *char_to_str(const char c);
|
||||
void spawn(const char *str, ...);
|
||||
void swap_ptr(void **x, void **y);
|
||||
void uicb_spawn(uicb_t);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user