minor cleaning

This commit is contained in:
fluxgen 2003-06-13 12:02:00 +00:00
parent cb14466431
commit b05f27d33a
2 changed files with 43 additions and 38 deletions

View file

@ -20,16 +20,16 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: ClientPattern.cc,v 1.1 2003/06/12 15:12:19 rathnor Exp $ // $Id: ClientPattern.cc,v 1.2 2003/06/13 12:01:06 fluxgen Exp $
#include "ClientPattern.hh" #include "ClientPattern.hh"
#include "RegExp.hh" #include "RegExp.hh"
#include "StringUtil.hh" #include "StringUtil.hh"
#include "WinClient.hh" #include "WinClient.hh"
//use GNU extensions // use GNU extensions
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif // _GNU_SOURCE #endif // _GNU_SOURCE
@ -41,10 +41,6 @@
using namespace std; using namespace std;
/********************************************************
* ClientPattern *
***********/
ClientPattern::ClientPattern(): ClientPattern::ClientPattern():
m_matchlimit(0), m_matchlimit(0),
m_nummatches(0) {} m_nummatches(0) {}
@ -161,17 +157,19 @@ std::string ClientPattern::toString() const {
Terms::const_iterator it_end = m_terms.end(); Terms::const_iterator it_end = m_terms.end();
for (; it != it_end; ++it) { for (; it != it_end; ++it) {
pat.append(" ("); pat.append(" (");
if ((*it)->prop == NAME) {
switch ((*it)->prop) {
case NAME:
// do nothing -> this is the default // do nothing -> this is the default
} else if ((*it)->prop == CLASS) { break;
case CLASS:
pat.append("class="); pat.append("class=");
} else if ((*it)->prop == TITLE) { break;
case TITLE:
pat.append("title="); pat.append("title=");
} else { break;
#ifdef DEBUG
cerr<<"WARNING: unknown window property, can't save properly"<<endl;
#endif //DEBUG
} }
pat.append((*it)->orig); pat.append((*it)->orig);
pat.append(")"); pat.append(")");
} }
@ -228,8 +226,8 @@ std::string ClientPattern::getProperty(WinProperty prop, const WinClient &client
return client.getWMClassClass(); return client.getWMClassClass();
break; break;
case NAME: case NAME:
default:
return client.getWMClassName(); return client.getWMClassName();
break; break;
} }
return client.getWMClassName();
} }

View file

@ -21,12 +21,13 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: ClientPattern.hh,v 1.1 2003/06/12 15:12:19 rathnor Exp $ // $Id: ClientPattern.hh,v 1.2 2003/06/13 12:02:00 fluxgen Exp $
#ifndef CLIENTPATTERN_HH #ifndef CLIENTPATTERN_HH
#define CLIENTPATTERN_HH #define CLIENTPATTERN_HH
#include "RegExp.hh" #include "RegExp.hh"
#include "NotCopyable.hh"
#include <string> #include <string>
#include <list> #include <list>
@ -37,28 +38,32 @@ class WinClient;
* This class represents a "pattern" that we can match against a * This class represents a "pattern" that we can match against a
* Window based on various properties. * Window based on various properties.
*/ */
class ClientPattern { class ClientPattern:private FbTk::NotCopyable {
public: public:
ClientPattern(); ClientPattern();
// create the pattern from the given string as it would appear in the /**
// apps file. the bool value returns the character at which * Create the pattern from the given string as it would appear in the
// there was a parse problem, or -1. * apps file. the bool value returns the character at which
* there was a parse problem, or -1.
*/
explicit ClientPattern(const char * str); explicit ClientPattern(const char * str);
~ClientPattern(); ~ClientPattern();
// return a string representation of this pattern /// @return a string representation of this pattern
std::string toString() const; std::string toString() const;
enum WinProperty { TITLE, CLASS, NAME }; enum WinProperty { TITLE, CLASS, NAME };
// does this client match this pattern? /// Does this client match this pattern?
bool match(const WinClient &win) const; bool match(const WinClient &win) const;
// add an expression to match against /**
// The first argument is a regular expression, the second is the member * Add an expression to match against
// function that we wish to match against. * @param str is a regular expression
// returns false if the regexp wasn't valid * @param prop is the member function that we wish to match against
* @return false if the regexp wasn't valid
*/
bool addTerm(const std::string &str, WinProperty prop); bool addTerm(const std::string &str, WinProperty prop);
inline void addMatch() { ++m_nummatches; } inline void addMatch() { ++m_nummatches; }
@ -68,18 +73,21 @@ public:
return match(win); return match(win);
} }
// if there are no terms, then there is assumed to be an error /**
// the column of the error is stored in m_matchlimit * If there are no terms, then there is assumed to be an error
inline int error() { return (m_terms.empty())?m_matchlimit:0; } * the column of the error is stored in m_matchlimit
*/
inline int error() const { return m_terms.empty() ? m_matchlimit : 0; }
std::string getProperty(WinProperty prop, const WinClient &winclient) const; std::string getProperty(WinProperty prop, const WinClient &winclient) const;
private: private:
// 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 * This is the type of the actual pattern we want to match against
// we also need to keep track of the uncompiled regular expression * We have a "term" in the whole expression which is the full pattern
// for final output * we also need to keep track of the uncompiled regular expression
* for final output
*/
struct Term { struct Term {
Term(const std::string &regstr, bool full_match) :regexp(regstr, full_match){}; Term(const std::string &regstr, bool full_match) :regexp(regstr, full_match){};
std::string orig; std::string orig;
@ -87,11 +95,10 @@ private:
WinProperty prop; WinProperty prop;
}; };
// our pattern is made up of a sequence of terms
// currently we "and" them all
typedef std::list<Term *> Terms; typedef std::list<Term *> Terms;
Terms m_terms; Terms m_terms; ///< our pattern is made up of a sequence of terms currently we "and" them all
int m_matchlimit, m_nummatches; int m_matchlimit, m_nummatches;
}; };