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 <tqvaluelist.h> 00016 #include <tqwidget.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 TQPoint invalidPoint( INT_MIN, INT_MIN ); 00040 00041 class Client; 00042 class Group; 00043 class Options; 00044 00045 typedef TQValueList< Client* > ClientList; 00046 typedef TQValueList< const Client* > ConstClientList; 00047 00048 typedef TQValueList< Group* > GroupList; 00049 typedef TQValueList< 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 }; 00102 00103 enum ShadeMode 00104 { 00105 ShadeNone, // not shaded 00106 ShadeNormal, // normally shaded - isShade() is true only here 00107 ShadeHover, // "shaded", but visible due to hover unshade 00108 ShadeActivated // "shaded", but visible due to alt+tab to the window 00109 }; 00110 00111 class Shape 00112 { 00113 public: 00114 static bool available() { return kwin_shape_version > 0; } 00115 static int version() { return kwin_shape_version; } // as 16*major+minor, i.e. two hex digits 00116 static bool hasShape( WId w); 00117 static int shapeEvent(); 00118 static void init(); 00119 private: 00120 static int kwin_shape_version; 00121 static int kwin_shape_event; 00122 }; 00123 00124 // compile with XShape older than 1.0 00125 #ifndef ShapeInput 00126 const int ShapeInput = 2; 00127 #endif 00128 00129 class Motif 00130 { 00131 public: 00132 static void readFlags( WId w, bool& noborder, bool& resize, bool& move, 00133 bool& minimize, bool& maximize, bool& close ); 00134 struct MwmHints 00135 { 00136 ulong flags; 00137 ulong functions; 00138 ulong decorations; 00139 long input_mode; 00140 ulong status; 00141 }; 00142 enum { 00143 MWM_HINTS_FUNCTIONS = (1L << 0), 00144 MWM_HINTS_DECORATIONS = (1L << 1), 00145 00146 MWM_FUNC_ALL = (1L << 0), 00147 MWM_FUNC_RESIZE = (1L << 1), 00148 MWM_FUNC_MOVE = (1L << 2), 00149 MWM_FUNC_MINIMIZE = (1L << 3), 00150 MWM_FUNC_MAXIMIZE = (1L << 4), 00151 MWM_FUNC_CLOSE = (1L << 5) 00152 }; 00153 }; 00154 00155 class KWinSelectionOwner 00156 : public KSelectionOwner 00157 { 00158 Q_OBJECT 00159 public: 00160 KWinSelectionOwner( int screen ); 00161 protected: 00162 virtual bool genericReply( Atom target, Atom property, Window requestor ); 00163 virtual void replyTargets( Atom property, Window requestor ); 00164 virtual void getAtoms(); 00165 private: 00166 Atom make_selection_atom( int screen ); 00167 static Atom xa_version; 00168 }; 00169 00170 // Class which saves original value of the variable, assigns the new value 00171 // to it, and in the destructor restores the value. 00172 // Used in Client::isMaximizable() and so on. 00173 // It also casts away contness and generally this looks like a hack. 00174 template< typename T > 00175 class TemporaryAssign 00176 { 00177 public: 00178 TemporaryAssign( const T& var, const T& value ) 00179 : variable( var ), orig( var ) 00180 { 00181 const_cast< T& >( variable ) = value; 00182 } 00183 ~TemporaryAssign() 00184 { 00185 const_cast< T& >( variable ) = orig; 00186 } 00187 private: 00188 const T& variable; 00189 T orig; 00190 }; 00191 00192 TQCString getStringProperty(WId w, Atom prop, char separator=0); 00193 void updateXTime(); 00194 void grabXServer(); 00195 void ungrabXServer(); 00196 bool grabbedXServer(); 00197 00198 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint 00199 #ifndef UrgencyHint 00200 #define UrgencyHint XUrgencyHint 00201 #endif 00202 00203 // for STL-like algo's 00204 #define KWIN_CHECK_PREDICATE( name, check ) \ 00205 struct name \ 00206 { \ 00207 inline bool operator()( const Client* cl ) { return check; }; \ 00208 } 00209 00210 #define KWIN_COMPARE_PREDICATE( name, type, check ) \ 00211 struct name \ 00212 { \ 00213 typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \ 00214 inline name( const type_helper& compare_value ) : value( compare_value ) {}; \ 00215 inline bool operator()( const Client* cl ) { return check; }; \ 00216 const type_helper& value; \ 00217 } 00218 00219 #define KWIN_PROCEDURE( name, action ) \ 00220 struct name \ 00221 { \ 00222 inline void operator()( Client* cl ) { action; }; \ 00223 } 00224 00225 KWIN_CHECK_PREDICATE( TruePredicate, cl == cl /*true, avoid warning about 'cl' */ ); 00226 00227 template< typename T > 00228 Client* findClientInList( const ClientList& list, T predicate ) 00229 { 00230 for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it) 00231 { 00232 if ( predicate( const_cast< const Client* >( *it))) 00233 return *it; 00234 } 00235 return NULL; 00236 } 00237 00238 inline 00239 int timestampCompare( Time time1, Time time2 ) // like strcmp() 00240 { 00241 return NET::timestampCompare( time1, time2 ); 00242 } 00243 00244 inline 00245 Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1 00246 { 00247 return NET::timestampDiff( time1, time2 ); 00248 } 00249 00250 bool isLocalMachine( const TQCString& host ); 00251 00252 void checkNonExistentClients(); 00253 00254 #ifndef KCMRULES 00255 // Qt dialogs emit no signal when closed :( 00256 class ShortcutDialog 00257 : public KShortcutDialog 00258 { 00259 Q_OBJECT 00260 public: 00261 ShortcutDialog( const KShortcut& cut ); 00262 virtual void accept(); 00263 virtual void hide(); 00264 signals: 00265 void dialogDone( bool ok ); 00266 protected: 00267 virtual void done( int r ) { KShortcutDialog::done( r ); emit dialogDone( r == Accepted ); } 00268 }; 00269 #endif 00270 00271 } // namespace 00272 00273 #endif