From 06dc3ba2213fa951d6795b820eb0225c978570d7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 13 Nov 2007 21:40:33 +0100 Subject: [PATCH] add new rules.c file with new functions for using Rule-s struct --- Makefile | 2 +- client.c | 1 + config.c | 1 + rules.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rules.h | 34 ++++++++++++++++++++++++ tag.c | 1 + tag.h | 2 -- 7 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 rules.c create mode 100644 rules.h diff --git a/Makefile b/Makefile index 76b3cfedd..df65832d5 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 c97571615..d772a891f 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 9a85591c0..bd18188c2 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 000000000..42c20bb12 --- /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 000000000..116acb49d --- /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 43f9f2578..d5618fc5d 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 0c410304d..2ae039fb7 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))