< prev index next >

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

Print this page

 25 
 26 #import "common.h"
 27 #import "com_sun_glass_events_TouchEvent.h"
 28 
 29 #import "GlassMacros.h"
 30 #import "GlassTouches.h"
 31 #import "GlassKey.h"
 32 #import "GlassHelper.h"
 33 #import "GlassStatics.h"
 34 
 35 
 36 //#define VERBOSE
 37 #ifndef VERBOSE
 38     #define LOG(MSG, ...)
 39 #else
 40     #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
 41 #endif
 42 
 43 
 44 static GlassTouches* glassTouches = nil;

 45 
 46 
 47 @interface GlassTouches (hidden)
 48 
 49 - (void)releaseTouches;
 50 
 51 - (void)terminateImpl;
 52 
 53 - (void)enableTouchInputEventTap;
 54 
 55 - (void)sendJavaTouchEvent:(NSEvent *)theEvent;
 56 - (void)notifyTouch:(JNIEnv*)env    identity:(const id)identity
 57                                     phase:(NSUInteger)phase
 58                                     pos:(const NSPoint*)pos;
 59 @end
 60 
 61 
 62 static jint getTouchStateFromPhase(NSUInteger phase)
 63 {
 64     switch (phase)

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             //

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     //

 25 
 26 #import "common.h"
 27 #import "com_sun_glass_events_TouchEvent.h"
 28 
 29 #import "GlassMacros.h"
 30 #import "GlassTouches.h"
 31 #import "GlassKey.h"
 32 #import "GlassHelper.h"
 33 #import "GlassStatics.h"
 34 
 35 
 36 //#define VERBOSE
 37 #ifndef VERBOSE
 38     #define LOG(MSG, ...)
 39 #else
 40     #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
 41 #endif
 42 
 43 
 44 static GlassTouches* glassTouches = nil;
 45 static BOOL useEventTap = NO;
 46 
 47 
 48 @interface GlassTouches (hidden)
 49 
 50 - (void)releaseTouches;
 51 
 52 - (void)terminateImpl;
 53 
 54 - (void)enableTouchInputEventTap;
 55 
 56 - (void)sendJavaTouchEvent:(NSEvent *)theEvent;
 57 - (void)notifyTouch:(JNIEnv*)env    identity:(const id)identity
 58                                     phase:(NSUInteger)phase
 59                                     pos:(const NSPoint*)pos;
 60 @end
 61 
 62 
 63 static jint getTouchStateFromPhase(NSUInteger phase)
 64 {
 65     switch (phase)

160     if (!glassTouches || glassTouches->curConsumer != delegate)
161     {
162         return;
163     }
164 
165     // Keep updating java touch point counter, just have no view to notify.
166     glassTouches->curConsumer = nil;
167 
168     LOG("TOUCHES: stopTracking: delegate=%p\n", glassTouches->curConsumer);
169 }
170 
171 + (void)terminate
172 {
173     // Should be called right after Application's run loop terminate
174     [glassTouches terminateImpl];
175     glassTouches = nil;
176 }
177 
178 - (id)init
179 {
180     useEventTap = YES;
181     if (@available(macOS 10.15, *)) {
182         useEventTap = NO;
183     }
184 
185     self = [super init];
186     if (self != nil)
187     {
188         self->curConsumer   = nil;
189         self->eventTap      = nil;
190         self->runLoopSource = nil;
191         self->touches       = nil;
192         self->lastTouchId   = 0;
193 
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             //

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             }
225         }
226     }
227     return self;
228 }
229 
230 @end
231 
232 
233 @implementation GlassTouches (hidden)
234 - (void)terminateImpl
235 {





236     if (useEventTap) {
237         LOG("TOUCHES: terminateImpl eventTap=%p runLoopSource=%p\n", self->eventTap,
238             self->runLoopSource);
239 
240         if (self->runLoopSource)
241         {
242             CFRunLoopRemoveSource(CFRunLoopGetCurrent(), self->runLoopSource,
243                                   kCFRunLoopCommonModes);
244             CFRelease(self->runLoopSource);
245             self->runLoopSource = nil;
246         }
247 
248         if (self->eventTap)
249         {
250             CFRelease(self->eventTap);
251             self->eventTap = nil;
252         }
253     }
254     [self releaseTouches];
255 }
256 
257 - (void)enableTouchInputEventTap
258 {





259     if (useEventTap) {
260         CGEventTapEnable(self->eventTap, true);
261     }
262 }
263 
264 - (void)sendJavaTouchEvent:(NSEvent *)theEvent
265 {
266     jint modifiers = GetJavaModifiers(theEvent);
267 
268     const NSSet* touchPoints =
269             [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
270 
271     //
272     // Known issues with OSX touch input:
273     // - multiple 'NSTouchPhaseBegan' for the same touch point;
274     // - missing 'NSTouchPhaseEnded' for released touch points
275     //  (RT-20139, RT-20375);
276     //
277 
278     //
< prev index next >