feat(detect): filter out espanso-generated events on macOS

This commit is contained in:
Federico Terzi 2021-08-14 16:07:14 +02:00
parent 0a38fafae9
commit 97130e972c

View File

@ -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;