Skip to content

Commit 2ab40c1

Browse files
8231513: JavaFX cause Keystroke Receiving prompt on MacOS 10.15 (Catalina)
Reviewed-by: prr, jvos
1 parent 1823f6e commit 2ab40c1

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

modules/javafx.graphics/src/main/native-glass/mac/GlassTouches.m

+56-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,6 +42,7 @@
4242

4343

4444
static GlassTouches* glassTouches = nil;
45+
static BOOL useEventTap = NO;
4546

4647

4748
@interface GlassTouches (hidden)
@@ -176,6 +177,11 @@ + (void)terminate
176177

177178
- (id)init
178179
{
180+
useEventTap = YES;
181+
if (@available(macOS 10.15, *)) {
182+
useEventTap = NO;
183+
}
184+
179185
self = [super init];
180186
if (self != nil)
181187
{
@@ -185,35 +191,37 @@ - (id)init
185191
self->touches = nil;
186192
self->lastTouchId = 0;
187193

188-
//
189-
// Notes after fixing RT-23199:
190-
//
191-
// Don't use NSMachPort and NSRunLoop to integrate CFMachPortRef
192-
// instance into run loop.
193-
//
194-
// Ignoring the above "don't"s results into performance degradation
195-
// referenced in the bug.
196-
//
197-
198-
self->eventTap = CGEventTapCreate(kCGHIDEventTap,
199-
kCGHeadInsertEventTap,
200-
kCGEventTapOptionListenOnly,
201-
CGEventMaskBit(NSEventTypeGesture),
202-
listenTouchEvents, nil);
203-
204-
LOG("TOUCHES: eventTap=%p\n", self->eventTap);
205-
206-
if (self->eventTap)
207-
{ // Create a run loop source.
208-
self->runLoopSource = CFMachPortCreateRunLoopSource(
209-
kCFAllocatorDefault,
210-
self->eventTap, 0);
211-
212-
LOG("TOUCHES: runLoopSource=%p\n", self->runLoopSource);
213-
214-
// Add to the current run loop.
215-
CFRunLoopAddSource(CFRunLoopGetCurrent(), self->runLoopSource,
216-
kCFRunLoopCommonModes);
194+
if (useEventTap) {
195+
//
196+
// Notes after fixing RT-23199:
197+
//
198+
// Don't use NSMachPort and NSRunLoop to integrate CFMachPortRef
199+
// instance into run loop.
200+
//
201+
// Ignoring the above "don't"s results into performance degradation
202+
// referenced in the bug.
203+
//
204+
205+
self->eventTap = CGEventTapCreate(kCGHIDEventTap,
206+
kCGHeadInsertEventTap,
207+
kCGEventTapOptionListenOnly,
208+
CGEventMaskBit(NSEventTypeGesture),
209+
listenTouchEvents, nil);
210+
211+
LOG("TOUCHES: eventTap=%p\n", self->eventTap);
212+
213+
if (self->eventTap)
214+
{ // Create a run loop source.
215+
self->runLoopSource = CFMachPortCreateRunLoopSource(
216+
kCFAllocatorDefault,
217+
self->eventTap, 0);
218+
219+
LOG("TOUCHES: runLoopSource=%p\n", self->runLoopSource);
220+
221+
// Add to the current run loop.
222+
CFRunLoopAddSource(CFRunLoopGetCurrent(), self->runLoopSource,
223+
kCFRunLoopCommonModes);
224+
}
217225
}
218226
}
219227
return self;
@@ -225,29 +233,32 @@ - (id)init
225233
@implementation GlassTouches (hidden)
226234
- (void)terminateImpl
227235
{
228-
LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
229-
self->runLoopSource);
236+
if (useEventTap) {
237+
LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
238+
self->runLoopSource);
230239

231-
if (self->runLoopSource)
232-
{
233-
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
234-
kCFRunLoopCommonModes);
235-
CFRelease(self->runLoopSource);
236-
self->runLoopSource = nil;
237-
}
240+
if (self->runLoopSource)
241+
{
242+
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
243+
kCFRunLoopCommonModes);
244+
CFRelease(self->runLoopSource);
245+
self->runLoopSource = nil;
246+
}
238247

239-
if (self->eventTap)
240-
{
241-
CFRelease(self->eventTap);
242-
self->eventTap = nil;
248+
if (self->eventTap)
249+
{
250+
CFRelease(self->eventTap);
251+
self->eventTap = nil;
252+
}
243253
}
244-
245254
[self releaseTouches];
246255
}
247256

248257
- (void)enableTouchInputEventTap
249258
{
250-
CGEventTapEnable(self->eventTap, true);
259+
if (useEventTap) {
260+
CGEventTapEnable(self->eventTap, true);
261+
}
251262
}
252263

253264
- (void)sendJavaTouchEvent:(NSEvent *)theEvent

0 commit comments

Comments
 (0)