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 *********************************************************************/
25 #include <netwm_def.h>
27 #include <kconfiggroup.h>
30 #include "placement.h"
31 #include "lib/kdecoration.h"
43 #ifndef KCMRULES // only for kwin core
46 : public KDecorationDefines
49 WindowRules( const QVector
< Rules
* >& rules
);
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
85 MaximizeMode
checkMaximizeVert( MaximizeMode mode
, bool init
) const;
86 MaximizeMode
checkMaximizeHoriz( MaximizeMode mode
, bool init
) const;
87 QVector
< Rules
* > rules
;
92 : public KDecorationDefines
96 Rules( const KConfigGroup
& );
97 Rules( const QString
&, bool temporary
);
98 void write( KConfigGroup
& ) const;
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
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!
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
156 UnusedSetRule
= Unused
,
157 SetRuleDummy
= 256 // so that it's at least short int
161 UnusedForceRule
= Unused
,
162 ForceRuleDummy
= 256 // so that it's at least short int
167 UnimportantMatch
= FirstStringMatch
,
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
);
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
);
183 int temporary_state
; // e.g. for kstart
186 StringMatch wmclassmatch
;
187 bool wmclasscomplete
;
188 QByteArray windowrole
;
189 StringMatch windowrolematch
;
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
;
200 SetRule positionrule
;
204 ForceRule minsizerule
;
206 ForceRule maxsizerule
;
208 ForceRule opacityactiverule
;
210 ForceRule opacityinactiverule
;
212 ForceRule ignorepositionrule
;
215 NET::WindowType type
; // type for setting
218 SetRule maximizevertrule
;
220 SetRule maximizehorizrule
;
222 SetRule minimizerule
;
226 SetRule skiptaskbarrule
;
228 SetRule skippagerrule
;
234 SetRule fullscreenrule
;
236 SetRule noborderrule
;
238 ForceRule fsplevelrule
;
240 ForceRule acceptfocusrule
;
241 Options::MoveResizeMode moveresizemode
;
242 ForceRule moveresizemoderule
;
244 ForceRule closeablerule
;
246 ForceRule strictgeometryrule
;
248 SetRule shortcutrule
;
249 bool disableglobalshortcuts
;
250 ForceRule disableglobalshortcutsrule
;
251 friend kdbgstream
& operator<<( kdbgstream
& stream
, const Rules
* );
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
)
268 bool Rules::checkForceRule( ForceRule rule
)
270 return rule
== ( ForceRule
)Force
|| rule
== ( ForceRule
) ForceTemporarily
;
274 bool Rules::checkSetStop( SetRule rule
)
276 return rule
!= UnusedSetRule
;
280 bool Rules::checkForceStop( ForceRule rule
)
282 return rule
!= UnusedForceRule
;
286 WindowRules::WindowRules( const QVector
< Rules
* >& r
)
292 WindowRules::WindowRules()
297 bool WindowRules::contains( const Rules
* rule
) const
299 return qFind( rules
.begin(), rules
.end(), rule
) != rules
.end();
303 void WindowRules::remove( Rules
* rule
)
305 QVector
< Rules
* >::Iterator pos
= qFind( rules
.begin(), rules
.end(), rule
);
306 if( pos
!= rules
.end())
312 kdbgstream
& operator<<( kdbgstream
& stream
, const Rules
* );