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>
|
#include <string.h>
|
||||||
|
|
||||||
|
const float ESPANSO_EVENT_MARKER = -27469;
|
||||||
|
|
||||||
const unsigned long long FLAGS = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown |
|
const unsigned long long FLAGS = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown |
|
||||||
NSEventMaskLeftMouseUp | NSEventMaskRightMouseDown | NSEventMaskRightMouseUp |
|
NSEventMaskLeftMouseUp | NSEventMaskRightMouseDown | NSEventMaskRightMouseUp |
|
||||||
NSEventMaskOtherMouseDown | NSEventMaskOtherMouseUp;
|
NSEventMaskOtherMouseDown | NSEventMaskOtherMouseUp;
|
||||||
|
@ -58,6 +60,12 @@ void * detect_initialize(EventCallback callback, InitializeOptions options) {
|
||||||
// Setup key detection
|
// Setup key detection
|
||||||
|
|
||||||
[NSEvent addGlobalMonitorForEventsMatchingMask:FLAGS handler:^(NSEvent *event){
|
[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 = {};
|
InputEvent inputEvent = {};
|
||||||
if (event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp ) {
|
if (event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp ) {
|
||||||
inputEvent.event_type = INPUT_EVENT_TYPE_KEYBOARD;
|
inputEvent.event_type = INPUT_EVENT_TYPE_KEYBOARD;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user