add more spacing
[personal-kdebase.git] / workspace / kwin / rules.h
blob1152a94c9b5cf96c47879f52afeecbbc2e4ba4f0
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2004 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #ifndef KWIN_RULES_H
22 #define KWIN_RULES_H
25 #include <netwm_def.h>
26 #include <QRect>
27 #include <kconfiggroup.h>
28 #include <kdebug.h>
30 #include "placement.h"
31 #include "lib/kdecoration.h"
32 #include "options.h"
33 #include "utils.h"
35 class KConfig;
37 namespace KWin
40 class Client;
41 class Rules;
43 #ifndef KCMRULES // only for kwin core
45 class WindowRules
46 : public KDecorationDefines
48 public:
49 WindowRules( const QVector< Rules* >& rules );
50 WindowRules();
51 void update( Client* );
52 void discardTemporary();
53 bool contains( const Rules* rule ) const;
54 void remove( Rules* rule );
55 Placement::Policy checkPlacement( Placement::Policy placement ) const;
56 QRect checkGeometry( QRect rect, bool init = false ) const;
57 // use 'invalidPoint' with checkPosition, unlike QSize() and QRect(), QPoint() is a valid point
58 QPoint checkPosition( QPoint pos, bool init = false ) const;
59 QSize checkSize( QSize s, bool init = false ) const;
60 QSize checkMinSize( QSize s ) const;
61 QSize checkMaxSize( QSize s ) const;
62 int checkOpacityActive(int s) const;
63 int checkOpacityInactive(int s) const;
64 bool checkIgnoreGeometry( bool ignore ) const;
65 int checkDesktop( int desktop, bool init = false ) const;
66 NET::WindowType checkType( NET::WindowType type ) const;
67 MaximizeMode checkMaximize( MaximizeMode mode, bool init = false ) const;
68 bool checkMinimize( bool minimized, bool init = false ) const;
69 ShadeMode checkShade( ShadeMode shade, bool init = false ) const;
70 bool checkSkipTaskbar( bool skip, bool init = false ) const;
71 bool checkSkipPager( bool skip, bool init = false ) const;
72 bool checkKeepAbove( bool above, bool init = false ) const;
73 bool checkKeepBelow( bool below, bool init = false ) const;
74 bool checkFullScreen( bool fs, bool init = false ) const;
75 bool checkNoBorder( bool noborder, bool init = false ) const;
76 int checkFSP( int fsp ) const;
77 bool checkAcceptFocus( bool focus ) const;
78 Options::MoveResizeMode checkMoveResizeMode( Options::MoveResizeMode mode ) const;
79 bool checkCloseable( bool closeable ) const;
80 bool checkStrictGeometry( bool strict ) const;
81 QString checkShortcut( QString s, bool init = false ) const;
82 bool checkDisableGlobalShortcuts( bool disable ) const;
83 bool checkIgnorePosition( bool ignore ) const; // obsolete
84 private:
85 MaximizeMode checkMaximizeVert( MaximizeMode mode, bool init ) const;
86 MaximizeMode checkMaximizeHoriz( MaximizeMode mode, bool init ) const;
87 QVector< Rules* > rules;
89 #endif
91 class Rules
92 : public KDecorationDefines
94 public:
95 Rules();
96 Rules( const KConfigGroup& );
97 Rules( const QString&, bool temporary );
98 void write( KConfigGroup& ) const;
99 bool isEmpty() const;
100 #ifndef KCMRULES
101 void discardUsed( bool withdrawn );
102 bool match( const Client* c ) const;
103 bool update( Client* );
104 bool isTemporary() const;
105 bool discardTemporary( bool force ); // removes if temporary and forced or too old
106 bool applyPlacement( Placement::Policy& placement ) const;
107 bool applyGeometry( QRect& rect, bool init ) const;
108 // use 'invalidPoint' with applyPosition, unlike QSize() and QRect(), QPoint() is a valid point
109 bool applyPosition( QPoint& pos, bool init ) const;
110 bool applySize( QSize& s, bool init ) const;
111 bool applyMinSize( QSize& s ) const;
112 bool applyMaxSize( QSize& s ) const;
113 bool applyOpacityActive(int& s) const;
114 bool applyOpacityInactive(int& s) const;
115 bool applyIgnoreGeometry( bool& ignore ) const;
116 bool applyDesktop( int& desktop, bool init ) const;
117 bool applyType( NET::WindowType& type ) const;
118 bool applyMaximizeVert( MaximizeMode& mode, bool init ) const;
119 bool applyMaximizeHoriz( MaximizeMode& mode, bool init ) const;
120 bool applyMinimize( bool& minimized, bool init ) const;
121 bool applyShade( ShadeMode& shade, bool init ) const;
122 bool applySkipTaskbar( bool& skip, bool init ) const;
123 bool applySkipPager( bool& skip, bool init ) const;
124 bool applyKeepAbove( bool& above, bool init ) const;
125 bool applyKeepBelow( bool& below, bool init ) const;
126 bool applyFullScreen( bool& fs, bool init ) const;
127 bool applyNoBorder( bool& noborder, bool init ) const;
128 bool applyFSP( int& fsp ) const;
129 bool applyAcceptFocus( bool& focus ) const;
130 bool applyMoveResizeMode( Options::MoveResizeMode& mode ) const;
131 bool applyCloseable( bool& closeable ) const;
132 bool applyStrictGeometry( bool& strict ) const;
133 bool applyShortcut( QString& shortcut, bool init ) const;
134 bool applyDisableGlobalShortcuts( bool& disable ) const;
135 bool applyIgnorePosition( bool& ignore ) const; // obsolete
136 private:
137 #endif
138 bool matchType( NET::WindowType match_type ) const;
139 bool matchWMClass( const QByteArray& match_class, const QByteArray& match_name ) const;
140 bool matchRole( const QByteArray& match_role ) const;
141 bool matchTitle( const QString& match_title ) const;
142 bool matchClientMachine( const QByteArray& match_machine ) const;
143 // All these values are saved to the cfg file, and are also used in kstart!
144 enum
146 Unused = 0,
147 DontAffect, // use the default value
148 Force, // force the given value
149 Apply, // apply only after initial mapping
150 Remember, // like apply, and remember the value when the window is withdrawn
151 ApplyNow, // apply immediatelly, then forget the setting
152 ForceTemporarily // apply and force until the window is withdrawn
154 enum SetRule
156 UnusedSetRule = Unused,
157 SetRuleDummy = 256 // so that it's at least short int
159 enum ForceRule
161 UnusedForceRule = Unused,
162 ForceRuleDummy = 256 // so that it's at least short int
164 enum StringMatch
166 FirstStringMatch,
167 UnimportantMatch = FirstStringMatch,
168 ExactMatch,
169 SubstringMatch,
170 RegExpMatch,
171 LastStringMatch = RegExpMatch
173 void readFromCfg( const KConfigGroup& cfg );
174 static SetRule readSetRule( const KConfigGroup&, const QString& key );
175 static ForceRule readForceRule( const KConfigGroup&, const QString& key );
176 static NET::WindowType readType( const KConfigGroup&, const QString& key );
177 #ifndef KCMRULES
178 static bool checkSetRule( SetRule rule, bool init );
179 static bool checkForceRule( ForceRule rule );
180 static bool checkSetStop( SetRule rule );
181 static bool checkForceStop( ForceRule rule );
182 #endif
183 int temporary_state; // e.g. for kstart
184 QString description;
185 QByteArray wmclass;
186 StringMatch wmclassmatch;
187 bool wmclasscomplete;
188 QByteArray windowrole;
189 StringMatch windowrolematch;
190 QString title;
191 StringMatch titlematch;
192 QByteArray extrarole;
193 StringMatch extrarolematch;
194 QByteArray clientmachine;
195 StringMatch clientmachinematch;
196 unsigned long types; // types for matching
197 Placement::Policy placement;
198 ForceRule placementrule;
199 QPoint position;
200 SetRule positionrule;
201 QSize size;
202 SetRule sizerule;
203 QSize minsize;
204 ForceRule minsizerule;
205 QSize maxsize;
206 ForceRule maxsizerule;
207 int opacityactive;
208 ForceRule opacityactiverule;
209 int opacityinactive;
210 ForceRule opacityinactiverule;
211 bool ignoreposition;
212 ForceRule ignorepositionrule;
213 int desktop;
214 SetRule desktoprule;
215 NET::WindowType type; // type for setting
216 ForceRule typerule;
217 bool maximizevert;
218 SetRule maximizevertrule;
219 bool maximizehoriz;
220 SetRule maximizehorizrule;
221 bool minimize;
222 SetRule minimizerule;
223 bool shade;
224 SetRule shaderule;
225 bool skiptaskbar;
226 SetRule skiptaskbarrule;
227 bool skippager;
228 SetRule skippagerrule;
229 bool above;
230 SetRule aboverule;
231 bool below;
232 SetRule belowrule;
233 bool fullscreen;
234 SetRule fullscreenrule;
235 bool noborder;
236 SetRule noborderrule;
237 int fsplevel;
238 ForceRule fsplevelrule;
239 bool acceptfocus;
240 ForceRule acceptfocusrule;
241 Options::MoveResizeMode moveresizemode;
242 ForceRule moveresizemoderule;
243 bool closeable;
244 ForceRule closeablerule;
245 bool strictgeometry;
246 ForceRule strictgeometryrule;
247 QString shortcut;
248 SetRule shortcutrule;
249 bool disableglobalshortcuts;
250 ForceRule disableglobalshortcutsrule;
251 friend kdbgstream& operator<<( kdbgstream& stream, const Rules* );
254 #ifndef KCMRULES
255 inline
256 bool Rules::checkSetRule( SetRule rule, bool init )
258 if( rule > ( SetRule )DontAffect) // Unused or DontAffect
260 if( rule == ( SetRule )Force || rule == ( SetRule ) ApplyNow
261 || rule == ( SetRule ) ForceTemporarily || init )
262 return true;
264 return false;
267 inline
268 bool Rules::checkForceRule( ForceRule rule )
270 return rule == ( ForceRule )Force || rule == ( ForceRule ) ForceTemporarily;
273 inline
274 bool Rules::checkSetStop( SetRule rule )
276 return rule != UnusedSetRule;
279 inline
280 bool Rules::checkForceStop( ForceRule rule )
282 return rule != UnusedForceRule;
285 inline
286 WindowRules::WindowRules( const QVector< Rules* >& r )
287 : rules( r )
291 inline
292 WindowRules::WindowRules()
296 inline
297 bool WindowRules::contains( const Rules* rule ) const
299 return qFind( rules.begin(), rules.end(), rule ) != rules.end();
302 inline
303 void WindowRules::remove( Rules* rule )
305 QVector< Rules* >::Iterator pos = qFind( rules.begin(), rules.end(), rule );
306 if( pos != rules.end())
307 rules.erase( pos );
310 #endif
312 kdbgstream& operator<<( kdbgstream& stream, const Rules* );
314 } // namespace
316 #endif