00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KWIN_RULES_H
00022 #define KWIN_RULES_H
00023
00024
00025 #include <netwm_def.h>
00026 #include <QRect>
00027 #include <kconfiggroup.h>
00028 #include <kdebug.h>
00029
00030 #include "placement.h"
00031 #include "lib/kdecoration.h"
00032 #include "options.h"
00033 #include "utils.h"
00034
00035 class KConfig;
00036
00037 namespace KWin
00038 {
00039
00040 class Client;
00041 class Rules;
00042
00043 #ifndef KCMRULES // only for kwin core
00044
00045 class WindowRules
00046 : public KDecorationDefines
00047 {
00048 public:
00049 WindowRules( const QVector< Rules* >& rules );
00050 WindowRules();
00051 void update( Client* );
00052 void discardTemporary();
00053 bool contains( const Rules* rule ) const;
00054 void remove( Rules* rule );
00055 Placement::Policy checkPlacement( Placement::Policy placement ) const;
00056 QRect checkGeometry( QRect rect, bool init = false ) const;
00057
00058 QPoint checkPosition( QPoint pos, bool init = false ) const;
00059 QSize checkSize( QSize s, bool init = false ) const;
00060 QSize checkMinSize( QSize s ) const;
00061 QSize checkMaxSize( QSize s ) const;
00062 int checkOpacityActive(int s) const;
00063 int checkOpacityInactive(int s) const;
00064 bool checkIgnoreGeometry( bool ignore ) const;
00065 int checkDesktop( int desktop, bool init = false ) const;
00066 NET::WindowType checkType( NET::WindowType type ) const;
00067 MaximizeMode checkMaximize( MaximizeMode mode, bool init = false ) const;
00068 bool checkMinimize( bool minimized, bool init = false ) const;
00069 ShadeMode checkShade( ShadeMode shade, bool init = false ) const;
00070 bool checkSkipTaskbar( bool skip, bool init = false ) const;
00071 bool checkSkipPager( bool skip, bool init = false ) const;
00072 bool checkKeepAbove( bool above, bool init = false ) const;
00073 bool checkKeepBelow( bool below, bool init = false ) const;
00074 bool checkFullScreen( bool fs, bool init = false ) const;
00075 bool checkNoBorder( bool noborder, bool init = false ) const;
00076 int checkFSP( int fsp ) const;
00077 bool checkAcceptFocus( bool focus ) const;
00078 Options::MoveResizeMode checkMoveResizeMode( Options::MoveResizeMode mode ) const;
00079 bool checkCloseable( bool closeable ) const;
00080 bool checkStrictGeometry( bool strict ) const;
00081 QString checkShortcut( QString s, bool init = false ) const;
00082 bool checkDisableGlobalShortcuts( bool disable ) const;
00083 bool checkIgnorePosition( bool ignore ) const;
00084 private:
00085 MaximizeMode checkMaximizeVert( MaximizeMode mode, bool init ) const;
00086 MaximizeMode checkMaximizeHoriz( MaximizeMode mode, bool init ) const;
00087 QVector< Rules* > rules;
00088 };
00089 #endif
00090
00091 class Rules
00092 : public KDecorationDefines
00093 {
00094 public:
00095 Rules();
00096 Rules( const KConfigGroup& );
00097 Rules( const QString&, bool temporary );
00098 void write( KConfigGroup& ) const;
00099 bool isEmpty() const;
00100 #ifndef KCMRULES
00101 void discardUsed( bool withdrawn );
00102 bool match( const Client* c ) const;
00103 bool update( Client* );
00104 bool isTemporary() const;
00105 bool discardTemporary( bool force );
00106 bool applyPlacement( Placement::Policy& placement ) const;
00107 bool applyGeometry( QRect& rect, bool init ) const;
00108
00109 bool applyPosition( QPoint& pos, bool init ) const;
00110 bool applySize( QSize& s, bool init ) const;
00111 bool applyMinSize( QSize& s ) const;
00112 bool applyMaxSize( QSize& s ) const;
00113 bool applyOpacityActive(int& s) const;
00114 bool applyOpacityInactive(int& s) const;
00115 bool applyIgnoreGeometry( bool& ignore ) const;
00116 bool applyDesktop( int& desktop, bool init ) const;
00117 bool applyType( NET::WindowType& type ) const;
00118 bool applyMaximizeVert( MaximizeMode& mode, bool init ) const;
00119 bool applyMaximizeHoriz( MaximizeMode& mode, bool init ) const;
00120 bool applyMinimize( bool& minimized, bool init ) const;
00121 bool applyShade( ShadeMode& shade, bool init ) const;
00122 bool applySkipTaskbar( bool& skip, bool init ) const;
00123 bool applySkipPager( bool& skip, bool init ) const;
00124 bool applyKeepAbove( bool& above, bool init ) const;
00125 bool applyKeepBelow( bool& below, bool init ) const;
00126 bool applyFullScreen( bool& fs, bool init ) const;
00127 bool applyNoBorder( bool& noborder, bool init ) const;
00128 bool applyFSP( int& fsp ) const;
00129 bool applyAcceptFocus( bool& focus ) const;
00130 bool applyMoveResizeMode( Options::MoveResizeMode& mode ) const;
00131 bool applyCloseable( bool& closeable ) const;
00132 bool applyStrictGeometry( bool& strict ) const;
00133 bool applyShortcut( QString& shortcut, bool init ) const;
00134 bool applyDisableGlobalShortcuts( bool& disable ) const;
00135 bool applyIgnorePosition( bool& ignore ) const;
00136 private:
00137 #endif
00138 bool matchType( NET::WindowType match_type ) const;
00139 bool matchWMClass( const QByteArray& match_class, const QByteArray& match_name ) const;
00140 bool matchRole( const QByteArray& match_role ) const;
00141 bool matchTitle( const QString& match_title ) const;
00142 bool matchClientMachine( const QByteArray& match_machine ) const;
00143
00144 enum
00145 {
00146 Unused = 0,
00147 DontAffect,
00148 Force,
00149 Apply,
00150 Remember,
00151 ApplyNow,
00152 ForceTemporarily
00153 };
00154 enum SetRule
00155 {
00156 UnusedSetRule = Unused,
00157 SetRuleDummy = 256
00158 };
00159 enum ForceRule
00160 {
00161 UnusedForceRule = Unused,
00162 ForceRuleDummy = 256
00163 };
00164 enum StringMatch
00165 {
00166 FirstStringMatch,
00167 UnimportantMatch = FirstStringMatch,
00168 ExactMatch,
00169 SubstringMatch,
00170 RegExpMatch,
00171 LastStringMatch = RegExpMatch
00172 };
00173 void readFromCfg( const KConfigGroup& cfg );
00174 static SetRule readSetRule( const KConfigGroup&, const QString& key );
00175 static ForceRule readForceRule( const KConfigGroup&, const QString& key );
00176 static NET::WindowType readType( const KConfigGroup&, const QString& key );
00177 #ifndef KCMRULES
00178 static bool checkSetRule( SetRule rule, bool init );
00179 static bool checkForceRule( ForceRule rule );
00180 static bool checkSetStop( SetRule rule );
00181 static bool checkForceStop( ForceRule rule );
00182 #endif
00183 int temporary_state;
00184 QString description;
00185 QByteArray wmclass;
00186 StringMatch wmclassmatch;
00187 bool wmclasscomplete;
00188 QByteArray windowrole;
00189 StringMatch windowrolematch;
00190 QString title;
00191 StringMatch titlematch;
00192 QByteArray extrarole;
00193 StringMatch extrarolematch;
00194 QByteArray clientmachine;
00195 StringMatch clientmachinematch;
00196 unsigned long types;
00197 Placement::Policy placement;
00198 ForceRule placementrule;
00199 QPoint position;
00200 SetRule positionrule;
00201 QSize size;
00202 SetRule sizerule;
00203 QSize minsize;
00204 ForceRule minsizerule;
00205 QSize maxsize;
00206 ForceRule maxsizerule;
00207 int opacityactive;
00208 ForceRule opacityactiverule;
00209 int opacityinactive;
00210 ForceRule opacityinactiverule;
00211 bool ignoreposition;
00212 ForceRule ignorepositionrule;
00213 int desktop;
00214 SetRule desktoprule;
00215 NET::WindowType type;
00216 ForceRule typerule;
00217 bool maximizevert;
00218 SetRule maximizevertrule;
00219 bool maximizehoriz;
00220 SetRule maximizehorizrule;
00221 bool minimize;
00222 SetRule minimizerule;
00223 bool shade;
00224 SetRule shaderule;
00225 bool skiptaskbar;
00226 SetRule skiptaskbarrule;
00227 bool skippager;
00228 SetRule skippagerrule;
00229 bool above;
00230 SetRule aboverule;
00231 bool below;
00232 SetRule belowrule;
00233 bool fullscreen;
00234 SetRule fullscreenrule;
00235 bool noborder;
00236 SetRule noborderrule;
00237 int fsplevel;
00238 ForceRule fsplevelrule;
00239 bool acceptfocus;
00240 ForceRule acceptfocusrule;
00241 Options::MoveResizeMode moveresizemode;
00242 ForceRule moveresizemoderule;
00243 bool closeable;
00244 ForceRule closeablerule;
00245 bool strictgeometry;
00246 ForceRule strictgeometryrule;
00247 QString shortcut;
00248 SetRule shortcutrule;
00249 bool disableglobalshortcuts;
00250 ForceRule disableglobalshortcutsrule;
00251 friend kdbgstream& operator<<( kdbgstream& stream, const Rules* );
00252 };
00253
00254 #ifndef KCMRULES
00255 inline
00256 bool Rules::checkSetRule( SetRule rule, bool init )
00257 {
00258 if( rule > ( SetRule )DontAffect)
00259 {
00260 if( rule == ( SetRule )Force || rule == ( SetRule ) ApplyNow
00261 || rule == ( SetRule ) ForceTemporarily || init )
00262 return true;
00263 }
00264 return false;
00265 }
00266
00267 inline
00268 bool Rules::checkForceRule( ForceRule rule )
00269 {
00270 return rule == ( ForceRule )Force || rule == ( ForceRule ) ForceTemporarily;
00271 }
00272
00273 inline
00274 bool Rules::checkSetStop( SetRule rule )
00275 {
00276 return rule != UnusedSetRule;
00277 }
00278
00279 inline
00280 bool Rules::checkForceStop( ForceRule rule )
00281 {
00282 return rule != UnusedForceRule;
00283 }
00284
00285 inline
00286 WindowRules::WindowRules( const QVector< Rules* >& r )
00287 : rules( r )
00288 {
00289 }
00290
00291 inline
00292 WindowRules::WindowRules()
00293 {
00294 }
00295
00296 inline
00297 bool WindowRules::contains( const Rules* rule ) const
00298 {
00299 return qFind( rules.begin(), rules.end(), rule ) != rules.end();
00300 }
00301
00302 inline
00303 void WindowRules::remove( Rules* rule )
00304 {
00305 QVector< Rules* >::Iterator pos = qFind( rules.begin(), rules.end(), rule );
00306 if( pos != rules.end())
00307 rules.erase( pos );
00308 }
00309
00310 #endif
00311
00312 kdbgstream& operator<<( kdbgstream& stream, const Rules* );
00313
00314 }
00315
00316 #endif