rules.h

00001 /*****************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 2004 Lubos Lunak <l.lunak@kde.org>
00006 
00007 You can Freely distribute this program under the GNU General Public
00008 License. See the file "COPYING" for the exact licensing terms.
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         bool contains( const Rules* rule ) const;
00044         void remove( Rules* rule );
00045         Placement::Policy checkPlacement( Placement::Policy placement ) const;
00046         QRect checkGeometry( QRect rect, bool init = false ) const;
00047         // use 'invalidPoint' with checkPosition, unlike QSize() and QRect(), QPoint() is a valid point
00048         QPoint checkPosition( QPoint pos, bool init = false ) const;
00049         QSize checkSize( QSize s, bool init = false ) const;
00050         QSize checkMinSize( QSize s ) const;
00051         QSize checkMaxSize( QSize s ) const;
00052         int checkOpacityActive(int s) const;
00053         int checkOpacityInactive(int s) const;
00054         bool checkIgnoreGeometry( bool ignore ) const;
00055         int checkDesktop( int desktop, bool init = false ) const;
00056         NET::WindowType checkType( NET::WindowType type ) const;
00057         MaximizeMode checkMaximize( MaximizeMode mode, bool init = false ) const;
00058         bool checkMinimize( bool minimized, bool init = false ) const;
00059         ShadeMode checkShade( ShadeMode shade, bool init = false ) const;
00060         bool checkSkipTaskbar( bool skip, bool init = false ) const;
00061         bool checkSkipPager( bool skip, bool init = false ) const;
00062         bool checkKeepAbove( bool above, bool init = false ) const;
00063         bool checkKeepBelow( bool below, bool init = false ) const;
00064         bool checkFullScreen( bool fs, bool init = false ) const;
00065         bool checkNoBorder( bool noborder, bool init = false ) const;
00066         int checkFSP( int fsp ) const;
00067         bool checkAcceptFocus( bool focus ) const;
00068         Options::MoveResizeMode checkMoveResizeMode( Options::MoveResizeMode mode ) const;
00069         bool checkCloseable( bool closeable ) const;
00070         bool checkStrictGeometry( bool strict ) const;
00071         QString checkShortcut( QString s, bool init = false ) const;
00072         bool checkDisableGlobalShortcuts( bool disable ) const;
00073         bool checkIgnorePosition( bool ignore ) const; // obsolete
00074     private:
00075         MaximizeMode checkMaximizeVert( MaximizeMode mode, bool init ) const;
00076         MaximizeMode checkMaximizeHoriz( MaximizeMode mode, bool init ) const;
00077         QValueVector< Rules* > rules;
00078     };
00079 #endif
00080 
00081 class Rules
00082     : public KDecorationDefines
00083     {
00084     public:
00085         Rules();
00086         Rules( KConfig& );
00087         Rules( const QString&, bool temporary );
00088         void write( KConfig& ) const;
00089         bool isEmpty() const;
00090 #ifndef KCMRULES
00091         void discardUsed( bool withdrawn );
00092         bool match( const Client* c ) const;
00093         bool update( Client* );
00094         bool isTemporary() const;
00095         bool discardTemporary( bool force ); // removes if temporary and forced or too old
00096         bool applyPlacement( Placement::Policy& placement ) const;
00097         bool applyGeometry( QRect& rect, bool init ) const;
00098         // use 'invalidPoint' with applyPosition, unlike QSize() and QRect(), QPoint() is a valid point
00099         bool applyPosition( QPoint& pos, bool init ) const;
00100         bool applySize( QSize& s, bool init ) const;
00101         bool applyMinSize( QSize& s ) const;
00102         bool applyMaxSize( QSize& s ) const;
00103         bool applyOpacityActive(int& s) const;
00104         bool applyOpacityInactive(int& s) const;
00105         bool applyIgnoreGeometry( bool& ignore ) const;
00106         bool applyDesktop( int& desktop, bool init ) const;
00107         bool applyType( NET::WindowType& type ) const;
00108         bool applyMaximizeVert( MaximizeMode& mode, bool init ) const;
00109         bool applyMaximizeHoriz( MaximizeMode& mode, bool init ) const;
00110         bool applyMinimize( bool& minimized, bool init ) const;
00111         bool applyShade( ShadeMode& shade, bool init ) const;
00112         bool applySkipTaskbar( bool& skip, bool init ) const;
00113         bool applySkipPager( bool& skip, bool init ) const;
00114         bool applyKeepAbove( bool& above, bool init ) const;
00115         bool applyKeepBelow( bool& below, bool init ) const;
00116         bool applyFullScreen( bool& fs, bool init ) const;
00117         bool applyNoBorder( bool& noborder, bool init ) const;
00118         bool applyFSP( int& fsp ) const;
00119         bool applyAcceptFocus( bool& focus ) const;
00120         bool applyMoveResizeMode( Options::MoveResizeMode& mode ) const;
00121         bool applyCloseable( bool& closeable ) const;
00122         bool applyStrictGeometry( bool& strict ) const;
00123         bool applyShortcut( QString& shortcut, bool init ) const;
00124         bool applyDisableGlobalShortcuts( bool& disable ) const;
00125         bool applyIgnorePosition( bool& ignore ) const; // obsolete
00126     private:
00127 #endif
00128         bool matchType( NET::WindowType match_type ) const;
00129         bool matchWMClass( const QCString& match_class, const QCString& match_name ) const;
00130         bool matchRole( const QCString& match_role ) const;
00131         bool matchTitle( const QString& match_title ) const;
00132         bool matchClientMachine( const QCString& match_machine ) const;
00133         // All these values are saved to the cfg file, and are also used in kstart!
00134         enum
00135             {
00136             Unused = 0,
00137             DontAffect, // use the default value
00138             Force,      // force the given value
00139             Apply,      // apply only after initial mapping
00140             Remember,   // like apply, and remember the value when the window is withdrawn
00141             ApplyNow,   // apply immediatelly, then forget the setting
00142             ForceTemporarily // apply and force until the window is withdrawn
00143             };
00144         enum SetRule
00145             {
00146             UnusedSetRule = Unused,
00147             SetRuleDummy = 256   // so that it's at least short int
00148             };
00149         enum ForceRule
00150             {
00151             UnusedForceRule = Unused,
00152             ForceRuleDummy = 256   // so that it's at least short int
00153             };
00154         enum StringMatch
00155             {
00156             FirstStringMatch,
00157             UnimportantMatch = FirstStringMatch,
00158             ExactMatch,
00159             SubstringMatch,
00160             RegExpMatch,
00161             LastStringMatch = RegExpMatch
00162             };
00163         void readFromCfg( KConfig& cfg );
00164         static SetRule readSetRule( KConfig&, const QString& key );
00165         static ForceRule readForceRule( KConfig&, const QString& key );
00166         static NET::WindowType readType( KConfig&, const QString& key );
00167 #ifndef KCMRULES
00168         static bool checkSetRule( SetRule rule, bool init );
00169         static bool checkForceRule( ForceRule rule );
00170         static bool checkSetStop( SetRule rule );
00171         static bool checkForceStop( ForceRule rule );
00172 #endif
00173         int temporary_state; // e.g. for kstart
00174         QString description;
00175         QCString wmclass;
00176         StringMatch wmclassmatch;
00177         bool wmclasscomplete;
00178         QCString windowrole;
00179         StringMatch windowrolematch;
00180         QString title; // TODO "caption" ?
00181         StringMatch titlematch;
00182         QCString extrarole;
00183         StringMatch extrarolematch;
00184         QCString clientmachine;
00185         StringMatch clientmachinematch;
00186         unsigned long types; // types for matching
00187         Placement::Policy placement;
00188         ForceRule placementrule;
00189         QPoint position;
00190         SetRule positionrule;
00191         QSize size;
00192         SetRule sizerule;
00193         QSize minsize;
00194         ForceRule minsizerule;
00195         QSize maxsize;
00196         ForceRule maxsizerule;
00197         int opacityactive;
00198         ForceRule opacityactiverule;
00199         int opacityinactive;
00200         ForceRule opacityinactiverule;
00201         bool ignoreposition;
00202         ForceRule ignorepositionrule;
00203         int desktop;
00204         SetRule desktoprule;
00205         NET::WindowType type; // type for setting
00206         ForceRule typerule;
00207         bool maximizevert;
00208         SetRule maximizevertrule;
00209         bool maximizehoriz;
00210         SetRule maximizehorizrule;
00211         bool minimize;
00212         SetRule minimizerule;
00213         bool shade;
00214         SetRule shaderule;
00215         bool skiptaskbar;
00216         SetRule skiptaskbarrule;
00217         bool skippager;
00218         SetRule skippagerrule;
00219         bool above;
00220         SetRule aboverule;
00221         bool below;
00222         SetRule belowrule;
00223         bool fullscreen;
00224         SetRule fullscreenrule;
00225         bool noborder;
00226         SetRule noborderrule;
00227         int fsplevel;
00228         ForceRule fsplevelrule;
00229         bool acceptfocus;
00230         ForceRule acceptfocusrule;
00231         Options::MoveResizeMode moveresizemode;
00232         ForceRule moveresizemoderule;
00233         bool closeable;
00234         ForceRule closeablerule;
00235         bool strictgeometry;
00236         ForceRule strictgeometryrule;
00237         QString shortcut;
00238         SetRule shortcutrule;
00239         bool disableglobalshortcuts;
00240         ForceRule disableglobalshortcutsrule;
00241         friend kdbgstream& operator<<( kdbgstream& stream, const Rules* );
00242     };
00243 
00244 #ifndef KCMRULES
00245 inline
00246 bool Rules::checkSetRule( SetRule rule, bool init )
00247     {
00248     if( rule > ( SetRule )DontAffect) // Unused or DontAffect
00249         {
00250         if( rule == ( SetRule )Force || rule == ( SetRule ) ApplyNow
00251             || rule == ( SetRule ) ForceTemporarily || init )
00252             return true;
00253         }
00254     return false;
00255     }
00256 
00257 inline
00258 bool Rules::checkForceRule( ForceRule rule )
00259     {
00260     return rule == ( ForceRule )Force || rule == ( ForceRule ) ForceTemporarily;
00261     }
00262 
00263 inline
00264 bool Rules::checkSetStop( SetRule rule )
00265     {
00266     return rule != UnusedSetRule;
00267     }
00268     
00269 inline
00270 bool Rules::checkForceStop( ForceRule rule )
00271     {
00272     return rule != UnusedForceRule;
00273     }
00274 
00275 inline
00276 WindowRules::WindowRules( const QValueVector< Rules* >& r )
00277     : rules( r )
00278     {
00279     }
00280 
00281 inline
00282 WindowRules::WindowRules()
00283     {
00284     }
00285 
00286 inline
00287 bool WindowRules::contains( const Rules* rule ) const
00288     {
00289     return qFind( rules.begin(), rules.end(), rule ) != rules.end();
00290     }
00291     
00292 inline
00293 void WindowRules::remove( Rules* rule )
00294     {
00295     QValueVector< Rules* >::Iterator pos = qFind( rules.begin(), rules.end(), rule );
00296     if( pos != rules.end())
00297         rules.erase( pos );
00298     }
00299 
00300 #endif
00301 
00302 #ifdef NDEBUG
00303 inline
00304 kndbgstream& operator<<( kndbgstream& stream, const Rules* ) { return stream; }
00305 #else
00306 kdbgstream& operator<<( kdbgstream& stream, const Rules* );
00307 #endif
00308 
00309 } // namespace
00310 
00311 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys