Port native event filter to Qt 5.

This commit is contained in:
Felix Geyer 2015-07-22 20:30:46 +02:00
parent 03a330a4dd
commit 3b07098731
2 changed files with 24 additions and 19 deletions

View File

@ -18,13 +18,37 @@
#include "Application.h"
#include <QAbstractNativeEventFilter>
#include <QFileOpenEvent>
#include "autotype/AutoType.h"
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX)
class XcbEventFilter : public QAbstractNativeEventFilter
{
public:
virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) Q_DECL_OVERRIDE
{
Q_UNUSED(result)
if (eventType == QByteArrayLiteral("xcb_generic_event_t")) {
int retCode = autoType()->callEventFilter(message);
if (retCode == 1) {
return true;
}
}
return false;
}
};
#endif
Application::Application(int& argc, char** argv)
: QApplication(argc, argv)
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX)
installNativeEventFilter(new XcbEventFilter());
#endif
}
bool Application::event(QEvent* event)
@ -37,19 +61,3 @@ bool Application::event(QEvent* event)
return QApplication::event(event);
}
#ifdef Q_WS_X11
bool Application::x11EventFilter(XEvent* event)
{
int retCode = autoType()->callEventFilter(event);
if (retCode == 0) {
return false;
}
else if (retCode == 1) {
return true;
}
return QApplication::x11EventFilter(event);
}
#endif

View File

@ -31,9 +31,6 @@ public:
Application(int& argc, char** argv);
bool event(QEvent* event) Q_DECL_OVERRIDE;
#ifdef Q_WS_X11
bool x11EventFilter(XEvent* event) Q_DECL_OVERRIDE;
#endif
Q_SIGNALS:
void openFile(const QString& filename);