From a9209297dfca93e4750bf5c1c28620908eb104bf Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 31 Aug 2015 13:07:17 +0300 Subject: [PATCH] diagnostics for IDEA-143603 (unable to paste text copied from other applications) --- .../src/com/intellij/ide/IdeEventQueue.java | 36 +++++++++++++++++++ .../util/resources/misc/registry.properties | 6 +++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 51ccdff43c77..b53c1a6cd250 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -521,6 +521,8 @@ public class IdeEventQueue extends EventQueue { } myEventCount++; + + traceClipboardEvents(e); if (e instanceof WindowEvent) { processAppActivationEvents((WindowEvent)e); @@ -648,6 +650,40 @@ public class IdeEventQueue extends EventQueue { } } + private static final Field ourInvocationEventRunnableAccessor; + + static { + Field field = null; + if (Registry.is("trace.clipboard.events") && SystemInfo.isJavaVersionAtLeast("1.8.0_60")) { + try { + field = InvocationEvent.class.getDeclaredField("runnable"); + field.setAccessible(true); + } + catch (Exception e) { + LOG.warn("Error creating accessor for java.awt.event.InvocationEvent.runnable field", e); + } + } + ourInvocationEventRunnableAccessor = field; + } + + private static void traceClipboardEvents(AWTEvent e) { + if (ourInvocationEventRunnableAccessor != null && e instanceof InvocationEvent && e.getClass().getName().equals("sun.awt.PeerEvent")) { + try { + Object r = ourInvocationEventRunnableAccessor.get(e); + if (r != null) { + String className = r.getClass().getName(); + // This check for event constructed in SunClipboard.lostOwnershipLater() (known to work with JDK 8u60) + if (className.contains("sun.awt.datatransfer.SunClipboard") && className.contains("Lambda")) { + LOG.info("Clipboard has been set by other application"); + } + } + } + catch (Exception ex) { + LOG.warn("Error accessing java.awt.event.InvocationEvent.runnable field"); + } + } + } + private MouseEvent lastClickEvent = null; private long lastClickTime = 0L; diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 9b7ad38fe876..85efd2301fbd 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -653,4 +653,8 @@ ruby.remote.debugger.supports.catchpoint.removal=true use.read.action.to.init.service=true -ide.mac.new.color.picker=false \ No newline at end of file +ide.mac.new.color.picker=false + +trace.clipboard.events=false +trace.clipboard.events.description=Enable detection and logging of OS notifications about external clipboard changes +trace.clipboard.events.restartRequired=true \ No newline at end of file