1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
42
42
43
43
44
44
static GlassTouches* glassTouches = nil ;
45
+ static BOOL useEventTap = NO ;
45
46
46
47
47
48
@interface GlassTouches (hidden)
@@ -176,6 +177,11 @@ + (void)terminate
176
177
177
178
- (id )init
178
179
{
180
+ useEventTap = YES ;
181
+ if (@available (macOS 10.15 , *)) {
182
+ useEventTap = NO ;
183
+ }
184
+
179
185
self = [super init ];
180
186
if (self != nil )
181
187
{
@@ -185,35 +191,37 @@ - (id)init
185
191
self->touches = nil ;
186
192
self->lastTouchId = 0 ;
187
193
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
+ }
217
225
}
218
226
}
219
227
return self;
@@ -225,29 +233,32 @@ - (id)init
225
233
@implementation GlassTouches (hidden)
226
234
- (void )terminateImpl
227
235
{
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 );
230
239
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
+ }
238
247
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
+ }
243
253
}
244
-
245
254
[self releaseTouches ];
246
255
}
247
256
248
257
- (void )enableTouchInputEventTap
249
258
{
250
- CGEventTapEnable (self->eventTap , true );
259
+ if (useEventTap) {
260
+ CGEventTapEnable (self->eventTap , true );
261
+ }
251
262
}
252
263
253
264
- (void )sendJavaTouchEvent : (NSEvent *)theEvent
0 commit comments