Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
HookUnix.cpp
1#include "HookUnix.h"
2
3#include <QDebug>
4#include <QApplication>
5#include <QWidget>
6#include <QAbstractEventDispatcher>
7#include <QLoggingCategory>
8
9CHook* CHook::GetHook(QObject *parent)
10{
11 CHookUnix* p = nullptr;
12 if(!p)
13 p = new CHookUnix(parent);
14 return p;
15}
16
17CHookUnix::CHookUnix(QObject *parent)
18 : CHook(parent),
19 m_pNativeEventFilter(new CHookUnixNativeEventFilter())
20{
21 //TODO:
22 //RegisterKeyboard();
23}
24
25CHookUnix::~CHookUnix()
26{
27 UnRegisterKeyboard();
28}
29
30int CHookUnix::RegisterKeyboard()
31{
32 if(!m_pNativeEventFilter)
33 {
34 Q_ASSERT(false);
35 return -1;
36 }
37#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
38 qApp->installNativeEventFilter(m_pNativeEventFilter);
39#else
40 if(QCoreApplication::eventDispatcher())
41 QCoreApplication::eventDispatcher()->installNativeEventFilter(m_pNativeEventFilter);
42#endif
43 return 0;
44}
45
46int CHookUnix::UnRegisterKeyboard()
47{
48 if(!m_pNativeEventFilter) return -1;
49
50#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
51 qApp->removeNativeEventFilter(m_pNativeEventFilter);
52#else
53 if(QCoreApplication::eventDispatcher())
54 QCoreApplication::eventDispatcher()->removeNativeEventFilter(m_pNativeEventFilter);
55#endif
56 return 0;
57}
The class is the HOOK abstract class.
Definition Hook.h:14