00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KWIN_UTILS_H
00023 #define KWIN_UTILS_H
00024
00025 #include <config-workspace.h>
00026 #include <config-X11.h>
00027 #include <config-kwin.h>
00028
00029 #include <kwinconfig.h>
00030
00031 #include <X11/Xlib.h>
00032
00033 #include <fixx11h.h>
00034
00035 #include <QWidget>
00036 #include <kmanagerselection.h>
00037 #include <netwm_def.h>
00038 #include <kkeysequencewidget.h>
00039 #include <limits.h>
00040 #include <QX11Info>
00041 #include <kdialog.h>
00042
00043 #include <kwinglobals.h>
00044
00045
00046 Q_DECLARE_METATYPE(QList<int>)
00047
00048 namespace KWin
00049 {
00050
00051 #ifndef HAVE_XDAMAGE
00052 typedef long Damage;
00053 struct XDamageNotifyEvent
00054 {
00055 };
00056 #endif
00057
00058
00059 const int SUPPORTED_MANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
00060 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::TopMenuMask
00061 | NET::UtilityMask | NET::SplashMask;
00062
00063 const int SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
00064 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::TopMenuMask
00065 | NET::UtilityMask | NET::SplashMask | NET::DropdownMenuMask | NET::PopupMenuMask
00066 | NET::TooltipMask | NET::NotificationMask | NET::ComboBoxMask | NET::DNDIconMask;
00067
00068 const long ClientWinMask = KeyPressMask | KeyReleaseMask |
00069 ButtonPressMask | ButtonReleaseMask |
00070 KeymapStateMask |
00071 ButtonMotionMask |
00072 PointerMotionMask |
00073 EnterWindowMask | LeaveWindowMask |
00074 FocusChangeMask |
00075 ExposureMask |
00076 StructureNotifyMask |
00077 SubstructureRedirectMask;
00078
00079 const QPoint invalidPoint( INT_MIN, INT_MIN );
00080
00081 class Toplevel;
00082 class Client;
00083 class Unmanaged;
00084 class Deleted;
00085 class Group;
00086 class Options;
00087
00088 typedef QList< Toplevel* > ToplevelList;
00089 typedef QList< const Toplevel* > ConstToplevelList;
00090 typedef QList< Client* > ClientList;
00091 typedef QList< const Client* > ConstClientList;
00092 typedef QList< Unmanaged* > UnmanagedList;
00093 typedef QList< const Unmanaged* > ConstUnmanagedList;
00094 typedef QList< Deleted* > DeletedList;
00095 typedef QList< const Deleted* > ConstDeletedList;
00096
00097 typedef QList< Group* > GroupList;
00098 typedef QList< const Group* > ConstGroupList;
00099
00100 extern Options* options;
00101
00102 enum Layer
00103 {
00104 UnknownLayer = -1,
00105 FirstLayer = 0,
00106 DesktopLayer = FirstLayer,
00107 BelowLayer,
00108 NormalLayer,
00109 DockLayer,
00110 AboveLayer,
00111 ActiveLayer,
00112 NumLayers
00113 };
00114
00115
00116 inline void operator++( Layer& lay )
00117 {
00118 lay = static_cast< Layer >( lay + 1 );
00119 }
00120
00121
00122 enum ActivityFlags
00123 {
00124 ActivityFocus = 1 << 0,
00125 ActivityFocusForce = 1 << 1,
00126 ActivityRaise = 1 << 2
00127 };
00128
00129
00130
00131
00132
00133 enum allowed_t { Allowed };
00134
00135
00136 enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
00137
00138
00139
00140 enum ShadeMode
00141 {
00142 ShadeNone,
00143 ShadeNormal,
00144 ShadeHover,
00145 ShadeActivated
00146 };
00147
00148 enum HiddenPreviews
00149 {
00150 HiddenPreviewsNever,
00151 HiddenPreviewsKeep,
00152 HiddenPreviewUpdate,
00153 HiddenPreviewsActive
00154 };
00155
00156
00157 #ifndef ShapeInput
00158 const int ShapeInput = 2;
00159 #endif
00160
00161 class Motif
00162 {
00163 public:
00164 static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
00165 bool& minimize, bool& maximize, bool& close );
00166 struct MwmHints
00167 {
00168 ulong flags;
00169 ulong functions;
00170 ulong decorations;
00171 long input_mode;
00172 ulong status;
00173 };
00174 enum {
00175 MWM_HINTS_FUNCTIONS = (1L << 0),
00176 MWM_HINTS_DECORATIONS = (1L << 1),
00177
00178 MWM_FUNC_ALL = (1L << 0),
00179 MWM_FUNC_RESIZE = (1L << 1),
00180 MWM_FUNC_MOVE = (1L << 2),
00181 MWM_FUNC_MINIMIZE = (1L << 3),
00182 MWM_FUNC_MAXIMIZE = (1L << 4),
00183 MWM_FUNC_CLOSE = (1L << 5)
00184 };
00185 };
00186
00187 class KWinSelectionOwner
00188 : public KSelectionOwner
00189 {
00190 Q_OBJECT
00191 public:
00192 KWinSelectionOwner( int screen );
00193 protected:
00194 virtual bool genericReply( Atom target, Atom property, Window requestor );
00195 virtual void replyTargets( Atom property, Window requestor );
00196 virtual void getAtoms();
00197 private:
00198 Atom make_selection_atom( int screen );
00199 static Atom xa_version;
00200 };
00201
00202
00203
00204
00205
00206 template< typename T >
00207 class TemporaryAssign
00208 {
00209 public:
00210 TemporaryAssign( const T& var, const T& value )
00211 : variable( var ), orig( var )
00212 {
00213 const_cast< T& >( variable ) = value;
00214 }
00215 ~TemporaryAssign()
00216 {
00217 const_cast< T& >( variable ) = orig;
00218 }
00219 private:
00220 const T& variable;
00221 T orig;
00222 };
00223
00224 QByteArray getStringProperty(WId w, Atom prop, char separator=0);
00225 void updateXTime();
00226 void grabXServer();
00227 void ungrabXServer();
00228 bool grabbedXServer();
00229 bool grabXKeyboard( Window w = rootWindow());
00230 void ungrabXKeyboard();
00231
00232 class Scene;
00233 extern Scene* scene;
00234 inline bool compositing() { return scene != NULL; }
00235
00236
00237 #ifndef UrgencyHint
00238 #define UrgencyHint XUrgencyHint
00239 #endif
00240
00241
00242 #define KWIN_CHECK_PREDICATE( name, cls, check ) \
00243 struct name \
00244 { \
00245 inline bool operator()( const cls* cl ) { return check; } \
00246 }
00247
00248 #define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
00249 struct name \
00250 { \
00251 typedef type type_helper; \
00252 inline name( const type_helper& compare_value ) : value( compare_value ) {} \
00253 inline bool operator()( const cls* cl ) { return check; } \
00254 const type_helper& value; \
00255 }
00256
00257 #define KWIN_PROCEDURE( name, cls, action ) \
00258 struct name \
00259 { \
00260 inline void operator()( cls* cl ) { action; } \
00261 }
00262
00263 KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl );
00264
00265 template< typename T >
00266 Client* findClientInList( const ClientList& list, T predicate )
00267 {
00268 for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it)
00269 {
00270 if ( predicate( const_cast< const Client* >( *it)))
00271 return *it;
00272 }
00273 return NULL;
00274 }
00275
00276 template< typename T >
00277 Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate )
00278 {
00279 for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it)
00280 {
00281 if ( predicate( const_cast< const Unmanaged* >( *it)))
00282 return *it;
00283 }
00284 return NULL;
00285 }
00286
00287 inline
00288 int timestampCompare( Time time1, Time time2 )
00289 {
00290 return NET::timestampCompare( time1, time2 );
00291 }
00292
00293 inline
00294 Time timestampDiff( Time time1, Time time2 )
00295 {
00296 return NET::timestampDiff( time1, time2 );
00297 }
00298
00299 bool isLocalMachine( const QByteArray& host );
00300
00301 QPoint cursorPos();
00302
00303
00304 int qtToX11Button( Qt::MouseButton button );
00305 Qt::MouseButton x11ToQtMouseButton( int button );
00306 int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
00307 Qt::MouseButtons x11ToQtMouseButtons( int state );
00308 Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state );
00309
00310 void checkNonExistentClients();
00311
00312 #ifndef KCMRULES
00313
00314 class ShortcutDialog
00315 : public KDialog
00316 {
00317 Q_OBJECT
00318 public:
00319 ShortcutDialog( const QKeySequence& cut );
00320 virtual void accept();
00321 QKeySequence shortcut() const;
00322 signals:
00323 void dialogDone( bool ok );
00324 protected:
00325 virtual void done( int r );
00326 private:
00327 KKeySequenceWidget* widget;
00328 };
00329
00330 #endif //KCMRULES
00331
00332 }
00333
00334 #endif