added new shortcuts as described in prev snap, fixed rule.c issues (update_rules()), changed bar rendering order as explained in IRC (expand is the first non-intern label with east alignment)

This commit is contained in:
Anselm R. Garbe 2006-03-26 18:21:12 +02:00
parent 0d935ce433
commit d12fe194b5
5 changed files with 52 additions and 43 deletions

View File

@ -93,11 +93,11 @@ update_bar_geometry()
void
draw_bar()
{
unsigned int i = 0, x = 0;
unsigned int i = 0, w = 0;
int exp = 0;
Draw d = { 0 };
Label *l = nil;
d.align = CENTER;
d.gc = bargc;
d.drawable = barpmap;
d.rect = brect;
@ -111,7 +111,7 @@ draw_bar()
if(!nlabel)
return;
for(i = 0; (i < nlabel) && (x < brect.width); i++) {
for(i = 0; (i < nlabel) && (w < brect.width); i++) {
l = label[i];
if(l->intern) {
if(nview && !strncmp(l->name, def.tag, sizeof(l->name)))
@ -119,32 +119,42 @@ draw_bar()
else
l->color = def.norm;
}
l->rect.x = 0;
l->rect.y = 0;
l->rect.x = x;
l->rect.width = brect.height;
if(strlen(l->name))
l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
l->rect.height = brect.height;
x += l->rect.width;
w += l->rect.width;
}
if(i != nlabel) { /* give all labels same width */
unsigned int w = brect.width / nlabel;
w = brect.width / nlabel;
for(i = 0; i < nlabel; i++) {
l = label[i];
l->rect.x = i * w;
l->rect.width = w;
}
}
label[nlabel - 1]->rect.width = brect.width - label[nlabel - 1]->rect.x;
else { /* expand label properly */
for(exp = 0; (exp < nlabel) && (label[exp]->intern); exp++);
if(exp == nlabel)
exp = -1;
else
label[exp]->rect.width += (brect.width - w);
for(i = 1; i < nlabel; i++)
label[i]->rect.x = label[i - 1]->rect.x + label[i - 1]->rect.width;
}
for(i = 0; i < nlabel; i++) {
l = label[i];
d.color = l->color;
d.rect = l->rect;
d.data = l->data;
if(i + 1 == nlabel)
if(i == exp)
d.align = EAST;
else
d.align = CENTER;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
}

View File

@ -545,6 +545,7 @@ send2area_client(Client *c, char *arg)
a->frame[j] = a->frame[i];
a->frame[i] = f;
arrange_area(a);
focus_client(c);
return;
}
else if(!strncmp(arg, "down", 5)) {
@ -556,6 +557,7 @@ send2area_client(Client *c, char *arg)
a->frame[j] = a->frame[i];
a->frame[i] = f;
arrange_area(a);
focus_client(c);
return;
}
else if(!strncmp(arg, "toggle", 7)) {

View File

@ -1353,11 +1353,14 @@ static char *
xclunk(IXPConn *c, Fcall *fcall)
{
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
unsigned char type = qpath_type(m->qid.path);
if(!m)
return Enofile;
if(qpath_type(m->qid.path) == FsFkeys)
if(type == FsFkeys)
update_keys();
else if(type == FsFrules)
update_rules();
cext_array_detach((void **)c->map, m, &c->mapsz);
free(m);
fcall->id = RCLUNK;

View File

@ -24,44 +24,46 @@ typedef struct {
Bool is_valid;
} Rule;
static Rule *rule = nil;
static unsigned int rulesz = 0;
static unsigned int nrule = 0;
enum {
IGNORE,
REGEX,
TAGS
};
static Rule *
parse(char *data, unsigned int *n)
void
update_rules()
{
static Rule *rule = nil;
static unsigned int rulesz = 0;
unsigned int i;
int mode = IGNORE;
char *p, *r, *t, regex[256], tags[256];
if(!data || !strlen(data))
return nil;
if(!def.rules || !strlen(def.rules))
return;
*n = 0;
for(p = data; *p; p++)
if(*p == '\n')
(*n)++;
for(i = 0; i < rulesz; i++)
for(i = 0; i < nrule; i++)
if(rule[i].is_valid) {
regfree(&rule[i].regex);
rule[i].is_valid = False;
}
if(*n > rulesz) {
nrule = 0;
for(p = def.rules; *p; p++)
if(*p == '\n')
nrule++;
if(nrule > rulesz) {
if(rule)
free(rule);
rule = cext_emallocz(sizeof(Rule) * (*n));
rulesz = *n;
rule = cext_emallocz(sizeof(Rule) * nrule);
rulesz = nrule;
}
i = 0;
for(p = data; *p; p++)
for(p = def.rules; *p; p++)
switch(mode) {
case IGNORE:
if(*p == '/') {
@ -78,7 +80,7 @@ parse(char *data, unsigned int *n)
if(*p == '/') {
mode = IGNORE;
*r = 0;
rule[i].is_valid = regcomp(&rule[i].regex, regex, 0);
rule[i].is_valid = !regcomp(&rule[i].regex, regex, 0);
}
else {
*r = *p;
@ -100,26 +102,22 @@ parse(char *data, unsigned int *n)
}
break;
}
return rule;
}
static void
match(Rule *rule, unsigned int rulesz, Client *c, const char *prop)
match(Client *c, const char *prop)
{
unsigned int i, j;
regmatch_t tmpregm;
c->ntag = 0;
for(i = 0; i < rulesz && c->ntag < MAX_TAGS; i++) {
for(i = 0; i < nrule; i++) {
Rule *r = &rule[i];
if(r->is_valid) {
if(!regexec(&r->regex, prop, 1, &tmpregm, 0)) {
for(j = 0; c->ntag < MAX_TAGS && j < r->ntag; j++) {
cext_strlcpy(c->tag[c->ntag], r->tag[j], sizeof(c->tag[c->ntag]));
c->ntag++;
}
if(r->is_valid && !regexec(&r->regex, prop, 1, &tmpregm, 0)) {
for(j = 0; c->ntag < MAX_TAGS && j < r->ntag; j++) {
cext_strlcpy(c->tag[c->ntag], r->tag[j], sizeof(c->tag[c->ntag]));
c->ntag++;
}
}
}
@ -128,13 +126,8 @@ match(Rule *rule, unsigned int rulesz, Client *c, const char *prop)
void
match_tags(Client *c)
{
unsigned int n;
Rule *rule;
if(!def.rules)
return;
rule = parse(def.rules, &n);
match(rule, n, c, c->name);
match(rule, n, c, c->classinst);
match(c, c->name);
match(c, c->classinst);
}

View File

@ -275,6 +275,7 @@ void grab_mouse(Window w, unsigned long mod, unsigned int button);
void ungrab_mouse(Window w, unsigned long mod, unsigned int button);
/* rule.c */
void update_rules();
void match_tags(Client *c);
/* tag.c */