Add support for xlib backend X Event filters

Change-Id: Id1e7995f98395de748ce47a27365e4bdd564ea49
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
This commit is contained in:
John Stanley 2012-02-07 03:59:40 -05:00 committed by Qt by Nokia
parent 6e3c4de94f
commit 7038151326
6 changed files with 29 additions and 5 deletions

View File

@ -68,7 +68,7 @@ QXlibIntegration::QXlibIntegration()
XInitThreads(); XInitThreads();
mPrimaryScreen = new QXlibScreen(); mPrimaryScreen = new QXlibScreen(mNativeInterface);
mScreens.append(mPrimaryScreen); mScreens.append(mPrimaryScreen);
screenAdded(mPrimaryScreen); screenAdded(mPrimaryScreen);
} }

View File

@ -54,6 +54,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QXlibScreen; class QXlibScreen;
class QXlibNativeInterface;
class QXlibIntegration : public QPlatformIntegration class QXlibIntegration : public QPlatformIntegration
{ {
@ -82,7 +83,7 @@ private:
QList<QPlatformScreen *> mScreens; QList<QPlatformScreen *> mScreens;
QPlatformFontDatabase *mFontDb; QPlatformFontDatabase *mFontDb;
QPlatformClipboard *mClipboard; QPlatformClipboard *mClipboard;
QPlatformNativeInterface *mNativeInterface; QXlibNativeInterface *mNativeInterface;
QAbstractEventDispatcher *mEventDispatcher; QAbstractEventDispatcher *mEventDispatcher;
}; };

View File

@ -92,6 +92,17 @@ void * QXlibNativeInterface::nativeResourceForWindow(const QByteArray &resourceS
} }
return result; return result;
} }
QPlatformNativeInterface::EventFilter QXlibNativeInterface::setEventFilter(const QByteArray &eventType, QPlatformNativeInterface::EventFilter filter)
{
EventFilter oldFilter = m_eventFilters.value(eventType);
m_eventFilters.insert(eventType, filter);
return oldFilter;
}
QPlatformNativeInterface::EventFilter QXlibNativeInterface::eventFilterForEventType(const QByteArray& eventType) const
{
return m_eventFilters.value(eventType);
}
void * QXlibNativeInterface::displayForWindow(QWindow *window) void * QXlibNativeInterface::displayForWindow(QWindow *window)
{ {

View File

@ -60,6 +60,9 @@ public:
void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window); void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window);
EventFilter setEventFilter(const QByteArray &eventType, EventFilter filter);
EventFilter eventFilterForEventType(const QByteArray& eventType) const;
void *displayForWindow(QWindow *window); void *displayForWindow(QWindow *window);
void *eglDisplayForWindow(QWindow *window); void *eglDisplayForWindow(QWindow *window);
void *connectionForWindow(QWindow *window); void *connectionForWindow(QWindow *window);
@ -68,6 +71,7 @@ public:
void *eglContextForWindow(QWindow *window); void *eglContextForWindow(QWindow *window);
private: private:
QHash<QByteArray, EventFilter> m_eventFilters;
static QXlibScreen *qPlatformScreenForWindow(QWindow *window); static QXlibScreen *qPlatformScreenForWindow(QWindow *window);
}; };

View File

@ -50,6 +50,7 @@
#include "qxlibstatic.h" #include "qxlibstatic.h"
#include "qxlibclipboard.h" #include "qxlibclipboard.h"
#include "qxlibdisplay.h" #include "qxlibdisplay.h"
#include "qxlibnativeinterface.h"
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QSocketNotifier> #include <QtCore/QSocketNotifier>
@ -190,8 +191,9 @@ qDebug() << "qt_x_errhandler" << err->error_code;
return 0; return 0;
} }
QXlibScreen::QXlibScreen() QXlibScreen::QXlibScreen(QXlibNativeInterface *nativeInterface)
: mFormat(QImage::Format_RGB32) : mNativeInterface(nativeInterface)
, mFormat(QImage::Format_RGB32)
#if !defined(QT_NO_OPENGL) && defined(QT_OPENGL_ES_2) #if !defined(QT_NO_OPENGL) && defined(QT_OPENGL_ES_2)
, mEGLDisplay(0) , mEGLDisplay(0)
#endif #endif
@ -263,6 +265,11 @@ unsigned long QXlibScreen::whitePixel()
bool QXlibScreen::handleEvent(XEvent *xe) bool QXlibScreen::handleEvent(XEvent *xe)
{ {
if (QPlatformNativeInterface::EventFilter filter = mNativeInterface->eventFilterForEventType(QByteArrayLiteral("XEvent"))) {
if (filter(xe, 0))
return true;
}
int quit = false; int quit = false;
QXlibWindow *platformWindow = QXlibWindow::platformWindowForXWindow(xe->xany.window); QXlibWindow *platformWindow = QXlibWindow::platformWindowForXWindow(xe->xany.window);
if (!platformWindow) if (!platformWindow)

View File

@ -55,7 +55,7 @@ class QXlibScreen : public QObject, public QPlatformScreen
{ {
Q_OBJECT Q_OBJECT
public: public:
QXlibScreen(); QXlibScreen(QXlibNativeInterface *nativeInterface);
~QXlibScreen(); ~QXlibScreen();
@ -93,6 +93,7 @@ public slots:
private: private:
void handleSelectionRequest(XEvent *event); void handleSelectionRequest(XEvent *event);
QXlibNativeInterface *mNativeInterface;
QRect mGeometry; QRect mGeometry;
QSizeF mPhysicalSize; QSizeF mPhysicalSize;
int mDepth; int mDepth;