mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
add new rules.c file with new functions for using Rule-s struct
This commit is contained in:
parent
ae49735001
commit
06dc3ba221
7 changed files with 116 additions and 3 deletions
2
Makefile
2
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
|
||||
|
|
1
client.c
1
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"
|
||||
|
|
1
config.c
1
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"
|
||||
|
|
78
rules.c
Normal file
78
rules.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* rules.c - rules management
|
||||
*
|
||||
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
||||
*
|
||||
* 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
|
34
rules.h
Normal file
34
rules.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* rules.h - rules management header
|
||||
*
|
||||
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
||||
*
|
||||
* 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
|
1
tag.c
1
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)
|
||||
|
|
2
tag.h
2
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))
|
||||
|
||||
|
|
Loading…
Reference in a new issue