From 2e84c74fc8df7122da6abaa7bc8ecdf607286ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Fri, 5 Jan 2007 16:32:32 +0000 Subject: [PATCH] Functions also for converting from X11 mouse/keyboard state to Qt mouse/keyboard state. svn path=/branches/work/kwin_composite/; revision=620299 --- events.cpp | 31 --------------- utils.cpp | 72 +++++++++++++++++++++++++++++++++++ utils.h | 108 +++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 160 insertions(+), 51 deletions(-) diff --git a/events.cpp b/events.cpp index a6cf6abefa..f4c58fa5cf 100644 --- a/events.cpp +++ b/events.cpp @@ -1093,37 +1093,6 @@ void Client::updateMouseGrab() } } -int qtToX11Button( Qt::ButtonState button ) - { - if( button == Qt::LeftButton ) - return Button1; - else if( button == Qt::MidButton ) - return Button2; - else if( button == Qt::RightButton ) - return Button3; - return AnyButton; - } - -int qtToX11State( Qt::ButtonState buttons, Qt::KeyboardModifiers modifiers ) - { - int ret = 0; - if( buttons & Qt::LeftButton ) - ret |= Button1Mask; - if( buttons & Qt::MidButton ) - ret |= Button2Mask; - if( buttons & Qt::RightButton ) - ret |= Button3Mask; - if( modifiers & Qt::ShiftModifier ) - ret |= ShiftMask; - if( modifiers & Qt::ControlModifier ) - ret |= ControlMask; - if( modifiers & Qt::AltModifier ) - ret |= KKeyServer::modXAlt(); - if( modifiers & Qt::MetaModifier ) - ret |= KKeyServer::modXMeta(); - return ret; - } - // Qt propagates mouse events up the widget hierachy, which means events // for the decoration window cannot be (easily) intercepted as X11 events bool Client::eventFilter( QObject* o, QEvent* e ) diff --git a/utils.cpp b/utils.cpp index ef7b939b88..336aafdea7 100644 --- a/utils.cpp +++ b/utils.cpp @@ -25,6 +25,7 @@ License. See the file "COPYING" for the exact licensing terms. #include #include #include +#include #include #include @@ -351,6 +352,77 @@ bool grabbedXServer() { return server_grab_count > 0; } + +// converting between X11 mouse/keyboard state mask and Qt button/keyboard states + +int qtToX11Button( Qt::MouseButton button ) + { + if( button == Qt::LeftButton ) + return Button1; + else if( button == Qt::MidButton ) + return Button2; + else if( button == Qt::RightButton ) + return Button3; + return AnyButton; // 0 + } + +Qt::MouseButton x11ToQtMouseButton( int button ) + { + if( button == Button1 ) + return Qt::LeftButton; + if( button == Button2 ) + return Qt::MidButton; + if( button == Button3 ) + return Qt::RightButton; + return Qt::NoButton; + } + +int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers ) + { + int ret = 0; + if( buttons & Qt::LeftButton ) + ret |= Button1Mask; + if( buttons & Qt::MidButton ) + ret |= Button2Mask; + if( buttons & Qt::RightButton ) + ret |= Button3Mask; + if( modifiers & Qt::ShiftModifier ) + ret |= ShiftMask; + if( modifiers & Qt::ControlModifier ) + ret |= ControlMask; + if( modifiers & Qt::AltModifier ) + ret |= KKeyServer::modXAlt(); + if( modifiers & Qt::MetaModifier ) + ret |= KKeyServer::modXMeta(); + return ret; + } + +Qt::MouseButtons x11ToQtMouseButtons( int state ) + { + Qt::MouseButtons ret = 0; + if( state & Button1Mask ) + ret |= Qt::LeftButton; + if( state & Button2Mask ) + ret |= Qt::MidButton; + if( state & Button3Mask ) + ret |= Qt::RightButton; + return ret; + } + +Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state ) + { + Qt::KeyboardModifiers ret = 0; + if( state & ShiftMask ) + ret |= Qt::ShiftModifier; + if( state & ControlMask ) + ret |= Qt::ControlModifier; + if( state & KKeyServer::modXAlt()) + ret |= Qt::AltModifier; + if( state & KKeyServer::modXMeta()) + ret |= Qt::MetaModifier; + return ret; + } + #endif bool isLocalMachine( const QByteArray& host ) diff --git a/utils.h b/utils.h index 3902e7629e..20ed1a6909 100644 --- a/utils.h +++ b/utils.h @@ -12,6 +12,32 @@ License. See the file "COPYING" for the exact licensing terms. #ifndef KWIN_UTILS_H #define KWIN_UTILS_H +#include +#include + +#include + +#ifdef HAVE_XRANDR +#include +#endif + +#ifdef HAVE_XCOMPOSITE +#include +#if XCOMPOSITE_MAJOR > 0 || XCOMPOSITE_MINOR >= 3 +#define HAVE_XCOMPOSITE_OVERLAY +#endif +#endif + +#ifdef HAVE_XDAMAGE +#include +#endif + +#ifdef HAVE_XFIXES +#include +#endif + +#include + #include #include #include @@ -22,6 +48,13 @@ License. See the file "COPYING" for the exact licensing terms. namespace KWinInternal { +#ifndef HAVE_XDAMAGE +typedef long Damage; +struct XDamageNotifyEvent + { + }; +#endif + const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask; @@ -39,12 +72,18 @@ const long ClientWinMask = KeyPressMask | KeyReleaseMask | const QPoint invalidPoint( INT_MIN, INT_MIN ); +class Toplevel; class Client; +class Unmanaged; class Group; class Options; +typedef QList< Toplevel* > ToplevelList; +typedef QList< const Toplevel* > ConstToplevelList; typedef QList< Client* > ClientList; typedef QList< const Client* > ConstClientList; +typedef QList< Unmanaged* > UnmanagedList; +typedef QList< const Unmanaged* > ConstUnmanagedList; typedef QList< Group* > GroupList; typedef QList< const Group* > ConstGroupList; @@ -87,6 +126,7 @@ enum allowed_t { Allowed }; // some enums to have more readable code, instead of using bools enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet }; + // Areas, mostly related to Xinerama enum clientAreaOption { @@ -109,24 +149,32 @@ enum ShadeMode ShadeActivated // "shaded", but visible due to alt+tab to the window }; -class Shape +class Extensions { public: - static bool available() { return kwin_shape_version > 0; } - static int version() { return kwin_shape_version; } // as 16*major+minor, i.e. two hex digits - static bool hasShape( WId w); - static int shapeEvent(); static void init(); + static bool shapeAvailable() { return has_shape; } + static int shapeNotifyEvent(); + static bool randrAvailable() { return has_randr; } + static int randrNotifyEvent(); + static bool damageAvailable() { return has_damage; } + static int damageNotifyEvent(); + static bool compositeAvailable() { return has_composite; } + static bool compositeOverlayAvailable() { return has_composite && has_composite_overlay; } + static bool fixesAvailable() { return has_fixes; } + static bool hasShape( Window w ); private: - static int kwin_shape_version; - static int kwin_shape_event; + static bool has_shape; + static int shape_event_base; + static bool has_randr; + static int randr_event_base; + static bool has_damage; + static int damage_event_base; + static bool has_composite; + static bool has_composite_overlay; + static bool has_fixes; }; -// compile with XShape older than 1.0 -#ifndef ShapeInput -const int ShapeInput = 2; -#endif - class Motif { public: @@ -226,34 +274,38 @@ int displayHeight() return XDisplayHeight( display(), DefaultScreen( display())); } +class Scene; +extern Scene* scene; +inline bool compositing() { return scene != NULL; } + // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint #ifndef UrgencyHint #define UrgencyHint XUrgencyHint #endif // for STL-like algo's -#define KWIN_CHECK_PREDICATE( name, check ) \ +#define KWIN_CHECK_PREDICATE( name, cls, check ) \ struct name \ { \ - inline bool operator()( const Client* cl ) { return check; }; \ + inline bool operator()( const cls* cl ) { return check; }; \ } -#define KWIN_COMPARE_PREDICATE( name, type, check ) \ +#define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \ struct name \ { \ typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \ inline name( const type_helper& compare_value ) : value( compare_value ) {}; \ - inline bool operator()( const Client* cl ) { return check; }; \ + inline bool operator()( const cls* cl ) { return check; }; \ const type_helper& value; \ } -#define KWIN_PROCEDURE( name, action ) \ +#define KWIN_PROCEDURE( name, cls, action ) \ struct name \ { \ - inline void operator()( Client* cl ) { action; }; \ + inline void operator()( cls* cl ) { action; }; \ } -KWIN_CHECK_PREDICATE( TruePredicate, cl == cl /*true, avoid warning about 'cl' */ ); +KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */ ); template< typename T > Client* findClientInList( const ClientList& list, T predicate ) @@ -266,6 +318,17 @@ Client* findClientInList( const ClientList& list, T predicate ) return NULL; } +template< typename T > +Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate ) + { + for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it) + { + if ( predicate( const_cast< const Unmanaged* >( *it))) + return *it; + } + return NULL; + } + inline int timestampCompare( Time time1, Time time2 ) // like strcmp() { @@ -280,7 +343,12 @@ Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1 bool isLocalMachine( const QByteArray& host ); -void checkNonExistentClients(); +// converting between X11 mouse/keyboard state mask and Qt button/keyboard states +int qtToX11Button( Qt::MouseButton button ); +Qt::MouseButton x11ToQtMouseButton( int button ); +int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers ); +Qt::MouseButtons x11ToQtMouseButtons( int state ); +Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state ); #ifndef KCMRULES // Qt dialogs emit no signal when closed :(