< prev index next >

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

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -40,10 +40,11 @@
      #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
  #endif
  
  
  static GlassTouches* glassTouches = nil;
+ static BOOL useEventTap = NO;
  
  
  @interface GlassTouches (hidden)
  
  - (void)releaseTouches;

@@ -174,48 +175,55 @@
      glassTouches = nil;
  }
  
  - (id)init
  {
+     useEventTap = YES;
+     if (@available(macOS 10.15, *)) {
+         useEventTap = NO;
+     }
+ 
      self = [super init];
      if (self != nil)
      {
          self->curConsumer   = nil;
          self->eventTap      = nil;
          self->runLoopSource = nil;
          self->touches       = nil;
          self->lastTouchId   = 0;
  
-         //
-         // Notes after fixing RT-23199:
-         //
-         //  Don't use NSMachPort and NSRunLoop to integrate CFMachPortRef
-         //  instance into run loop.
-         //
-         // Ignoring the above "don't"s results into performance degradation
-         // referenced in the bug.
-         //
- 
-         self->eventTap = CGEventTapCreate(kCGHIDEventTap,
-                                           kCGHeadInsertEventTap,
-                                           kCGEventTapOptionListenOnly,
-                                           CGEventMaskBit(NSEventTypeGesture),
-                                           listenTouchEvents, nil);
- 
-         LOG("TOUCHES: eventTap=%p\n", self->eventTap);
- 
-         if (self->eventTap)
-         {   // Create a run loop source.
-             self->runLoopSource = CFMachPortCreateRunLoopSource(
-                                                         kCFAllocatorDefault,
-                                                         self->eventTap, 0);
- 
-             LOG("TOUCHES: runLoopSource=%p\n", self->runLoopSource);
- 
-             // Add to the current run loop.
-             CFRunLoopAddSource(CFRunLoopGetCurrent(), self->runLoopSource,
-                                kCFRunLoopCommonModes);
+         if (useEventTap) {
+             //
+             // Notes after fixing RT-23199:
+             //
+             //  Don't use NSMachPort and NSRunLoop to integrate CFMachPortRef
+             //  instance into run loop.
+             //
+             // Ignoring the above "don't"s results into performance degradation
+             // referenced in the bug.
+             //
+ 
+             self->eventTap = CGEventTapCreate(kCGHIDEventTap,
+                                               kCGHeadInsertEventTap,
+                                               kCGEventTapOptionListenOnly,
+                                               CGEventMaskBit(NSEventTypeGesture),
+                                               listenTouchEvents, nil);
+ 
+             LOG("TOUCHES: eventTap=%p\n", self->eventTap);
+ 
+             if (self->eventTap)
+             {   // Create a run loop source.
+                 self->runLoopSource = CFMachPortCreateRunLoopSource(
+                                                             kCFAllocatorDefault,
+                                                             self->eventTap, 0);
+ 
+                 LOG("TOUCHES: runLoopSource=%p\n", self->runLoopSource);
+ 
+                 // Add to the current run loop.
+                 CFRunLoopAddSource(CFRunLoopGetCurrent(), self->runLoopSource,
+                                    kCFRunLoopCommonModes);
+             }
          }
      }
      return self;
  }
  

@@ -223,33 +231,36 @@
  
  
  @implementation GlassTouches (hidden)
  - (void)terminateImpl
  {
-     LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
-         self->runLoopSource);
+     if (useEventTap) {
+         LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
+             self->runLoopSource);
  
-     if (self->runLoopSource)
-     {
-         CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
-                               kCFRunLoopCommonModes);
-         CFRelease(self->runLoopSource);
-         self->runLoopSource = nil;
-     }
+         if (self->runLoopSource)
+         {
+             CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
+                                   kCFRunLoopCommonModes);
+             CFRelease(self->runLoopSource);
+             self->runLoopSource = nil;
+         }
  
-     if (self->eventTap)
-     {
-         CFRelease(self->eventTap);
-         self->eventTap = nil;
+         if (self->eventTap)
+         {
+             CFRelease(self->eventTap);
+             self->eventTap = nil;
+         }
      }
- 
      [self releaseTouches];
  }
  
  - (void)enableTouchInputEventTap
  {
-     CGEventTapEnable(self->eventTap, true);
+     if (useEventTap) {
+         CGEventTapEnable(self->eventTap, true);
+     }
  }
  
  - (void)sendJavaTouchEvent:(NSEvent *)theEvent
  {
      jint modifiers = GetJavaModifiers(theEvent);
< prev index next >