From 0a38fafae9fd324c6dda1e2d4ce36e55d4aa5cb5 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 14 Aug 2021 16:06:54 +0200 Subject: [PATCH] feat(inject): mark espanso-generated event with magic location on macOS --- espanso-inject/src/mac/native.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/espanso-inject/src/mac/native.mm b/espanso-inject/src/mac/native.mm index ea05bcb..7a8e27f 100644 --- a/espanso-inject/src/mac/native.mm +++ b/espanso-inject/src/mac/native.mm @@ -22,6 +22,10 @@ #import #include +// Events dispatched by espanso are "marked" with a custom location +// so that we can later skip them in the detect module. +CGPoint ESPANSO_POINT_MARKER = CGPointMake(-27469, 0); + void inject_string(char *string) { char * stringCopy = strdup(string); @@ -40,6 +44,7 @@ void inject_string(char *string) // To see why: https://github.com/federico-terzi/espanso/issues/279 if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, 0x38)) { CGEventRef e2 = CGEventCreateKeyboardEvent(NULL, 0x38, false); + CGEventSetLocation(e2, ESPANSO_POINT_MARKER); CGEventPost(kCGHIDEventTap, e2); CFRelease(e2); @@ -58,6 +63,7 @@ void inject_string(char *string) UniChar * offset_buffer = buffer.data() + i; CGEventRef e = CGEventCreateKeyboardEvent(NULL, 0x31, true); + CGEventSetLocation(e, ESPANSO_POINT_MARKER); CGEventKeyboardSetUnicodeString(e, chunk_size, offset_buffer); CGEventPost(kCGHIDEventTap, e); CFRelease(e); @@ -67,6 +73,7 @@ void inject_string(char *string) // Some applications require an explicit release of the space key // For more information: https://github.com/federico-terzi/espanso/issues/159 CGEventRef e2 = CGEventCreateKeyboardEvent(NULL, 0x31, false); + CGEventSetLocation(e2, ESPANSO_POINT_MARKER); CGEventPost(kCGHIDEventTap, e2); CFRelease(e2); @@ -89,6 +96,7 @@ void inject_separate_vkeys(int32_t *_vkey_array, int32_t vkey_count, int32_t del for (int i = 0; i