diff --git a/Makefile b/Makefile index 76b3cfed..df65832d 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c window.c awesome-client-common.c +SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c window.c rules.c awesome-client-common.c OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o} SRCCLIENT = awesome-client.c awesome-client-common.c util.c diff --git a/client.c b/client.c index c9757161..d772a891 100644 --- a/client.c +++ b/client.c @@ -27,6 +27,7 @@ #include "awesome.h" #include "layout.h" #include "tag.h" +#include "rules.h" #include "util.h" #include "statusbar.h" #include "window.h" diff --git a/config.c b/config.c index 9a85591c..bd18188c 100644 --- a/config.c +++ b/config.c @@ -32,6 +32,7 @@ #include "draw.h" #include "event.h" #include "tag.h" +#include "rules.h" #include "statusbar.h" #include "event.h" #include "layout.h" diff --git a/rules.c b/rules.c new file mode 100644 index 00000000..42c20bb1 --- /dev/null +++ b/rules.c @@ -0,0 +1,78 @@ +/* + * rules.c - rules management + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "util.h" +#include "rules.h" + +Bool +client_match_rule(Client *c, Rule *r) +{ + char *prop; + regmatch_t tmp; + ssize_t len; + XClassHint ch = { 0, 0 }; + Bool ret; + + XGetClassHint(c->display, c->win, &ch); + + len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name); + prop = p_new(char, len + 3); + + /* rule matching */ + snprintf(prop, len + 3, "%s:%s:%s", + ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name); + + ret = (r->propregex && !regexec(r->propregex, prop, 1, &tmp, 0)); + + p_delete(&prop); + + if(ch.res_class) + XFree(ch.res_class); + if(ch.res_name) + XFree(ch.res_name); + + return ret; +} + +int +get_client_screen_from_rules(Client *c, Rule *rules) +{ + Rule *r; + + for(r = rules; r; r = r->next) + if(client_match_rule(c, r)) + return r->screen; + + return RULE_NOSCREEN; +} + +Bool +is_client_tag_from_rules(Client *c, Tag *t, Rule *r) +{ + regmatch_t tmp; + + if(!regexec(r->tagregex, t->name, 1, &tmp, 0)) + return True; + + return False; +} + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/rules.h b/rules.h new file mode 100644 index 00000000..116acb49 --- /dev/null +++ b/rules.h @@ -0,0 +1,34 @@ +/* + * rules.h - rules management header + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_RULES_H +#define AWESOME_RULES_H + +#include "config.h" + +#define RULE_NOSCREEN -1 + +Bool client_match_rule(Client *, Rule *); +int get_client_screen_from_rules(Client *, Rule *); +Bool is_client_tag_from_rules(Client *, Tag *, Rule *); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/tag.c b/tag.c index 43f9f257..d5618fc5 100644 --- a/tag.c +++ b/tag.c @@ -26,6 +26,7 @@ #include "layout.h" #include "tag.h" #include "util.h" +#include "rules.h" int applyrules(Client *c, awesome_config *awesomeconf) diff --git a/tag.h b/tag.h index 0c410304..2ae039fb 100644 --- a/tag.h +++ b/tag.h @@ -24,8 +24,6 @@ #include "client.h" -#define RULE_NOSCREEN -1 - /** Check if a client is tiled */ #define IS_TILED(client, screen, tags, ntags) (client && !client->isfloating && isvisible(client, screen, tags, ntags))