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();
mPrimaryScreen = new QXlibScreen();
mPrimaryScreen = new QXlibScreen(mNativeInterface);
mScreens.append(mPrimaryScreen);
screenAdded(mPrimaryScreen);
}

View File

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

View File

@ -92,6 +92,17 @@ void * QXlibNativeInterface::nativeResourceForWindow(const QByteArray &resourceS
}
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)
{

View File

@ -60,6 +60,9 @@ public:
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 *eglDisplayForWindow(QWindow *window);
void *connectionForWindow(QWindow *window);
@ -68,6 +71,7 @@ public:
void *eglContextForWindow(QWindow *window);
private:
QHash<QByteArray, EventFilter> m_eventFilters;
static QXlibScreen *qPlatformScreenForWindow(QWindow *window);
};

View File

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

View File

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