some cleanup in rule.c, added $MODKEY-Shift-{j,k}

This commit is contained in:
Anselm R. Garbe 2006-03-26 17:49:31 +02:00
parent 2ef7c06986
commit 0d935ce433
4 changed files with 53 additions and 11 deletions

View File

@ -9,7 +9,7 @@
#include "wm.h"
static int
comp_label(const void *l1, const void *l2)
comp_label_intern(const void *l1, const void *l2)
{
Label *ll1 = *(Label **)l1;
Label *ll2 = *(Label **)l2;
@ -17,6 +17,14 @@ comp_label(const void *l1, const void *l2)
return -1;
if(!ll1->intern && ll2->intern)
return 1;
return 0;
}
static int
comp_label_name(const void *l1, const void *l2)
{
Label *ll1 = *(Label **)l1;
Label *ll2 = *(Label **)l2;
return strcmp(ll1->name, ll2->name);
}
@ -36,7 +44,8 @@ get_label(char *name)
label = (Label **)cext_array_attach((void **)label, l,
sizeof(Label *), &labelsz);
nlabel++;
qsort(label, nlabel, sizeof(Label *), comp_label);
qsort(label, nlabel, sizeof(Label *), comp_label_name);
qsort(label, nlabel, sizeof(Label *), comp_label_intern);
return l;
}

View File

@ -536,6 +536,28 @@ send2area_client(Client *c, char *arg)
else
to = v->area[1];
}
else if(!strncmp(arg, "up", 3)) {
int j = frame2index(f);
if(j)
i = j - 1;
else
i = a->nframe - 1;
a->frame[j] = a->frame[i];
a->frame[i] = f;
arrange_area(a);
return;
}
else if(!strncmp(arg, "down", 5)) {
int j = frame2index(f);
if(j + 1 < a->nframe)
i = j + 1;
else
i = 0;
a->frame[j] = a->frame[i];
a->frame[i] = f;
arrange_area(a);
return;
}
else if(!strncmp(arg, "toggle", 7)) {
if(i)
to = v->area[0];

View File

@ -18,9 +18,10 @@
*/
typedef struct {
char regex[256];
regex_t regex;
char tag[MAX_TAGS][MAX_TAGLEN];
unsigned int ntag;
Bool is_valid;
} Rule;
enum {
@ -46,6 +47,12 @@ parse(char *data, unsigned int *n)
if(*p == '\n')
(*n)++;
for(i = 0; i < rulesz; i++)
if(rule[i].is_valid) {
regfree(&rule[i].regex);
rule[i].is_valid = False;
}
if(*n > rulesz) {
if(rule)
free(rule);
@ -71,7 +78,7 @@ parse(char *data, unsigned int *n)
if(*p == '/') {
mode = IGNORE;
*r = 0;
cext_strlcpy(rule[i].regex, regex, sizeof(rule[i].regex));
rule[i].is_valid = regcomp(&rule[i].regex, regex, 0);
}
else {
*r = *p;
@ -102,19 +109,17 @@ static void
match(Rule *rule, unsigned int rulesz, Client *c, const char *prop)
{
unsigned int i, j;
regex_t regex;
regmatch_t tmpregm;
c->ntag = 0;
for(i = 0; i < rulesz && c->ntag < MAX_TAGS; i++) {
Rule r = rule[i];
if(!regcomp(&regex, r.regex, 0)) {
if(!regexec(&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]));
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++;
}
regfree(&regex);
}
}
}

View File

@ -51,6 +51,8 @@ $MODKEY-Control-t
$MODKEY-t
$MODKEY-Shift-h
$MODKEY-Shift-l
$MODKEY-Shift-j
$MODKEY-Shift-k
$MODKEY-space
$MODKEY-Shift-space
$MODKEY-h
@ -124,6 +126,10 @@ do
xwrite /view/sel/sel/ctl sendto prev;;
$MODKEY-Shift-l)
xwrite /view/sel/sel/ctl sendto next;;
$MODKEY-Shift-j)
xwrite /view/sel/sel/ctl sendto down;;
$MODKEY-Shift-k)
xwrite /view/sel/sel/ctl sendto up;;
$MODKEY-space)
xwrite /view/ctl select toggle;;
$MODKEY-Shift-space)