moved client-related stuff from rule.c to client.c

This commit is contained in:
Anselm R. Garbe 2006-05-30 18:42:42 +02:00
parent 15dfca474f
commit e01ca2506a
3 changed files with 74 additions and 75 deletions

View File

@ -816,3 +816,75 @@ draw_clients()
}
}
static Bool
permit_tag(const char *tag)
{
static char *exclude[] = { "sel", "status" };
unsigned int i;
for(i = 0; i < (sizeof(exclude) / sizeof(exclude[0])); i++)
if(!strcmp(exclude[i], tag))
return False;
return True;
}
void
apply_tags(Client *c, const char *tags)
{
unsigned int i, j = 0, n;
char buf[256];
char *toks[16], *apply[16];
cext_strlcpy(buf, tags, sizeof(buf));
if(!(n = cext_tokenize(toks, 16, buf, '+')))
return;
for(i = 0; i < n; i++) {
if(!strncmp(toks[i], "~", 2))
c->floating = True;
else if(!strncmp(toks[i], "!", 2)) {
if(view.size)
apply[j++] = view.data[sel]->name;
else
apply[j++] = "nil";
}
else if(permit_tag(toks[i]))
apply[j++] = toks[i];
}
c->tags[0] = 0;
for(i = 0; i < j; i++) {
cext_strlcat(c->tags, apply[i], sizeof(c->tags) - strlen(c->tags) - 1);
if(i + 1 < j)
cext_strlcat(c->tags, "+", sizeof(c->tags) - strlen(c->tags) - 1);
}
if(!strlen(c->tags))
apply_tags(c, "nil");
}
static void
match_tags(Client *c, const char *prop)
{
unsigned int i;
regmatch_t tmpregm;
for(i = 0; i < crule.size; i++) {
Rule *r = crule.data[i];
if(!regexec(&r->regex, prop, 1, &tmpregm, 0))
if(!strlen(c->tags) || !strncmp(c->tags, "nil", 4))
apply_tags(c, r->values);
}
}
void
apply_rules(Client *c)
{
if(!def.rules)
goto Fallback;
match_tags(c, c->props);
Fallback:
if(!strlen(c->tags))
apply_tags(c, "nil");
}

View File

@ -22,17 +22,6 @@ vector_of_rules(RuleVector *rv)
return (Vector *) rv;
}
static Bool
permit_tag(const char *tag)
{
static char *exclude[] = { "sel", "status" };
unsigned int i;
for(i = 0; i < (sizeof(exclude) / sizeof(exclude[0])); i++)
if(!strcmp(exclude[i], tag))
return False;
return True;
}
void
update_rules(RuleVector *rule, const char *data)
{
@ -92,65 +81,3 @@ update_rules(RuleVector *rule, const char *data)
break;
}
}
void
apply_tags(Client *c, const char *tags)
{
unsigned int i, j = 0, n;
char buf[256];
char *toks[16], *apply[16];
cext_strlcpy(buf, tags, sizeof(buf));
if(!(n = cext_tokenize(toks, 16, buf, '+')))
return;
for(i = 0; i < n; i++) {
if(!strncmp(toks[i], "~", 2))
c->floating = True;
else if(!strncmp(toks[i], "!", 2)) {
if(view.size)
apply[j++] = view.data[sel]->name;
else
apply[j++] = "nil";
}
else if(permit_tag(toks[i]))
apply[j++] = toks[i];
}
c->tags[0] = 0;
for(i = 0; i < j; i++) {
cext_strlcat(c->tags, apply[i], sizeof(c->tags) - strlen(c->tags) - 1);
if(i + 1 < j)
cext_strlcat(c->tags, "+", sizeof(c->tags) - strlen(c->tags) - 1);
}
if(!strlen(c->tags))
apply_tags(c, "nil");
}
static void
match(Client *c, const char *prop)
{
unsigned int i;
regmatch_t tmpregm;
for(i = 0; i < crule.size; i++) {
Rule *r = crule.data[i];
if(!regexec(&r->regex, prop, 1, &tmpregm, 0))
if(!strlen(c->tags) || !strncmp(c->tags, "nil", 4))
apply_tags(c, r->values);
}
}
void
apply_rules(Client *c)
{
if(!def.rules)
goto Fallback;
match(c, c->props);
Fallback:
if(!strlen(c->tags))
apply_tags(c, "nil");
}

View File

@ -259,6 +259,8 @@ int idx_of_client_id(unsigned short id);
Client *client_of_win(Window w);
void draw_clients();
void update_client_grab(Client *c, Bool is_sel);
void apply_rules(Client *c);
void apply_tags(Client *c, const char *tags);
/* column.c */
void arrange_column(Area *a, Bool dirty);
@ -303,8 +305,6 @@ void snap_move(XRectangle *r, XRectangle *rects, unsigned int num,
/* rule.c */
void update_rules(RuleVector *rule, const char *data);
void apply_rules(Client *c);
void apply_tags(Client *c, const char *tags);
/* view.c */
void arrange_view(View *v);