2003-06-12 15:12:19 +00:00
|
|
|
// ClientPattern.cc for Fluxbox Window Manager
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2003-06-12 15:12:19 +00:00
|
|
|
// and Simon Bowden (rathnor at users.sourceforge.net)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#include "ClientPattern.hh"
|
2007-10-13 21:51:37 +00:00
|
|
|
|
2008-06-08 18:29:47 +00:00
|
|
|
#include "fluxbox.hh"
|
2007-10-13 21:51:37 +00:00
|
|
|
#include "FocusControl.hh"
|
|
|
|
#include "Layer.hh"
|
|
|
|
#include "Screen.hh"
|
2003-06-12 15:12:19 +00:00
|
|
|
#include "WinClient.hh"
|
2007-10-13 21:51:37 +00:00
|
|
|
#include "Workspace.hh"
|
2005-02-13 16:34:37 +00:00
|
|
|
|
2005-02-10 10:24:31 +00:00
|
|
|
#include "FbTk/StringUtil.hh"
|
2004-04-28 13:04:06 +00:00
|
|
|
#include "FbTk/App.hh"
|
2005-02-13 16:34:37 +00:00
|
|
|
#include "FbTk/stringstream.hh"
|
2010-09-10 14:35:49 +00:00
|
|
|
#include "FbTk/STLUtil.hh"
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2003-06-13 12:02:00 +00:00
|
|
|
// use GNU extensions
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
2003-06-12 15:12:19 +00:00
|
|
|
#endif // _GNU_SOURCE
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2011-02-23 21:46:13 +00:00
|
|
|
#include <algorithm>
|
2004-08-31 15:26:40 +00:00
|
|
|
#ifdef HAVE_CSTDIO
|
|
|
|
#include <cstdio>
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2010-09-09 13:33:12 +00:00
|
|
|
#ifdef HAVE_CSTRING
|
|
|
|
#include <cstring>
|
|
|
|
#else
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
2003-10-12 16:25:28 +00:00
|
|
|
// needed as well for index on some systems (e.g. solaris)
|
2006-10-27 06:57:43 +00:00
|
|
|
#include <strings.h>
|
2003-10-12 16:25:28 +00:00
|
|
|
|
2006-10-27 06:57:43 +00:00
|
|
|
using std::string;
|
2003-11-17 00:33:16 +00:00
|
|
|
|
2010-09-09 13:33:12 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct Name2WinProperty {
|
|
|
|
const char* name;
|
|
|
|
ClientPattern::WinProperty prop;
|
|
|
|
};
|
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
const Name2WinProperty name_2_winproperties[] = { // sorted for 'bsearch'
|
2010-09-09 13:33:12 +00:00
|
|
|
{ "class", ClientPattern::CLASS },
|
|
|
|
{ "focushidden", ClientPattern::FOCUSHIDDEN },
|
|
|
|
{ "head", ClientPattern::HEAD },
|
|
|
|
{ "iconhidden", ClientPattern::ICONHIDDEN },
|
|
|
|
{ "layer", ClientPattern::LAYER },
|
|
|
|
{ "maximized", ClientPattern::MAXIMIZED },
|
|
|
|
{ "minimized", ClientPattern::MINIMIZED },
|
|
|
|
{ "name", ClientPattern::NAME },
|
|
|
|
{ "role", ClientPattern::ROLE },
|
|
|
|
{ "screen", ClientPattern::SCREEN },
|
|
|
|
{ "shaded", ClientPattern::SHADED },
|
|
|
|
{ "stuck", ClientPattern::STUCK },
|
|
|
|
{ "title", ClientPattern::TITLE },
|
|
|
|
{ "transient", ClientPattern::TRANSIENT },
|
|
|
|
{ "urgent", ClientPattern::URGENT },
|
|
|
|
{ "workspace", ClientPattern::WORKSPACE },
|
|
|
|
{ "workspacename", ClientPattern::WORKSPACENAME }
|
|
|
|
};
|
|
|
|
|
2011-03-23 11:02:15 +00:00
|
|
|
extern "C" {
|
2010-09-09 13:33:12 +00:00
|
|
|
int name_2_winproperty_cmp(const void* a, const void* b) {
|
|
|
|
return strcmp(
|
|
|
|
reinterpret_cast<const Name2WinProperty*>(a)->name,
|
|
|
|
reinterpret_cast<const Name2WinProperty*>(b)->name);
|
|
|
|
}
|
2011-03-23 11:02:15 +00:00
|
|
|
}
|
2010-09-09 13:33:12 +00:00
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
const Name2WinProperty* find_winproperty_by_name(const FbTk::FbString& name) {
|
|
|
|
|
|
|
|
const Name2WinProperty key = { name.c_str(), ClientPattern::CLASS };
|
|
|
|
const Name2WinProperty* result = reinterpret_cast<Name2WinProperty*>(
|
|
|
|
bsearch(&key, name_2_winproperties,
|
|
|
|
sizeof(name_2_winproperties) / sizeof(Name2WinProperty),
|
|
|
|
sizeof(Name2WinProperty),
|
|
|
|
name_2_winproperty_cmp));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 13:33:12 +00:00
|
|
|
struct Prop2String {
|
|
|
|
ClientPattern::WinProperty prop;
|
|
|
|
const char* str;
|
|
|
|
};
|
|
|
|
|
|
|
|
Prop2String property_2_strings[] = { // sorted by 'prop'
|
2010-09-11 15:09:07 +00:00
|
|
|
{ ClientPattern::TITLE, "title" },
|
|
|
|
{ ClientPattern::CLASS, "class" },
|
|
|
|
{ ClientPattern::NAME, "name" },
|
|
|
|
{ ClientPattern::ROLE, "role" },
|
|
|
|
{ ClientPattern::TRANSIENT, "transient" },
|
|
|
|
{ ClientPattern::MAXIMIZED, "maximized" },
|
|
|
|
{ ClientPattern::MINIMIZED, "minimized" },
|
|
|
|
{ ClientPattern::SHADED, "shaded" },
|
|
|
|
{ ClientPattern::STUCK, "stuck" },
|
|
|
|
{ ClientPattern::FOCUSHIDDEN, "focushidden" },
|
|
|
|
{ ClientPattern::ICONHIDDEN, "iconhidden" },
|
|
|
|
{ ClientPattern::WORKSPACE, "workspace" },
|
|
|
|
{ ClientPattern::WORKSPACENAME, "workspacename" },
|
|
|
|
{ ClientPattern::HEAD, "head" },
|
|
|
|
{ ClientPattern::LAYER, "layer" },
|
|
|
|
{ ClientPattern::URGENT, "urgent" },
|
|
|
|
{ ClientPattern::SCREEN, "screen" },
|
|
|
|
{ ClientPattern::XPROP, "@" },
|
2010-09-09 13:33:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2010-09-10 14:35:49 +00:00
|
|
|
/**
|
|
|
|
* This is the type of the actual pattern we want to match against
|
|
|
|
* We have a "term" in the whole expression which is the full pattern
|
|
|
|
* we also need to keep track of the uncompiled regular expression
|
|
|
|
* for final output
|
|
|
|
*/
|
|
|
|
struct ClientPattern::Term {
|
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
Term(const FbTk::FbString& _regstr, WinProperty _prop, bool _negate, const FbTk::FbString& _xprop) :
|
|
|
|
regstr(_regstr),
|
|
|
|
xpropstr(_xprop),
|
2010-09-10 14:35:49 +00:00
|
|
|
regexp(_regstr, true),
|
|
|
|
prop(_prop),
|
|
|
|
negate(_negate) {
|
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
xprop = XInternAtom(FbTk::App::instance()->display(), xpropstr.c_str(), False);
|
2010-09-10 14:35:49 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
// (title=.*bar) or (@FOO=.*bar)
|
|
|
|
FbTk::FbString regstr; // .*bar
|
|
|
|
FbTk::FbString xpropstr; // @FOO=.*bar
|
|
|
|
Atom xprop; // Atom of 'FOO'
|
|
|
|
FbTk::RegExp regexp; // compiled version of '.*bar'
|
2010-09-10 14:35:49 +00:00
|
|
|
WinProperty prop;
|
|
|
|
bool negate;
|
|
|
|
};
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
ClientPattern::ClientPattern():
|
|
|
|
m_matchlimit(0),
|
|
|
|
m_nummatches(0) {}
|
|
|
|
|
|
|
|
// parse the given pattern (to end of line)
|
2008-08-19 16:18:32 +00:00
|
|
|
ClientPattern::ClientPattern(const char *str):
|
2003-06-12 15:12:19 +00:00
|
|
|
m_matchlimit(0),
|
|
|
|
m_nummatches(0)
|
|
|
|
{
|
|
|
|
/* A rough grammar of a pattern is:
|
|
|
|
PATTERN ::= MATCH+ LIMIT?
|
2006-10-27 06:57:43 +00:00
|
|
|
MATCH ::= '(' word ')'
|
2003-06-12 15:12:19 +00:00
|
|
|
| '(' propertyname '=' word ')'
|
|
|
|
LIMIT ::= '{' number '}'
|
2006-10-27 06:57:43 +00:00
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
i.e. one or more match definitions, followed by
|
|
|
|
an optional limit on the number of apps to match to
|
2006-10-27 06:57:43 +00:00
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
Match definitions are enclosed in parentheses, and if no
|
|
|
|
property name is given, then CLASSNAME is assumed.
|
|
|
|
If no limit is specified, no limit is applied (i.e. limit = infinity)
|
|
|
|
*/
|
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
bool had_error = false;
|
2003-06-12 15:12:19 +00:00
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
string match;
|
|
|
|
int err = 1; // for starting first loop
|
2007-10-13 21:51:37 +00:00
|
|
|
while (!had_error && err > 0) {
|
2006-10-27 06:57:43 +00:00
|
|
|
err = FbTk::StringUtil::getStringBetween(match,
|
2003-06-12 15:12:19 +00:00
|
|
|
str + pos,
|
|
|
|
'(', ')', " \t\n", true);
|
2010-09-11 15:09:07 +00:00
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
if (err > 0) {
|
2010-09-11 15:09:07 +00:00
|
|
|
|
|
|
|
WinProperty prop = NAME;
|
|
|
|
std::string expr;
|
|
|
|
std::string xprop;
|
2007-10-23 17:30:49 +00:00
|
|
|
bool negate = false;
|
2010-09-11 15:09:07 +00:00
|
|
|
|
|
|
|
// need to determine the property used, potential patterns:
|
|
|
|
//
|
|
|
|
// A) foo (short for 'title=foo')
|
|
|
|
// B) foo=bar
|
|
|
|
// C) foo!=bar
|
|
|
|
//
|
|
|
|
// D) @foo=bar (xproperty 'foo' equal to 'bar')
|
|
|
|
//
|
|
|
|
|
|
|
|
string propstr = match;
|
|
|
|
string::size_type eq = propstr.find_first_of('=');
|
|
|
|
|
|
|
|
if (eq == propstr.npos) { // A
|
|
|
|
expr = "[current]";
|
|
|
|
} else { // B or C, so strip away the '='
|
|
|
|
|
|
|
|
// 'bar'
|
|
|
|
expr.assign(propstr.begin() + eq + 1, propstr.end());
|
|
|
|
|
|
|
|
// 'foo' or 'foo!'
|
|
|
|
propstr.resize(eq);
|
|
|
|
if (propstr.rfind("!", propstr.npos, 1) != propstr.npos) { // C 'foo!'
|
|
|
|
negate = true;
|
|
|
|
propstr.resize(propstr.size()-1);
|
|
|
|
}
|
2007-10-23 17:30:49 +00:00
|
|
|
}
|
2009-10-01 06:57:31 +00:00
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
if (propstr[0] != '@') { // not D
|
2009-10-01 06:57:31 +00:00
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
const Name2WinProperty* p = find_winproperty_by_name(FbTk::StringUtil::toLower(propstr));
|
2010-09-09 13:33:12 +00:00
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
if (p) {
|
|
|
|
prop = p->prop;
|
|
|
|
} else {
|
|
|
|
expr = match;
|
|
|
|
}
|
|
|
|
} else { // D
|
|
|
|
prop = XPROP;
|
|
|
|
xprop.assign(propstr, 1, propstr.size());
|
2007-10-13 21:51:37 +00:00
|
|
|
}
|
2010-09-09 13:33:12 +00:00
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
had_error = !addTerm(expr, prop, negate, xprop);
|
2003-06-12 15:12:19 +00:00
|
|
|
pos += err;
|
2006-10-27 06:57:43 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
2010-09-11 15:09:07 +00:00
|
|
|
if (pos == 0 && !had_error) { // no match terms given, this is not allowed
|
2007-10-13 21:51:37 +00:00
|
|
|
had_error = true;
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 15:09:07 +00:00
|
|
|
if (!had_error) { // otherwise, we check for a number
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
string number;
|
2006-10-27 06:57:43 +00:00
|
|
|
err = FbTk::StringUtil::getStringBetween(number,
|
2003-06-12 15:12:19 +00:00
|
|
|
str+pos,
|
|
|
|
'{', '}');
|
|
|
|
if (err > 0) {
|
2010-09-10 14:35:49 +00:00
|
|
|
FbTk::StringUtil::extractNumber(number, m_matchlimit);
|
2003-06-12 15:12:19 +00:00
|
|
|
pos+=err;
|
|
|
|
}
|
|
|
|
// we don't care if there isn't one
|
2006-10-27 06:57:43 +00:00
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
// there shouldn't be anything else on the line
|
|
|
|
match = str + pos;
|
2006-04-16 11:18:22 +00:00
|
|
|
size_t uerr;// need a special type here
|
|
|
|
uerr = match.find_first_not_of(" \t\n", pos);
|
|
|
|
if (uerr != match.npos) {
|
2003-06-12 15:12:19 +00:00
|
|
|
// found something, not good
|
2007-10-13 21:51:37 +00:00
|
|
|
had_error = true;
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
if (had_error) {
|
2010-09-10 14:35:49 +00:00
|
|
|
FbTk::STLUtil::destroyAndClear(m_terms);
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
2006-10-27 06:57:43 +00:00
|
|
|
}
|
2003-06-12 15:12:19 +00:00
|
|
|
|
|
|
|
ClientPattern::~ClientPattern() {
|
2010-09-10 14:35:49 +00:00
|
|
|
FbTk::STLUtil::destroyAndClear(m_terms);
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return a string representation of this pattern
|
2006-10-27 06:57:43 +00:00
|
|
|
string ClientPattern::toString() const {
|
2010-09-11 15:09:07 +00:00
|
|
|
string result;
|
2003-06-12 15:12:19 +00:00
|
|
|
Terms::const_iterator it = m_terms.begin();
|
|
|
|
Terms::const_iterator it_end = m_terms.end();
|
|
|
|
for (; it != it_end; ++it) {
|
2010-09-11 15:09:07 +00:00
|
|
|
const Term& term = *(*it);
|
|
|
|
result.append(" (");
|
|
|
|
result.append(property_2_strings[term.prop].str);
|
|
|
|
if (term.prop == XPROP)
|
|
|
|
result.append(term.xpropstr);
|
|
|
|
result.append(term.negate ? "!=" : "=");
|
|
|
|
result.append(term.regstr);
|
|
|
|
result.append(")");
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_matchlimit > 0) {
|
2010-09-11 15:09:07 +00:00
|
|
|
result.append(" {");
|
|
|
|
result.append(FbTk::StringUtil::number2String(m_matchlimit));
|
|
|
|
result.append("}");
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
2010-09-11 15:09:07 +00:00
|
|
|
return result;
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// does this client match this pattern?
|
2007-10-13 21:51:37 +00:00
|
|
|
bool ClientPattern::match(const Focusable &win) const {
|
|
|
|
if (m_matchlimit != 0 && m_nummatches >= m_matchlimit)
|
2003-06-12 15:12:19 +00:00
|
|
|
return false; // already matched out
|
|
|
|
|
|
|
|
// regmatch everything
|
|
|
|
// currently, we use an "AND" policy for multiple terms
|
|
|
|
// changing to OR would require minor modifications in this function only
|
|
|
|
Terms::const_iterator it = m_terms.begin();
|
|
|
|
Terms::const_iterator it_end = m_terms.end();
|
|
|
|
for (; it != it_end; ++it) {
|
2010-09-10 14:35:49 +00:00
|
|
|
const Term& term = *(*it);
|
2010-09-11 15:09:07 +00:00
|
|
|
if (term.prop == XPROP) {
|
Can check CARDINAL properties in CLIENT PATTERNS
Introduces a new member function, FbWindow::cardinalProperty()
This change also changes other code that previously used
FbWindow::property() to do the same thing as the new function; this
reduces code duplication.
There are still some bits of code (Ewmh.cc, extractNetWmIcon()) that use
FbWindow::property() to retrieve XA_CARDINAL values, but as the new
method is designed for getting a _single_ property, and that code uses
FbWindow::property() to retrieve the number of values present, and then
grab all of them; it's a different use case. I opted to not try to make
cardinalProperty() into some monolithic all-purpose cardinal method;
FbWindow::property() works just fine for that.
This change also adds an optional (default=NULL) boolean to
FbWindow::textProperty and friends that allows the caller to determine
whether or not a value was actually retrieved. This was necessary for
integrating FbWindow::cardinalProperty with the codebase, and it seemed
to fit with FbWindow::textProperty as well. Prior to this change, if
you got a return value of "", you wouldn't know if you successfully
retrieved the value which happened to be blank, or if you failed to
retrieve the value. Now, you can pass the address of a boolean if you
so choose in order to differentiate these situations; the same applies
to the new FbWindow::cardinalProperty().
2011-05-08 02:38:13 +00:00
|
|
|
if (!term.negate ^ ((term.regexp.match(win.getTextProperty(term.xprop))) || term.regexp.match(FbTk::StringUtil::number2String(win.getCardinalProperty(term.xprop)))))
|
2010-09-11 15:09:07 +00:00
|
|
|
return false;
|
|
|
|
} else if (term.regstr == "[current]") {
|
2007-10-24 17:09:26 +00:00
|
|
|
WinClient *focused = FocusControl::focusedWindow();
|
2010-09-10 14:35:49 +00:00
|
|
|
if (term.prop == WORKSPACE) {
|
|
|
|
if (!term.negate ^ (getProperty(term.prop, win) == FbTk::StringUtil::number2String(win.screen().currentWorkspaceID())))
|
2007-11-12 21:59:43 +00:00
|
|
|
return false;
|
2010-09-10 14:35:49 +00:00
|
|
|
} else if (term.prop == WORKSPACENAME) {
|
2007-11-12 21:59:43 +00:00
|
|
|
const Workspace *w = win.screen().currentWorkspace();
|
2010-09-10 14:35:49 +00:00
|
|
|
if (!w || (!term.negate ^ (getProperty(term.prop, win) == w->name())))
|
2007-11-12 21:59:43 +00:00
|
|
|
return false;
|
2010-09-10 14:35:49 +00:00
|
|
|
} else if (!focused || (!term.negate ^ (getProperty(term.prop, win) == getProperty(term.prop, *focused))))
|
2007-10-13 21:51:37 +00:00
|
|
|
return false;
|
2010-09-11 15:09:07 +00:00
|
|
|
} else if (term.prop == HEAD && term.regstr == "[mouse]") {
|
2010-09-10 14:35:49 +00:00
|
|
|
if (!term.negate ^ (getProperty(term.prop, win) == FbTk::StringUtil::number2String(win.screen().getCurrHead())))
|
2007-10-22 18:29:33 +00:00
|
|
|
return false;
|
|
|
|
|
2010-09-10 14:35:49 +00:00
|
|
|
} else if (!term.negate ^ term.regexp.match(getProperty(term.prop, win)))
|
2003-06-12 15:12:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-11-12 21:59:43 +00:00
|
|
|
bool ClientPattern::dependsOnFocusedWindow() const {
|
|
|
|
Terms::const_iterator it = m_terms.begin(), it_end = m_terms.end();
|
|
|
|
for (; it != it_end; ++it) {
|
|
|
|
if ((*it)->prop != WORKSPACE && (*it)->prop != WORKSPACENAME &&
|
2010-09-11 15:09:07 +00:00
|
|
|
(*it)->regstr == "[current]")
|
2007-11-12 21:59:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientPattern::dependsOnCurrentWorkspace() const {
|
|
|
|
Terms::const_iterator it = m_terms.begin(), it_end = m_terms.end();
|
|
|
|
for (; it != it_end; ++it) {
|
|
|
|
if (((*it)->prop == WORKSPACE || (*it)->prop == WORKSPACENAME) &&
|
2010-09-11 15:09:07 +00:00
|
|
|
(*it)->regstr == "[current]")
|
2007-11-12 21:59:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
// add an expression to match against
|
|
|
|
// The first argument is a regular expression, the second is the member
|
|
|
|
// function that we wish to match against.
|
2010-09-11 15:09:07 +00:00
|
|
|
bool ClientPattern::addTerm(const FbTk::FbString &str, WinProperty prop, bool negate, const FbTk::FbString& xprop) {
|
2010-09-10 14:35:49 +00:00
|
|
|
|
|
|
|
bool rc = false;
|
2010-09-11 15:09:07 +00:00
|
|
|
Term* term = new Term(str, prop, negate, xprop);
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2010-09-10 14:35:49 +00:00
|
|
|
if (!term)
|
|
|
|
return rc;
|
2003-06-12 15:12:19 +00:00
|
|
|
|
2010-09-14 23:22:01 +00:00
|
|
|
if ((rc = !term->regexp.error())) {
|
2010-09-10 14:35:49 +00:00
|
|
|
m_terms.push_back(term);
|
|
|
|
} else {
|
2003-06-12 15:12:19 +00:00
|
|
|
delete term;
|
|
|
|
}
|
2010-09-10 14:35:49 +00:00
|
|
|
|
|
|
|
return rc;
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 18:17:21 +00:00
|
|
|
FbTk::FbString ClientPattern::getProperty(WinProperty prop, const Focusable &client) {
|
2010-09-14 23:22:01 +00:00
|
|
|
|
|
|
|
FbTk::FbString result;
|
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
// we need this for some of the window properties
|
|
|
|
const FluxboxWindow *fbwin = client.fbwindow();
|
|
|
|
|
2003-06-12 15:12:19 +00:00
|
|
|
switch (prop) {
|
|
|
|
case TITLE:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = client.title().logical();
|
2003-06-12 15:12:19 +00:00
|
|
|
break;
|
|
|
|
case CLASS:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = client.getWMClassClass();
|
2003-06-12 15:12:19 +00:00
|
|
|
break;
|
2004-04-28 13:04:06 +00:00
|
|
|
case ROLE:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = client.getWMRole();
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
2007-10-14 18:05:31 +00:00
|
|
|
case TRANSIENT:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = client.isTransient() ? "yes" : "no";
|
2007-10-14 18:05:31 +00:00
|
|
|
break;
|
2007-10-13 21:51:37 +00:00
|
|
|
case MAXIMIZED:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = (fbwin && fbwin->isMaximized()) ? "yes" : "no";
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case MINIMIZED:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = (fbwin && fbwin->isIconic()) ? "yes" : "no";
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case SHADED:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = (fbwin && fbwin->isShaded()) ? "yes" : "no";
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case STUCK:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = (fbwin && fbwin->isStuck()) ? "yes" : "no";
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case FOCUSHIDDEN:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = (fbwin && fbwin->isFocusHidden()) ? "yes" : "no";
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case ICONHIDDEN:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = (fbwin && fbwin->isIconHidden()) ? "yes" : "no";
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case WORKSPACE: {
|
2009-06-25 10:18:27 +00:00
|
|
|
unsigned int wsnum = (fbwin ? fbwin->workspaceNumber() : client.screen().currentWorkspaceID());
|
2010-09-14 23:22:01 +00:00
|
|
|
result = FbTk::StringUtil::number2String(wsnum);
|
2007-10-24 17:09:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WORKSPACENAME: {
|
2009-06-25 10:18:27 +00:00
|
|
|
const Workspace *w = (fbwin ?
|
|
|
|
client.screen().getWorkspace(fbwin->workspaceNumber()) :
|
|
|
|
client.screen().currentWorkspace());
|
2010-09-14 23:22:01 +00:00
|
|
|
if (w) {
|
|
|
|
result = w->name();
|
|
|
|
}
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-09-14 23:22:01 +00:00
|
|
|
case HEAD:
|
|
|
|
if (fbwin) {
|
|
|
|
result = FbTk::StringUtil::number2String(client.screen().getHead(fbwin->fbWindow()));
|
|
|
|
}
|
2007-10-13 21:51:37 +00:00
|
|
|
break;
|
|
|
|
case LAYER:
|
2010-09-14 23:22:01 +00:00
|
|
|
if (fbwin) {
|
2011-03-23 11:02:15 +00:00
|
|
|
result = ::ResourceLayer::getString(fbwin->layerNum());
|
2010-09-14 23:22:01 +00:00
|
|
|
}
|
2004-04-28 13:04:06 +00:00
|
|
|
break;
|
2008-06-08 18:29:47 +00:00
|
|
|
case URGENT:
|
2010-09-14 23:22:01 +00:00
|
|
|
result = Fluxbox::instance()->attentionHandler()
|
2008-06-08 18:29:47 +00:00
|
|
|
.isDemandingAttention(client) ? "yes" : "no";
|
|
|
|
break;
|
2010-09-14 23:22:01 +00:00
|
|
|
case SCREEN:
|
|
|
|
result = FbTk::StringUtil::number2String(client.screen().screenNumber());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XPROP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAME:
|
|
|
|
default:
|
|
|
|
result = client.getWMClassName();
|
2009-06-28 20:10:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-09-14 23:22:01 +00:00
|
|
|
return result;
|
2003-06-12 15:12:19 +00:00
|
|
|
}
|
2006-04-23 14:51:04 +00:00
|
|
|
|
2007-10-24 17:09:26 +00:00
|
|
|
bool ClientPattern::operator ==(const ClientPattern &pat) const {
|
2006-04-23 14:51:04 +00:00
|
|
|
// we require the terms to be identical (order too)
|
|
|
|
Terms::const_iterator it = m_terms.begin();
|
|
|
|
Terms::const_iterator it_end = m_terms.end();
|
|
|
|
Terms::const_iterator other_it = pat.m_terms.begin();
|
|
|
|
Terms::const_iterator other_it_end = pat.m_terms.end();
|
2006-08-10 14:55:52 +00:00
|
|
|
for (; it != it_end && other_it != other_it_end; ++it, ++other_it) {
|
2010-09-11 15:09:07 +00:00
|
|
|
const Term& i = *(*it);
|
|
|
|
const Term& o = *(*other_it);
|
|
|
|
if (i.regstr != o.regstr ||
|
|
|
|
i.negate != o.negate ||
|
|
|
|
i.xpropstr != o.xpropstr)
|
2006-04-23 14:51:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (it != it_end || other_it != other_it_end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-11 15:09:07 +00:00
|
|
|
|