utils.h

00001 /*****************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
00006 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
00007 
00008 You can Freely distribute this program under the GNU General Public
00009 License. See the file "COPYING" for the exact licensing terms.
00010 ******************************************************************/
00011 
00012 #ifndef KWIN_UTILS_H
00013 #define KWIN_UTILS_H
00014 
00015 #include <qvaluelist.h>
00016 #include <qwidget.h>
00017 #include <kmanagerselection.h>
00018 #include <netwm_def.h>
00019 #include <kshortcutdialog.h>
00020 
00021 namespace KWinInternal
00022 {
00023 
00024 const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
00025     | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
00026     | NET::UtilityMask | NET::SplashMask;
00027 
00028 const long ClientWinMask = KeyPressMask | KeyReleaseMask |
00029                           ButtonPressMask | ButtonReleaseMask |
00030                   KeymapStateMask |
00031                   ButtonMotionMask |
00032                   PointerMotionMask | // need this, too!
00033                   EnterWindowMask | LeaveWindowMask |
00034                   FocusChangeMask |
00035                   ExposureMask |
00036                   StructureNotifyMask |
00037                   SubstructureRedirectMask;
00038 
00039 const QPoint invalidPoint( INT_MIN, INT_MIN );
00040 
00041 class Client;
00042 class Group;
00043 class Options;
00044 
00045 typedef QValueList< Client* > ClientList;
00046 typedef QValueList< const Client* > ConstClientList;
00047 
00048 typedef QValueList< Group* > GroupList;
00049 typedef QValueList< const Group* > ConstGroupList;
00050 
00051 extern Options* options;
00052 
00053 enum Layer
00054     {
00055     UnknownLayer = -1,
00056     FirstLayer = 0,
00057     DesktopLayer = FirstLayer,
00058     BelowLayer,
00059     NormalLayer,
00060     DockLayer,
00061     AboveLayer,
00062     ActiveLayer, // active fullscreen, or active dialog
00063     NumLayers // number of layers, must be last
00064     };
00065 
00066 // yes, I know this is not 100% like standard operator++
00067 inline void operator++( Layer& lay )
00068     {
00069     lay = static_cast< Layer >( lay + 1 );
00070     }
00071 
00072 // for Client::takeActivity()
00073 enum ActivityFlags
00074     {
00075     ActivityFocus = 1 << 0, // focus the window
00076     ActivityFocusForce = 1 << 1, // focus even if Dock etc.
00077     ActivityRaise = 1 << 2 // raise the window
00078     };
00079 
00080 // Some KWin classes, mainly Client and Workspace, are very tighly coupled,
00081 // and some of the methods of one class may be called only from speficic places.
00082 // Those methods have additional allowed_t argument. If you pass Allowed
00083 // as an argument to any function, make sure you really know what you're doing.
00084 enum allowed_t { Allowed };
00085 
00086 // some enums to have more readable code, instead of using bools
00087 enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
00088 
00089 // Areas, mostly related to Xinerama
00090 enum clientAreaOption
00091     {
00092     PlacementArea,         // geometry where a window will be initially placed after being mapped
00093     MovementArea,          // ???  window movement snapping area?  ignore struts
00094     MaximizeArea,          // geometry to which a window will be maximized
00095     MaximizeFullArea,      // like MaximizeArea, but ignore struts - used e.g. for topmenu
00096     FullScreenArea,        // area for fullscreen windows
00097     // these below don't depend on xinerama settings
00098     WorkArea,              // whole workarea (all screens together)
00099     FullArea,              // whole area (all screens together), ignore struts
00100     ScreenArea,            // one whole screen, ignore struts
00101     FullXineramaArea
00102     };
00103 
00104 enum ShadeMode
00105     {
00106     ShadeNone, // not shaded
00107     ShadeNormal, // normally shaded - isShade() is true only here
00108     ShadeHover, // "shaded", but visible due to hover unshade
00109     ShadeActivated // "shaded", but visible due to alt+tab to the window
00110     };
00111 
00112 class Shape 
00113     {
00114     public:
00115         static bool available() { return kwin_has_shape; }
00116         static bool hasShape( WId w);
00117         static int shapeEvent();
00118         static void init();
00119     private:
00120         static int kwin_has_shape;
00121         static int kwin_shape_event;
00122     };
00123 
00124 class Motif 
00125     {
00126     public:
00127         static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
00128             bool& minimize, bool& maximize, bool& close );
00129         struct MwmHints 
00130             {
00131             ulong flags;
00132             ulong functions;
00133             ulong decorations;
00134             long input_mode;
00135             ulong status;
00136             };
00137         enum {
00138             MWM_HINTS_FUNCTIONS = (1L << 0),
00139             MWM_HINTS_DECORATIONS =  (1L << 1),
00140 
00141             MWM_FUNC_ALL = (1L << 0),
00142             MWM_FUNC_RESIZE = (1L << 1),
00143             MWM_FUNC_MOVE = (1L << 2),
00144             MWM_FUNC_MINIMIZE = (1L << 3),
00145             MWM_FUNC_MAXIMIZE = (1L << 4),
00146             MWM_FUNC_CLOSE = (1L << 5)
00147             };
00148     };
00149 
00150 class KWinSelectionOwner
00151     : public KSelectionOwner
00152     {
00153     Q_OBJECT
00154     public:
00155         KWinSelectionOwner( int screen );
00156     protected:
00157         virtual bool genericReply( Atom target, Atom property, Window requestor );
00158         virtual void replyTargets( Atom property, Window requestor );
00159         virtual void getAtoms();
00160     private:
00161         Atom make_selection_atom( int screen );
00162         static Atom xa_version;
00163     };
00164 
00165 // Class which saves original value of the variable, assigns the new value
00166 // to it, and in the destructor restores the value.
00167 // Used in Client::isMaximizable() and so on.
00168 // It also casts away contness and generally this looks like a hack.
00169 template< typename T >
00170 class TemporaryAssign
00171     {
00172     public:
00173         TemporaryAssign( const T& var, const T& value )
00174             : variable( var ), orig( var )
00175             {
00176             const_cast< T& >( variable ) = value;
00177             }
00178         ~TemporaryAssign()
00179             {
00180             const_cast< T& >( variable ) = orig;
00181             }
00182     private:
00183         const T& variable;
00184         T orig;
00185     };
00186 
00187 QCString getStringProperty(WId w, Atom prop, char separator=0);
00188 void updateXTime();
00189 void grabXServer();
00190 void ungrabXServer();
00191 bool grabbedXServer();
00192 
00193 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
00194 #ifndef UrgencyHint
00195 #define UrgencyHint XUrgencyHint
00196 #endif
00197 
00198 // for STL-like algo's
00199 #define KWIN_CHECK_PREDICATE( name, check ) \
00200 struct name \
00201     { \
00202     inline bool operator()( const Client* cl ) { return check; }; \
00203     }
00204 
00205 #define KWIN_COMPARE_PREDICATE( name, type, check ) \
00206 struct name \
00207     { \
00208     typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
00209     inline name( const type_helper& compare_value ) : value( compare_value ) {}; \
00210     inline bool operator()( const Client* cl ) { return check; }; \
00211     const type_helper& value; \
00212     }
00213 
00214 #define KWIN_PROCEDURE( name, action ) \
00215 struct name \
00216     { \
00217     inline void operator()( Client* cl ) { action; }; \
00218     }
00219 
00220 KWIN_CHECK_PREDICATE( TruePredicate, cl == cl /*true, avoid warning about 'cl' */ );
00221 
00222 template< typename T >
00223 Client* findClientInList( const ClientList& list, T predicate )
00224     {
00225     for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it) 
00226         {
00227         if ( predicate( const_cast< const Client* >( *it)))
00228             return *it;
00229         }
00230     return NULL;
00231     }
00232 
00233 inline
00234 int timestampCompare( Time time1, Time time2 ) // like strcmp()
00235     {
00236     if( time1 == time2 )
00237         return 0;
00238     return ( time1 - time2 ) < 1000000000 ? 1 : -1; // time1 > time2 -> 1, handle wrapping
00239     }
00240 
00241 inline
00242 Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1
00243     { // no need to handle wrapping?
00244     return time2 - time1;
00245     }
00246 
00247 bool isLocalMachine( const QCString& host );
00248 
00249 #ifndef KCMRULES
00250 // Qt dialogs emit no signal when closed :(
00251 class ShortcutDialog
00252     : public KShortcutDialog
00253     {
00254     Q_OBJECT
00255     public:
00256         ShortcutDialog( const KShortcut& cut );
00257         virtual void accept();
00258     signals:
00259         void dialogDone( bool ok );
00260     protected:
00261         virtual void done( int r ) { KShortcutDialog::done( r ); emit dialogDone( r == Accepted ); }
00262     };
00263 #endif
00264 
00265 } // namespace
00266 
00267 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys