kwin Library API Documentation

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