feat(detect): filter out espanso-generated events on macOS
This commit is contained in:
parent
0a38fafae9
commit
97130e972c
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
const float ESPANSO_EVENT_MARKER = -27469;
|
||||
|
||||
const unsigned long long FLAGS = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown |
|
||||
NSEventMaskLeftMouseUp | NSEventMaskRightMouseDown | NSEventMaskRightMouseUp |
|
||||
NSEventMaskOtherMouseDown | NSEventMaskOtherMouseUp;
|
||||
|
@ -58,6 +60,12 @@ void * detect_initialize(EventCallback callback, InitializeOptions options) {
|
|||
// Setup key detection
|
||||
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:FLAGS handler:^(NSEvent *event){
|
||||
// Workaround used to determine if the event was generated by espanso itself
|
||||
float eventLocation = event.locationInWindow.x;
|
||||
if (fabs(eventLocation - ESPANSO_EVENT_MARKER) < 0.001) {
|
||||
return;
|
||||
}
|
||||
|
||||
InputEvent inputEvent = {};
|
||||
if (event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp ) {
|
||||
inputEvent.event_type = INPUT_EVENT_TYPE_KEYBOARD;
|
||||
|
|
Loading…
Reference in New Issue
Block a user