mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 19:25:49 +08:00
[Mac OS/X] Enable event taps in case it got disabled by timeout
This commit is contained in:
committed by
Mathew Sutcliffe
parent
8210423c44
commit
c6bfd3b01d
@@ -56,6 +56,7 @@ namespace BlackInput
|
|||||||
void *refcon);
|
void *refcon);
|
||||||
|
|
||||||
BlackMisc::Input::CHotkeyCombination m_keyCombination; //!< Current status of pressed keys;
|
BlackMisc::Input::CHotkeyCombination m_keyCombination; //!< Current status of pressed keys;
|
||||||
|
CFMachPortRef m_eventTap;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "keyboardmac.h"
|
#include "keyboardmac.h"
|
||||||
|
#include "blackmisc/logmessage.h"
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QtWidgets/QMessageBox>
|
#include <QtWidgets/QMessageBox>
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
@@ -109,14 +111,14 @@ namespace BlackInput
|
|||||||
CGEventMask eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventFlagsChanged));
|
CGEventMask eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventFlagsChanged));
|
||||||
|
|
||||||
// try creating an event tap just for keypresses. if it fails, we need Universal Access.
|
// try creating an event tap just for keypresses. if it fails, we need Universal Access.
|
||||||
CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,
|
m_eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,
|
||||||
eventMask, myCGEventCallback, this);
|
eventMask, myCGEventCallback, this);
|
||||||
|
|
||||||
CFRunLoopSourceRef source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault,
|
CFRunLoopSourceRef source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault,
|
||||||
eventTap, 0);
|
m_eventTap, 0);
|
||||||
|
|
||||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
|
||||||
CGEventTapEnable(eventTap, true);
|
CGEventTapEnable(m_eventTap, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -210,7 +212,15 @@ namespace BlackInput
|
|||||||
{
|
{
|
||||||
|
|
||||||
CKeyboardMac *keyboardMac = static_cast<CKeyboardMac*>(refcon);
|
CKeyboardMac *keyboardMac = static_cast<CKeyboardMac*>(refcon);
|
||||||
keyboardMac->processKeyEvent(type, event);
|
if (type == kCGEventTapDisabledByTimeout)
|
||||||
|
{
|
||||||
|
BlackMisc::CLogMessage(static_cast<CKeyboardMac *>(nullptr)).warning("Event tap got disabled by timeout. Enable it again.");
|
||||||
|
CGEventTapEnable(keyboardMac->m_eventTap, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyboardMac->processKeyEvent(type, event);
|
||||||
|
}
|
||||||
|
|
||||||
// send event to next application
|
// send event to next application
|
||||||
return event;
|
return event;
|
||||||
|
|||||||
Reference in New Issue
Block a user