qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 1/2] ui/cocoa: capture all keys and combos when mouse is g


From: Akihiko Odaki
Subject: Re: [PATCH v3 1/2] ui/cocoa: capture all keys and combos when mouse is grabbed
Date: Tue, 11 May 2021 12:08:46 +0900
User-agent: Mozilla/5.0 (X11; Linux aarch64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 2021/05/05 8:32, gustavo@noronha.eti.br wrote:> @@ -344,6 +361,32 @@ - (id)initWithFrame:(NSRect)frameRect
          kbd = qkbd_state_init(dcl.con);
}
+
+    CGEventMask mask = CGEventMaskBit(kCGEventKeyDown) | 
CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged);
+    eventsTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 
kCGEventTapOptionDefault,
+                                 mask, handleTapEvent, self);
+    if (!eventsTap) {
+        warn_report("Could not create event tap, system key combos will not be 
captured.\n");
+        return self;
+    } else {
+        COCOA_DEBUG("Global events tap created! Will capture system key 
combos.\n");
+    }
+
+    CFRunLoopRef runLoop = CFRunLoopGetCurrent();
+    if (!runLoop) {
+        warn_report("Could not obtain current CF RunLoop, system key combos will 
not be captured.\n");
+        return self;
+    }
+
+    CFRunLoopSourceRef tapEventsSrc = 
CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventsTap, 0);
+    if (!tapEventsSrc ) {
+        warn_report("Could not obtain current CF RunLoop, system key combos will 
not be captured.\n");
+        return self;
+    }
+
+    CFRunLoopAddSource(runLoop, tapEventsSrc, kCFRunLoopDefaultMode);
+    CFRelease(tapEventsSrc);
+
      return self;
  }

These statements should be in "if (self)" block which they follow, or it may rely on "self" even if it failed to allocate and initialize "self".

Regards,
Akihiko Odaki



reply via email to

[Prev in Thread] Current Thread [Next in Thread]