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
00149
00150 enum HiddenPreviews
00151 {
00152
00153
00154
00155 HiddenPreviewsNever,
00156
00157
00158 HiddenPreviewsShown,
00159
00160 HiddenPreviewsAlways
00161 };
00162
00163
00164 #ifndef ShapeInput
00165 const int ShapeInput = 2;
00166 #endif
00167
00168 class Motif
00169 {
00170 public:
00171 static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
00172 bool& minimize, bool& maximize, bool& close );
00173 struct MwmHints
00174 {
00175 ulong flags;
00176 ulong functions;
00177 ulong decorations;
00178 long input_mode;
00179 ulong status;
00180 };
00181 enum {
00182 MWM_HINTS_FUNCTIONS = (1L << 0),
00183 MWM_HINTS_DECORATIONS = (1L << 1),
00184
00185 MWM_FUNC_ALL = (1L << 0),
00186 MWM_FUNC_RESIZE = (1L << 1),
00187 MWM_FUNC_MOVE = (1L << 2),
00188 MWM_FUNC_MINIMIZE = (1L << 3),
00189 MWM_FUNC_MAXIMIZE = (1L << 4),
00190 MWM_FUNC_CLOSE = (1L << 5)
00191 };
00192 };
00193
00194 class KWinSelectionOwner
00195 : public KSelectionOwner
00196 {
00197 Q_OBJECT
00198 public:
00199 KWinSelectionOwner( int screen );
00200 protected:
00201 virtual bool genericReply( Atom target, Atom property, Window requestor );
00202 virtual void replyTargets( Atom property, Window requestor );
00203 virtual void getAtoms();
00204 private:
00205 Atom make_selection_atom( int screen );
00206 static Atom xa_version;
00207 };
00208
00209
00210
00211
00212
00213 template< typename T >
00214 class TemporaryAssign
00215 {
00216 public:
00217 TemporaryAssign( const T& var, const T& value )
00218 : variable( var ), orig( var )
00219 {
00220 const_cast< T& >( variable ) = value;
00221 }
00222 ~TemporaryAssign()
00223 {
00224 const_cast< T& >( variable ) = orig;
00225 }
00226 private:
00227 const T& variable;
00228 T orig;
00229 };
00230
00231 QByteArray getStringProperty(WId w, Atom prop, char separator=0);
00232 void updateXTime();
00233 void grabXServer();
00234 void ungrabXServer();
00235 bool grabbedXServer();
00236 bool grabXKeyboard( Window w = rootWindow());
00237 void ungrabXKeyboard();
00238
00239 class Scene;
00240 extern Scene* scene;
00241 inline bool compositing() { return scene != NULL; }
00242
00243
00244 #ifndef UrgencyHint
00245 #define UrgencyHint XUrgencyHint
00246 #endif
00247
00248
00249 #define KWIN_CHECK_PREDICATE( name, cls, check ) \
00250 struct name \
00251 { \
00252 inline bool operator()( const cls* cl ) { return check; } \
00253 }
00254
00255 #define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
00256 struct name \
00257 { \
00258 typedef type type_helper; \
00259 inline name( const type_helper& compare_value ) : value( compare_value ) {} \
00260 inline bool operator()( const cls* cl ) { return check; } \
00261 const type_helper& value; \
00262 }
00263
00264 #define KWIN_PROCEDURE( name, cls, action ) \
00265 struct name \
00266 { \
00267 inline void operator()( cls* cl ) { action; } \
00268 }
00269
00270 KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl );
00271
00272 template< typename T >
00273 Client* findClientInList( const ClientList& list, T predicate )
00274 {
00275 for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it)
00276 {
00277 if ( predicate( const_cast< const Client* >( *it)))
00278 return *it;
00279 }
00280 return NULL;
00281 }
00282
00283 template< typename T >
00284 Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate )
00285 {
00286 for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it)
00287 {
00288 if ( predicate( const_cast< const Unmanaged* >( *it)))
00289 return *it;
00290 }
00291 return NULL;
00292 }
00293
00294 inline
00295 int timestampCompare( Time time1, Time time2 )
00296 {
00297 return NET::timestampCompare( time1, time2 );
00298 }
00299
00300 inline
00301 Time timestampDiff( Time time1, Time time2 )
00302 {
00303 return NET::timestampDiff( time1, time2 );
00304 }
00305
00306 bool isLocalMachine( const QByteArray& host );
00307
00308 QPoint cursorPos();
00309
00310
00311 int qtToX11Button( Qt::MouseButton button );
00312 Qt::MouseButton x11ToQtMouseButton( int button );
00313 int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
00314 Qt::MouseButtons x11ToQtMouseButtons( int state );
00315 Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state );
00316
00317 void checkNonExistentClients();
00318
00319 #ifndef KCMRULES
00320
00321 class ShortcutDialog
00322 : public KDialog
00323 {
00324 Q_OBJECT
00325 public:
00326 ShortcutDialog( const QKeySequence& cut );
00327 virtual void accept();
00328 QKeySequence shortcut() const;
00329 public Q_SLOTS:
00330 void keySequenceChanged(const QKeySequence &seq);
00331 signals:
00332 void dialogDone( bool ok );
00333 protected:
00334 virtual void done( int r );
00335 private:
00336 KKeySequenceWidget* widget;
00337 QKeySequence _shortcut;
00338 };
00339
00340 #endif //KCMRULES
00341
00342 }
00343
00344 #endif