Use single function to parse sequences to keep the order
This commit is contained in:
parent
554952cc57
commit
5cdb0ac77c
105
src/status.c
105
src/status.c
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "status.h"
|
#include "status.h"
|
||||||
#include "barwin.h"
|
#include "barwin.h"
|
||||||
|
#include "config.h"
|
||||||
#include "infobar.h"
|
#include "infobar.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -47,12 +48,46 @@
|
|||||||
} \
|
} \
|
||||||
} while(/* CONSTCOND */ 0); \
|
} while(/* CONSTCOND */ 0); \
|
||||||
|
|
||||||
|
/* Parse mousebind sequence next normal sequence: \<seq>[](button;func;cmd) */
|
||||||
|
static char*
|
||||||
|
status_parse_mouse(struct status_seq *sq, struct element *e, char *str)
|
||||||
|
{
|
||||||
|
struct mousebind *m;
|
||||||
|
struct barwin *b = SLIST_FIRST(&e->bars);
|
||||||
|
char *arg[3] = { NULL };
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(*str != '(' || !strchr(str, ')'))
|
||||||
|
return str + 1;
|
||||||
|
|
||||||
|
for(i = 0, ++str, arg[0] = str; *str && *str != ')' && i < 3; ++str)
|
||||||
|
if(*str == ';')
|
||||||
|
{
|
||||||
|
*str = '\0';
|
||||||
|
arg[++i] = ++str;
|
||||||
|
}
|
||||||
|
*str = '\0';
|
||||||
|
|
||||||
|
m = xcalloc(1, sizeof(struct mousebind));
|
||||||
|
|
||||||
|
m->use_area = true;
|
||||||
|
m->button = ATOI(arg[0]);
|
||||||
|
m->func = uicb_name_func(arg[1]);
|
||||||
|
m->cmd = (i > 1 ? xstrdup(arg[2]) : NULL);
|
||||||
|
|
||||||
|
sq->mousebind = m;
|
||||||
|
|
||||||
|
SLIST_INSERT_HEAD(&b->mousebinds, m, next);
|
||||||
|
|
||||||
|
return str + 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
status_parse(struct infobar *ib)
|
status_parse(struct element *e)
|
||||||
{
|
{
|
||||||
struct status_seq *sq, *prev = NULL;
|
struct status_seq *sq, *prev = NULL;
|
||||||
int i, shift = 0;
|
int i, shift = 0;
|
||||||
char *dstr = xstrdup(ib->status), *sauv = dstr;
|
char *dstr = xstrdup(e->infobar->status), *sauv = dstr;
|
||||||
char type, *p, *end, *arg[6] = { NULL };
|
char type, *p, *end, *arg[6] = { NULL };
|
||||||
|
|
||||||
for(; *dstr; ++dstr)
|
for(; *dstr; ++dstr)
|
||||||
@ -63,14 +98,14 @@ status_parse(struct infobar *ib)
|
|||||||
|
|
||||||
p = ++dstr;
|
p = ++dstr;
|
||||||
|
|
||||||
if(!(strchr("sR", *p)) || !(end = strstr(p, "]\\")))
|
if(!(strchr("sR", *p)) || !(end = strchr(p, ']')))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Then parse & list it */
|
/* Then parse & list it */
|
||||||
switch((type = tolower(*p)))
|
switch((type = tolower(*p)))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Text sequence: \s[left/right;#color;text]\ OR \s[x;y;#color;text]\
|
* Text sequence: \s[left/right;#color;text] OR \s[x;y;#color;text]
|
||||||
*/
|
*/
|
||||||
case 's':
|
case 's':
|
||||||
STATUS_GET_ARGS(i, p, arg, 4);
|
STATUS_GET_ARGS(i, p, arg, 4);
|
||||||
@ -83,7 +118,7 @@ status_parse(struct infobar *ib)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rectangle sequence: \s[left/right;w;h;#color]\ OR \s[x;y;w;h;#color]\
|
* Rectangle sequence: \R[left/right;w;h;#color] OR \R[x;y;w;h;#color]
|
||||||
*/
|
*/
|
||||||
case 'r':
|
case 'r':
|
||||||
STATUS_GET_ARGS(i, p, arg, 5);
|
STATUS_GET_ARGS(i, p, arg, 5);
|
||||||
@ -97,11 +132,14 @@ status_parse(struct infobar *ib)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SLIST_INSERT_TAIL(&ib->statushead, sq, next, prev);
|
SLIST_INSERT_TAIL(&e->infobar->statushead, sq, next, prev);
|
||||||
|
|
||||||
|
dstr = status_parse_mouse(sq, e, end + 1);
|
||||||
|
|
||||||
|
printf(":%s\n", dstr);
|
||||||
|
|
||||||
prev = sq;
|
|
||||||
dstr = end + 2;
|
|
||||||
shift = 0;
|
shift = 0;
|
||||||
|
prev = sq;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sauv);
|
free(sauv);
|
||||||
@ -113,7 +151,6 @@ status_apply_list(struct element *e)
|
|||||||
struct status_seq *sq;
|
struct status_seq *sq;
|
||||||
struct barwin *b = SLIST_FIRST(&e->bars);
|
struct barwin *b = SLIST_FIRST(&e->bars);
|
||||||
int left = 0, right = 0;
|
int left = 0, right = 0;
|
||||||
int l;
|
|
||||||
|
|
||||||
SLIST_FOREACH(sq, &e->infobar->statushead, next)
|
SLIST_FOREACH(sq, &e->infobar->statushead, next)
|
||||||
{
|
{
|
||||||
@ -121,20 +158,31 @@ status_apply_list(struct element *e)
|
|||||||
{
|
{
|
||||||
/* Text */
|
/* Text */
|
||||||
case 's':
|
case 's':
|
||||||
if(sq->align == NoAlign)
|
sq->geo.w = draw_textw(e->infobar->theme, sq->str);
|
||||||
draw_text(b->dr, e->infobar->theme, sq->geo.x, sq->geo.y, sq->color, sq->str);
|
sq->geo.h = e->infobar->theme->font.height;
|
||||||
else if(sq->align == Left)
|
|
||||||
|
if(sq->align != NoAlign)
|
||||||
|
sq->geo.y = TEXTY(e->infobar->theme, e->geo.h);
|
||||||
|
|
||||||
|
if(sq->align == Left)
|
||||||
{
|
{
|
||||||
draw_text(b->dr, e->infobar->theme, left, TEXTY(e->infobar->theme, e->geo.h), sq->color, sq->str);
|
sq->geo.x = left;
|
||||||
left += draw_textw(e->infobar->theme, sq->str);
|
left += sq->geo.w;
|
||||||
}
|
}
|
||||||
else if(sq->align == Right)
|
else if(sq->align == Right)
|
||||||
{
|
{
|
||||||
l = draw_textw(e->infobar->theme, sq->str);
|
sq->geo.x = e->geo.w - right - sq->geo.w;
|
||||||
draw_text(b->dr, e->infobar->theme, e->geo.w - right - l,
|
right += sq->geo.w;
|
||||||
TEXTY(e->infobar->theme, e->geo.h), sq->color, sq->str);
|
|
||||||
right += l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_text(b->dr, e->infobar->theme, sq->geo.x, sq->geo.y, sq->color, sq->str);
|
||||||
|
|
||||||
|
if(sq->mousebind)
|
||||||
|
{
|
||||||
|
sq->mousebind->area = sq->geo;
|
||||||
|
sq->mousebind->area.y -= sq->geo.h;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Rectangle */
|
/* Rectangle */
|
||||||
@ -153,7 +201,12 @@ status_apply_list(struct element *e)
|
|||||||
right += sq->geo.w;
|
right += sq->geo.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
draw_rect(b->dr, sq->geo, sq->color);
|
draw_rect(b->dr, sq->geo, sq->color);
|
||||||
|
|
||||||
|
if(sq->mousebind)
|
||||||
|
sq->mousebind->area = sq->geo;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,10 +241,15 @@ void
|
|||||||
status_manage(struct element *e)
|
status_manage(struct element *e)
|
||||||
{
|
{
|
||||||
struct status_seq *sq;
|
struct status_seq *sq;
|
||||||
|
struct mousebind *m;
|
||||||
|
struct barwin *b = SLIST_FIRST(&e->bars);
|
||||||
|
|
||||||
SLIST_INIT(&e->infobar->statushead);
|
SLIST_INIT(&e->infobar->statushead);
|
||||||
|
|
||||||
/* Flush previous linked list of status sequences */
|
/*
|
||||||
|
* Flush previous linked list of status sequences
|
||||||
|
* and mousebind of status barwin
|
||||||
|
*/
|
||||||
while(!SLIST_EMPTY(&e->infobar->statushead))
|
while(!SLIST_EMPTY(&e->infobar->statushead))
|
||||||
{
|
{
|
||||||
sq = SLIST_FIRST(&e->infobar->statushead);
|
sq = SLIST_FIRST(&e->infobar->statushead);
|
||||||
@ -199,8 +257,15 @@ status_manage(struct element *e)
|
|||||||
free(sq->str);
|
free(sq->str);
|
||||||
free(sq);
|
free(sq);
|
||||||
}
|
}
|
||||||
|
while(!SLIST_EMPTY(&b->mousebinds))
|
||||||
|
{
|
||||||
|
m = SLIST_FIRST(&b->mousebinds);
|
||||||
|
SLIST_REMOVE_HEAD(&b->mousebinds, next);
|
||||||
|
free((void*)m->cmd);
|
||||||
|
free(m);
|
||||||
|
}
|
||||||
|
|
||||||
status_parse(e->infobar);
|
status_parse(e);
|
||||||
status_render(e);
|
status_render(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -96,6 +96,7 @@ struct barwin
|
|||||||
struct status_seq
|
struct status_seq
|
||||||
{
|
{
|
||||||
struct geo geo;
|
struct geo geo;
|
||||||
|
struct mousebind *mousebind;
|
||||||
enum position align;
|
enum position align;
|
||||||
char type;
|
char type;
|
||||||
char *str;
|
char *str;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user