mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-27 08:45:18 -04:00
Extract the OS event filter implementation (#2422)
This commit is contained in:
parent
fa687f246e
commit
4e1d3bfd73
6 changed files with 68 additions and 47 deletions
|
@ -204,6 +204,11 @@ if(MINGW)
|
||||||
core/ScreenLockListenerWin.h
|
core/ScreenLockListenerWin.h
|
||||||
core/ScreenLockListenerWin.cpp)
|
core/ScreenLockListenerWin.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
if(MINGW OR (UNIX AND NOT APPLE))
|
||||||
|
set(keepassx_SOURCES
|
||||||
|
${keepassx_SOURCES}
|
||||||
|
core/OSEventFilter.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(keepassx_SOURCES_MAINEXE main.cpp)
|
set(keepassx_SOURCES_MAINEXE main.cpp)
|
||||||
|
|
||||||
|
|
27
src/core/OSEventFilter.cpp
Normal file
27
src/core/OSEventFilter.cpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#include "OSEventFilter.h"
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
|
#include "autotype/AutoType.h"
|
||||||
|
|
||||||
|
OSEventFilter::OSEventFilter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OSEventFilter::nativeEventFilter(const QByteArray& eventType, void* message, long* result)
|
||||||
|
{
|
||||||
|
Q_UNUSED(result)
|
||||||
|
|
||||||
|
#if defined(Q_OS_UNIX)
|
||||||
|
if (eventType == QByteArrayLiteral("xcb_generic_event_t")) {
|
||||||
|
#elif defined(Q_OS_WIN)
|
||||||
|
if (eventType == QByteArrayLiteral("windows_generic_MSG")
|
||||||
|
|| eventType == QByteArrayLiteral("windows_dispatcher_MSG")) {
|
||||||
|
#endif
|
||||||
|
int retCode = autoType()->callEventFilter(message);
|
||||||
|
|
||||||
|
return retCode == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
16
src/core/OSEventFilter.h
Normal file
16
src/core/OSEventFilter.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef OSEVENTFILTER_H
|
||||||
|
#define OSEVENTFILTER_H
|
||||||
|
#include <QAbstractNativeEventFilter>
|
||||||
|
|
||||||
|
class QByteArray;
|
||||||
|
|
||||||
|
class OSEventFilter : public QAbstractNativeEventFilter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OSEventFilter();
|
||||||
|
bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override;
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(OSEventFilter)
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OSEVENTFILTER_H
|
|
@ -25,7 +25,7 @@ class ScreenLockListenerDBus : public ScreenLockListenerPrivate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ScreenLockListenerDBus(QWidget* parent = 0);
|
explicit ScreenLockListenerDBus(QWidget* parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void gnomeSessionStatusChanged(uint status);
|
void gnomeSessionStatusChanged(uint status);
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
|
|
||||||
#include <QAbstractNativeEventFilter>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
#include <QLockFile>
|
#include <QLockFile>
|
||||||
|
@ -32,6 +31,10 @@
|
||||||
#include "autotype/AutoType.h"
|
#include "autotype/AutoType.h"
|
||||||
#include "core/Global.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)
|
#if defined(Q_OS_UNIX)
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -42,46 +45,7 @@ namespace
|
||||||
{
|
{
|
||||||
constexpr int WaitTimeoutMSec = 150;
|
constexpr int WaitTimeoutMSec = 150;
|
||||||
const char BlockSizeProperty[] = "blockSize";
|
const char BlockSizeProperty[] = "blockSize";
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
Application::Application(int& argc, char** argv)
|
Application::Application(int& argc, char** argv)
|
||||||
: QApplication(argc, argv)
|
: QApplication(argc, argv)
|
||||||
|
@ -91,11 +55,12 @@ Application::Application(int& argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
, m_alreadyRunning(false)
|
, m_alreadyRunning(false)
|
||||||
, m_lockFile(nullptr)
|
, 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
|
#endif
|
||||||
#if defined(Q_OS_UNIX)
|
#if defined(Q_OS_UNIX)
|
||||||
registerUnixSignals();
|
registerUnixSignals();
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QtNetwork/QLocalServer>
|
#include <QtNetwork/QLocalServer>
|
||||||
|
|
||||||
|
#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||||
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
class OSEventFilter;
|
||||||
|
#endif
|
||||||
class QLockFile;
|
class QLockFile;
|
||||||
class QSocketNotifier;
|
class QSocketNotifier;
|
||||||
|
|
||||||
|
@ -33,7 +38,7 @@ class Application : public QApplication
|
||||||
public:
|
public:
|
||||||
Application(int& argc, char** argv);
|
Application(int& argc, char** argv);
|
||||||
QWidget* mainWindow() const;
|
QWidget* mainWindow() const;
|
||||||
~Application();
|
~Application() override;
|
||||||
void setMainWindow(QWidget* mainWindow);
|
void setMainWindow(QWidget* mainWindow);
|
||||||
|
|
||||||
bool event(QEvent* event) override;
|
bool event(QEvent* event) override;
|
||||||
|
@ -70,6 +75,9 @@ private:
|
||||||
QLockFile* m_lockFile;
|
QLockFile* m_lockFile;
|
||||||
QLocalServer m_lockServer;
|
QLocalServer m_lockServer;
|
||||||
QString m_socketName;
|
QString m_socketName;
|
||||||
|
#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||||
|
QScopedPointer<OSEventFilter> m_osEventFilter;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_APPLICATION_H
|
#endif // KEEPASSX_APPLICATION_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue