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