Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8231513: JavaFX cause Keystroke Receiving prompt on MacOS 10.15 (Catalina) #102

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
110 changes: 65 additions & 45 deletions modules/javafx.graphics/src/main/native-glass/mac/GlassTouches.m
@@ -1,5 +1,5 @@
/*
* 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
Expand Down Expand Up @@ -176,6 +176,11 @@ + (void)terminate

- (id)init
{
BOOL useEventTap = YES;
kevinrushforth marked this conversation as resolved.
Show resolved Hide resolved
if (@available(macOS 10.15, *)) {
useEventTap = NO;
}

self = [super init];
if (self != nil)
{
Expand All @@ -185,35 +190,37 @@ - (id)init
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;
Expand All @@ -225,29 +232,42 @@ - (id)init
@implementation GlassTouches (hidden)
- (void)terminateImpl
{
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;
BOOL useEventTap = YES;
if (@available(macOS 10.15, *)) {
useEventTap = NO;
}

if (self->eventTap)
{
CFRelease(self->eventTap);
self->eventTap = nil;
}
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->eventTap)
{
CFRelease(self->eventTap);
self->eventTap = nil;
}
}
[self releaseTouches];
}

- (void)enableTouchInputEventTap
{
CGEventTapEnable(self->eventTap, true);
BOOL useEventTap = YES;
if (@available(macOS 10.15, *)) {
useEventTap = NO;
}

if (useEventTap) {
CGEventTapEnable(self->eventTap, true);
}
}

- (void)sendJavaTouchEvent:(NSEvent *)theEvent
Expand Down