Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8231513: JavaFX cause Keystroke Receiving prompt on MacOS 10.15 (Cata…
…lina)

Reviewed-by: prr, jvos
  • Loading branch information
kevinrushforth committed Feb 1, 2020
1 parent 1823f6e commit 2ab40c1
Showing 1 changed file with 56 additions and 45 deletions.
101 changes: 56 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 @@ -42,6 +42,7 @@


static GlassTouches* glassTouches = nil;
static BOOL useEventTap = NO;


@interface GlassTouches (hidden)
Expand Down Expand Up @@ -176,6 +177,11 @@ + (void)terminate

- (id)init
{
useEventTap = YES;
if (@available(macOS 10.15, *)) {
useEventTap = NO;
}

self = [super init];
if (self != nil)
{
Expand All @@ -185,35 +191,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 +233,32 @@ - (id)init
@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
Expand Down

1 comment on commit 2ab40c1

@nicolabeghin
Copy link

@nicolabeghin nicolabeghin commented on 2ab40c1 Feb 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nicolabeghin, thanks for making a comment in an OpenJDK project!

All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user nicolabeghin for the summary.

If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.

Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.

Please sign in to comment.