diff options
Diffstat (limited to 'src/ClientPattern.hh')
-rw-r--r-- | src/ClientPattern.hh | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/ClientPattern.hh b/src/ClientPattern.hh new file mode 100644 index 0000000..7e89511 --- /dev/null +++ b/src/ClientPattern.hh | |||
@@ -0,0 +1,106 @@ | |||
1 | // ClientPattern.hh for Fluxbox Window Manager | ||
2 | // Copyright (c) 2002 Xavier Brouckaert | ||
3 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
4 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
5 | // | ||
6 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
7 | // copy of this software and associated documentation files (the "Software"), | ||
8 | // to deal in the Software without restriction, including without limitation | ||
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
10 | // and/or sell copies of the Software, and to permit persons to whom the | ||
11 | // Software is furnished to do so, subject to the following conditions: | ||
12 | // | ||
13 | // The above copyright notice and this permission notice shall be included in | ||
14 | // all copies or substantial portions of the Software. | ||
15 | // | ||
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
19 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
21 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
22 | // DEALINGS IN THE SOFTWARE. | ||
23 | |||
24 | // $Id: ClientPattern.hh,v 1.2 2003/06/13 12:02:00 fluxgen Exp $ | ||
25 | |||
26 | #ifndef CLIENTPATTERN_HH | ||
27 | #define CLIENTPATTERN_HH | ||
28 | |||
29 | #include "RegExp.hh" | ||
30 | #include "NotCopyable.hh" | ||
31 | |||
32 | #include <string> | ||
33 | #include <list> | ||
34 | |||
35 | class WinClient; | ||
36 | |||
37 | /** | ||
38 | * This class represents a "pattern" that we can match against a | ||
39 | * Window based on various properties. | ||
40 | */ | ||
41 | class ClientPattern:private FbTk::NotCopyable { | ||
42 | public: | ||
43 | ClientPattern(); | ||
44 | /** | ||
45 | * Create the pattern from the given string as it would appear in the | ||
46 | * apps file. the bool value returns the character at which | ||
47 | * there was a parse problem, or -1. | ||
48 | */ | ||
49 | explicit ClientPattern(const char * str); | ||
50 | |||
51 | ~ClientPattern(); | ||
52 | |||
53 | /// @return a string representation of this pattern | ||
54 | std::string toString() const; | ||
55 | |||
56 | enum WinProperty { TITLE, CLASS, NAME }; | ||
57 | |||
58 | /// Does this client match this pattern? | ||
59 | bool match(const WinClient &win) const; | ||
60 | |||
61 | /** | ||
62 | * Add an expression to match against | ||
63 | * @param str is a regular expression | ||
64 | * @param prop is the member function that we wish to match against | ||
65 | * @return false if the regexp wasn't valid | ||
66 | */ | ||
67 | bool addTerm(const std::string &str, WinProperty prop); | ||
68 | |||
69 | inline void addMatch() { ++m_nummatches; } | ||
70 | inline void delMatch() { --m_nummatches; } | ||
71 | |||
72 | inline bool operator == (const WinClient &win) const { | ||
73 | return match(win); | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * If there are no terms, then there is assumed to be an error | ||
78 | * the column of the error is stored in m_matchlimit | ||
79 | */ | ||
80 | inline int error() const { return m_terms.empty() ? m_matchlimit : 0; } | ||
81 | |||
82 | std::string getProperty(WinProperty prop, const WinClient &winclient) const; | ||
83 | |||
84 | private: | ||
85 | /** | ||
86 | * This is the type of the actual pattern we want to match against | ||
87 | * We have a "term" in the whole expression which is the full pattern | ||
88 | * we also need to keep track of the uncompiled regular expression | ||
89 | * for final output | ||
90 | */ | ||
91 | struct Term { | ||
92 | Term(const std::string ®str, bool full_match) :regexp(regstr, full_match){}; | ||
93 | std::string orig; | ||
94 | RegExp regexp; | ||
95 | WinProperty prop; | ||
96 | }; | ||
97 | |||
98 | |||
99 | typedef std::list<Term *> Terms; | ||
100 | |||
101 | Terms m_terms; ///< our pattern is made up of a sequence of terms currently we "and" them all | ||
102 | |||
103 | int m_matchlimit, m_nummatches; | ||
104 | }; | ||
105 | |||
106 | #endif // CLIENTPATTERN_HH | ||