allow negated patterns
This commit is contained in:
parent
c2badda58a
commit
c849d3c7ff
3 changed files with 24 additions and 10 deletions
|
@ -1,5 +1,8 @@
|
||||||
(Format: Year/Month/Day)
|
(Format: Year/Month/Day)
|
||||||
Changes for 1.0.1:
|
Changes for 1.0.1:
|
||||||
|
*07/10/23:
|
||||||
|
* Allow negated patterns, e.g. (name!=xterm) (Mark)
|
||||||
|
ClientPattern.cc/hh
|
||||||
*07/10/22:
|
*07/10/22:
|
||||||
* Added option "mouse" to client pattern ( Henrik )
|
* Added option "mouse" to client pattern ( Henrik )
|
||||||
This is usefull for xinerama. For example:
|
This is usefull for xinerama. For example:
|
||||||
|
|
|
@ -99,6 +99,11 @@ ClientPattern::ClientPattern(const char *str, bool default_no_transient):
|
||||||
memstr.assign(match, 0, eq); // memstr = our identifier
|
memstr.assign(match, 0, eq); // memstr = our identifier
|
||||||
expr.assign(match, eq+1, match.length());
|
expr.assign(match, eq+1, match.length());
|
||||||
}
|
}
|
||||||
|
bool negate = false;
|
||||||
|
if (!memstr.empty() && memstr[memstr.length()-1] == '!') {
|
||||||
|
negate = true;
|
||||||
|
memstr.assign(memstr, 0, memstr.length()-1);
|
||||||
|
}
|
||||||
if (strcasecmp(memstr.c_str(), "name") == 0) {
|
if (strcasecmp(memstr.c_str(), "name") == 0) {
|
||||||
prop = NAME;
|
prop = NAME;
|
||||||
} else if (strcasecmp(memstr.c_str(), "class") == 0) {
|
} else if (strcasecmp(memstr.c_str(), "class") == 0) {
|
||||||
|
@ -132,7 +137,7 @@ ClientPattern::ClientPattern(const char *str, bool default_no_transient):
|
||||||
prop = NAME;
|
prop = NAME;
|
||||||
expr = match;
|
expr = match;
|
||||||
}
|
}
|
||||||
had_error = !addTerm(expr, prop);
|
had_error = !addTerm(expr, prop, negate);
|
||||||
pos += err;
|
pos += err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,13 +271,15 @@ bool ClientPattern::match(const Focusable &win) const {
|
||||||
// workspaces don't necessarily have unique names, so we want to
|
// workspaces don't necessarily have unique names, so we want to
|
||||||
// compare numbers instead of strings
|
// compare numbers instead of strings
|
||||||
if ((*it)->prop == WORKSPACE && (!win.fbwindow() ||
|
if ((*it)->prop == WORKSPACE && (!win.fbwindow() ||
|
||||||
win.fbwindow()->workspaceNumber() !=
|
!((*it)->negate ^
|
||||||
win.screen().currentWorkspaceID()))
|
(win.fbwindow()->workspaceNumber() ==
|
||||||
|
win.screen().currentWorkspaceID()))))
|
||||||
return false;
|
return false;
|
||||||
else {
|
else {
|
||||||
WinClient *focused = FocusControl::focusedWindow();
|
WinClient *focused = FocusControl::focusedWindow();
|
||||||
if (!focused || getProperty((*it)->prop, win) !=
|
if (!focused || !((*it)->negate ^
|
||||||
getProperty((*it)->prop, *focused))
|
(getProperty((*it)->prop, win) ==
|
||||||
|
getProperty((*it)->prop, *focused))))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if ((*it)->prop == HEAD &&
|
} else if ((*it)->prop == HEAD &&
|
||||||
|
@ -291,10 +298,11 @@ bool ClientPattern::match(const Focusable &win) const {
|
||||||
}
|
}
|
||||||
char num[32];
|
char num[32];
|
||||||
sprintf(num, "%d", win.screen().getHead(x, y));
|
sprintf(num, "%d", win.screen().getHead(x, y));
|
||||||
if (getProperty((*it)->prop, win) != num)
|
if (!(*it)->negate ^ (getProperty((*it)->prop, win) == num))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else if (!(*it)->regexp.match(getProperty((*it)->prop, win)))
|
} else if (!(*it)->negate ^
|
||||||
|
(*it)->regexp.match(getProperty((*it)->prop, win)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -303,11 +311,12 @@ bool ClientPattern::match(const Focusable &win) const {
|
||||||
// add an expression to match against
|
// add an expression to match against
|
||||||
// The first argument is a regular expression, the second is the member
|
// The first argument is a regular expression, the second is the member
|
||||||
// function that we wish to match against.
|
// function that we wish to match against.
|
||||||
bool ClientPattern::addTerm(const string &str, WinProperty prop) {
|
bool ClientPattern::addTerm(const string &str, WinProperty prop, bool negate) {
|
||||||
|
|
||||||
Term *term = new Term(str, true);
|
Term *term = new Term(str, true);
|
||||||
term->orig = str;
|
term->orig = str;
|
||||||
term->prop = prop;
|
term->prop = prop;
|
||||||
|
term->negate = negate;
|
||||||
|
|
||||||
if (term->regexp.error()) {
|
if (term->regexp.error()) {
|
||||||
delete term;
|
delete term;
|
||||||
|
@ -386,7 +395,8 @@ bool ClientPattern::equals(const ClientPattern &pat) const {
|
||||||
Terms::const_iterator other_it = pat.m_terms.begin();
|
Terms::const_iterator other_it = pat.m_terms.begin();
|
||||||
Terms::const_iterator other_it_end = pat.m_terms.end();
|
Terms::const_iterator other_it_end = pat.m_terms.end();
|
||||||
for (; it != it_end && other_it != other_it_end; ++it, ++other_it) {
|
for (; it != it_end && other_it != other_it_end; ++it, ++other_it) {
|
||||||
if ((*it)->orig != (*other_it)->orig)
|
if ((*it)->orig != (*other_it)->orig ||
|
||||||
|
(*it)->negate != (*other_it)->negate)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (it != it_end || other_it != other_it_end)
|
if (it != it_end || other_it != other_it_end)
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
* @param prop is the member function that we wish to match against
|
* @param prop is the member function that we wish to match against
|
||||||
* @return false if the regexp wasn't valid
|
* @return false if the regexp wasn't valid
|
||||||
*/
|
*/
|
||||||
bool addTerm(const std::string &str, WinProperty prop);
|
bool addTerm(const std::string &str, WinProperty prop, bool negate = false);
|
||||||
|
|
||||||
inline void addMatch() { ++m_nummatches; }
|
inline void addMatch() { ++m_nummatches; }
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ private:
|
||||||
std::string orig;
|
std::string orig;
|
||||||
RegExp regexp;
|
RegExp regexp;
|
||||||
WinProperty prop;
|
WinProperty prop;
|
||||||
|
bool negate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue