Extract the OS event filter implementation (#2422)

This commit is contained in:
Gianluca Recchia 2018-10-30 13:46:12 +01:00 committed by Jonathan White
parent fa687f246e
commit 4e1d3bfd73
6 changed files with 68 additions and 47 deletions

View file

@ -21,7 +21,6 @@
#include "MainWindow.h"
#include "core/Config.h"
#include <QAbstractNativeEventFilter>
#include <QFileInfo>
#include <QFileOpenEvent>
#include <QLockFile>
@ -32,6 +31,10 @@
#include "autotype/AutoType.h"
#include "core/Global.h"
#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
#include "core/OSEventFilter.h"
#endif
#if defined(Q_OS_UNIX)
#include <signal.h>
#include <sys/socket.h>
@ -42,46 +45,7 @@ namespace
{
constexpr int WaitTimeoutMSec = 150;
const char BlockSizeProperty[] = "blockSize";
}
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
class XcbEventFilter : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override
{
Q_UNUSED(result)
if (eventType == QByteArrayLiteral("xcb_generic_event_t")) {
int retCode = autoType()->callEventFilter(message);
if (retCode == 1) {
return true;
}
}
return false;
}
};
#elif defined(Q_OS_WIN)
class WinEventFilter : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override
{
Q_UNUSED(result);
if (eventType == QByteArrayLiteral("windows_generic_MSG")
|| eventType == QByteArrayLiteral("windows_dispatcher_MSG")) {
int retCode = autoType()->callEventFilter(message);
if (retCode == 1) {
return true;
}
}
return false;
}
};
#endif
} // namespace
Application::Application(int& argc, char** argv)
: QApplication(argc, argv)
@ -91,11 +55,12 @@ Application::Application(int& argc, char** argv)
#endif
, m_alreadyRunning(false)
, m_lockFile(nullptr)
#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
, m_osEventFilter(new OSEventFilter())
{
installNativeEventFilter(m_osEventFilter.data());
#else
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
installNativeEventFilter(new XcbEventFilter());
#elif defined(Q_OS_WIN)
installNativeEventFilter(new WinEventFilter());
#endif
#if defined(Q_OS_UNIX)
registerUnixSignals();