1 // ClientPattern.hh for Fluxbox Window Manager 2 // Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) 3 // and Simon Bowden (rathnor at users.sourceforge.net) 4 // Copyright (c) 2002 Xavier Brouckaert 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 #ifndef CLIENTPATTERN_HH 25 #define CLIENTPATTERN_HH 26 27 #include "FbTk/RegExp.hh" 28 #include "FbTk/NotCopyable.hh" 29 #include "FbTk/FbString.hh" 30 31 #include <list> 32 33 class Focusable; 34 35 /** 36 * This class represents a "pattern" that we can match against a 37 * Window based on various properties. 38 */ 39 class ClientPattern:private FbTk::NotCopyable { 40 public: 41 ClientPattern(); 42 /** 43 * Create the pattern from the given string as it would appear in the 44 * apps file. the bool value returns the character at which 45 * there was a parse problem, or -1. 46 */ 47 explicit ClientPattern(const char * str); 48 49 ~ClientPattern(); 50 51 /// @return a string representation of this pattern 52 FbTk::FbString toString() const; 53 54 enum WinProperty { 55 TITLE = 0, CLASS, NAME, ROLE, TRANSIENT, 56 MAXIMIZED, MINIMIZED, SHADED, STUCK, FOCUSHIDDEN, ICONHIDDEN, 57 WORKSPACE, WORKSPACENAME, HEAD, LAYER, URGENT, SCREEN, 58 XPROP, FULLSCREEN, VERTMAX, HORZMAX 59 }; 60 61 /// Does this client match this pattern? 62 bool match(const Focusable &win) const; 63 64 /// Does this pattern depend on the focused window? 65 bool dependsOnFocusedWindow() const; 66 67 /// Does this pattern depend on the current workspace? 68 bool dependsOnCurrentWorkspace() const; 69 70 /** 71 * Add an expression to match against 72 * @param str is a regular expression 73 * @param prop is the member function that we wish to match against 74 * @param negate is if the term should be negated 75 * @param xprop is the name of the prop if prop is XPROP 76 * @return false if the regexp wasn't valid 77 */ 78 bool addTerm(const FbTk::FbString &str, WinProperty prop, bool negate = false, const FbTk::FbString& xprop = FbTk::FbString()); 79 addMatch()80 void addMatch() { ++m_nummatches; } removeMatch()81 void removeMatch() { --m_nummatches; } resetMatches()82 void resetMatches() { m_nummatches = 0; } 83 84 // whether this pattern has identical matching criteria 85 bool operator ==(const ClientPattern &pat) const; 86 87 /** 88 * If there are no terms, then there is assumed to be an error 89 * the column of the error is stored in m_matchlimit 90 */ error() const91 int error() const { return m_terms.empty() ? 1 : 0; } error_col() const92 int error_col() const { return m_matchlimit; } 93 94 static FbTk::FbString getProperty(WinProperty prop, const Focusable &client); 95 96 private: 97 struct Term; 98 friend struct Term; 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 int m_matchlimit; 103 int m_nummatches; 104 }; 105 106 #endif // CLIENTPATTERN_HH 107