3#include <QDesktopServices>
4#include <QLoggingCategory>
9 #include "Windows/HookWindows.h"
10#elif defined(Q_OS_ANDROID)
11#elif defined(Q_OS_MACOS)
12#elif defined(Q_OS_LINUX)
13 #include "Unix/NativeEventFilterUnix.h"
15#include "RabbitCommonTools.h"
17QAbstractNativeEventFilter* g_pNativeEventFilter =
nullptr;
18static Q_LOGGING_CATEGORY(log,
"Plugin.Hook")
22 , m_pParameterPlugin(pPara)
25 qDebug(log) <<
"CHook::~CHook()";
30 qDebug(log) <<
"CHook::~CHook()";
37 p =
new CHookWindows(pPara, parent);
38#elif defined(Q_OS_LINUX)
39 p =
new CHook(pPara, parent);
44int CHook::RegisterKeyboard()
48 if(m_pParameterPlugin->GetDesktopShortcutsScript()
49 && !m_pParameterPlugin->GetRestoreDesktopShortcutsScript().isEmpty()
50 && !m_pParameterPlugin->GetDisableDesktopShortcutsScript().isEmpty()) {
51#if defined(Q_OS_WIN32)
52 QDesktopServices::openUrl(m_pParameterPlugin->GetDisableDesktopShortcutsScript());
54 RunCommand(m_pParameterPlugin->GetDisableDesktopShortcutsScript());
58 OnDisableDesktopShortcuts();
64int CHook::UnRegisterKeyboard()
67#if defined(Q_OS_WIN32)
68 QDesktopServices::openUrl(m_pParameterPlugin->GetRestoreDesktopShortcutsScript());
70 RunCommand(m_pParameterPlugin->GetRestoreDesktopShortcutsScript());
73 OnRestoreDesktopShortcuts();
76 OnUnRegisterKeyboard();
80int CHook::OnRegisterKeyboard()
82#if defined(Q_OS_LINUX) && !defined(Q_OS_MACOS) && !defined(Q_OS_ANDROID)
83 if(-1 == QGuiApplication::platformName().indexOf(QRegularExpression(
"wayland.*"))) {
84 if(!g_pNativeEventFilter)
85 g_pNativeEventFilter =
new CNativeEventFilterUnix(m_pParameterPlugin);
86 if(g_pNativeEventFilter)
87 qApp->installNativeEventFilter(g_pNativeEventFilter);
89 qApp->installEventFilter(
this);
91 qApp->installEventFilter(
this);
96int CHook::OnUnRegisterKeyboard()
98 if(g_pNativeEventFilter) {
99 qApp->removeNativeEventFilter(g_pNativeEventFilter);
100 delete g_pNativeEventFilter;
101 g_pNativeEventFilter =
nullptr;
104 if(m_pParameterPlugin)
105 qApp->removeEventFilter(
this);
110int CHook::OnDisableDesktopShortcuts()
112#if defined(Q_OS_LINUX) && !defined(Q_OS_MACOS) && !defined(Q_OS_ANDROID)
113 m_DesktopShortcutsManager.disableAllShortcuts();
118int CHook::OnRestoreDesktopShortcuts()
120#if defined(Q_OS_LINUX) && !defined(Q_OS_MACOS) && !defined(Q_OS_ANDROID)
121 m_DesktopShortcutsManager.restoreAllShortcuts();
126bool CHook::eventFilter(QObject *watched, QEvent *event)
129 if(QEvent::KeyPress == event->type() || QEvent::KeyRelease == event->type())
131 if(m_pParameterPlugin && m_pParameterPlugin->GetCaptureAllKeyboard()) {
132 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
134 CFrmViewer* focus = qobject_cast<CFrmViewer*>(QApplication::focusWidget());
135 qDebug(log) <<
"eventFilter:" << keyEvent
138 if(focus == watched) {
148 switch(keyEvent->type())
150 case QKeyEvent::KeyPress:
151 emit focus->sigKeyPressEvent(keyEvent);
154 case QKeyEvent::KeyRelease:
155 emit focus->sigKeyReleaseEvent(keyEvent);
167bool CHook::RunCommand(
const QString &program,
const QStringList &args,
int timeout)
170 process.setProgram(program);
172 process.setArguments(args);
178 if (!process.waitForFinished(timeout)) {
179 qWarning(log) <<
"Command timeout:" << program << args;
183 if (process.exitCode() != 0) {
184 QString errorOutput = process.readAllStandardError();
185 qWarning(log) <<
"Command failed:" << program << args
186 <<
"exit code:" << process.exitCode()
187 <<
"failed:" << errorOutput;
191 QString standardOutput = process.readAllStandardOutput();
192 if (!standardOutput.isEmpty()) {
193 qDebug(log) <<
"Command output:" << standardOutput.trimmed();
The class is the HOOK abstract class.
Global parameters of plugins.