< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

159     if (!glassTouches || glassTouches->curConsumer != delegate)
160     {
161         return;
162     }
163 
164     // Keep updating java touch point counter, just have no view to notify.
165     glassTouches->curConsumer = nil;
166 
167     LOG("TOUCHES: stopTracking: delegate=%p\n", glassTouches->curConsumer);
168 }
169 
170 + (void)terminate
171 {
172     // Should be called right after Application's run loop terminate
173     [glassTouches terminateImpl];
174     glassTouches = nil;
175 }
176 
177 - (id)init
178 {





179     self = [super init];
180     if (self != nil)
181     {
182         self->curConsumer   = nil;
183         self->eventTap      = nil;
184         self->runLoopSource = nil;
185         self->touches       = nil;
186         self->lastTouchId   = 0;
187 
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);


217         }
218     }
219     return self;
220 }
221 
222 @end
223 
224 
225 @implementation GlassTouches (hidden)
226 - (void)terminateImpl
227 {
228     LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
229         self->runLoopSource);
230 
231     if (self->runLoopSource)
232     {
233         CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
234                               kCFRunLoopCommonModes);
235         CFRelease(self->runLoopSource);
236         self->runLoopSource = nil;
237     }
238 
239     if (self->eventTap)
240     {
241         CFRelease(self->eventTap);
242         self->eventTap = nil;
243     }






244 






245     [self releaseTouches];
246 }
247 
248 - (void)enableTouchInputEventTap
249 {
250     CGEventTapEnable(self->eventTap, true);







251 }
252 
253 - (void)sendJavaTouchEvent:(NSEvent *)theEvent
254 {
255     jint modifiers = GetJavaModifiers(theEvent);
256 
257     const NSSet* touchPoints =
258             [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
259 
260     //
261     // Known issues with OSX touch input:
262     // - multiple 'NSTouchPhaseBegan' for the same touch point;
263     // - missing 'NSTouchPhaseEnded' for released touch points
264     //  (RT-20139, RT-20375);
265     //
266 
267     //
268     // Find just released touch points that are not in the cache already.
269     // Don't send TouchEvent#TOUCH_RELEASED for these touch points.
270     //

  1 /*
  2  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

159     if (!glassTouches || glassTouches->curConsumer != delegate)
160     {
161         return;
162     }
163 
164     // Keep updating java touch point counter, just have no view to notify.
165     glassTouches->curConsumer = nil;
166 
167     LOG("TOUCHES: stopTracking: delegate=%p\n", glassTouches->curConsumer);
168 }
169 
170 + (void)terminate
171 {
172     // Should be called right after Application's run loop terminate
173     [glassTouches terminateImpl];
174     glassTouches = nil;
175 }
176 
177 - (id)init
178 {
179     BOOL useEventTap = YES;
180     if (@available(macOS 10.15, *)) {
181         useEventTap = NO;
182     }
183 
184     self = [super init];
185     if (self != nil)
186     {
187         self->curConsumer   = nil;
188         self->eventTap      = nil;
189         self->runLoopSource = nil;
190         self->touches       = nil;
191         self->lastTouchId   = 0;
192 
193         if (useEventTap) {
194             //
195             // Notes after fixing RT-23199:
196             //
197             //  Don't use NSMachPort and NSRunLoop to integrate CFMachPortRef
198             //  instance into run loop.
199             //
200             // Ignoring the above "don't"s results into performance degradation
201             // referenced in the bug.
202             //
203 
204             self->eventTap = CGEventTapCreate(kCGHIDEventTap,
205                                               kCGHeadInsertEventTap,
206                                               kCGEventTapOptionListenOnly,
207                                               CGEventMaskBit(NSEventTypeGesture),
208                                               listenTouchEvents, nil);
209 
210             LOG("TOUCHES: eventTap=%p\n", self->eventTap);
211 
212             if (self->eventTap)
213             {   // Create a run loop source.
214                 self->runLoopSource = CFMachPortCreateRunLoopSource(
215                                                             kCFAllocatorDefault,
216                                                             self->eventTap, 0);
217 
218                 LOG("TOUCHES: runLoopSource=%p\n", self->runLoopSource);
219 
220                 // Add to the current run loop.
221                 CFRunLoopAddSource(CFRunLoopGetCurrent(), self->runLoopSource,
222                                    kCFRunLoopCommonModes);
223             }
224         }
225     }
226     return self;
227 }
228 
229 @end
230 
231 
232 @implementation GlassTouches (hidden)
233 - (void)terminateImpl
234 {
235     BOOL useEventTap = YES;
236     if (@available(macOS 10.15, *)) {
237         useEventTap = NO;






238     }
239 
240     if (useEventTap) {
241         LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
242             self->runLoopSource);
243 
244         if (self->runLoopSource)
245         {
246             CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
247                                   kCFRunLoopCommonModes);
248             CFRelease(self->runLoopSource);
249             self->runLoopSource = nil;
250         }
251 
252         if (self->eventTap)
253         {
254             CFRelease(self->eventTap);
255             self->eventTap = nil;
256         }
257     }
258     [self releaseTouches];
259 }
260 
261 - (void)enableTouchInputEventTap
262 {
263     BOOL useEventTap = YES;
264     if (@available(macOS 10.15, *)) {
265         useEventTap = NO;
266     }
267 
268     if (useEventTap) {
269         CGEventTapEnable(self->eventTap, true);
270     }
271 }
272 
273 - (void)sendJavaTouchEvent:(NSEvent *)theEvent
274 {
275     jint modifiers = GetJavaModifiers(theEvent);
276 
277     const NSSet* touchPoints =
278             [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
279 
280     //
281     // Known issues with OSX touch input:
282     // - multiple 'NSTouchPhaseBegan' for the same touch point;
283     // - missing 'NSTouchPhaseEnded' for released touch points
284     //  (RT-20139, RT-20375);
285     //
286 
287     //
288     // Find just released touch points that are not in the cache already.
289     // Don't send TouchEvent#TOUCH_RELEASED for these touch points.
290     //
< prev index next >