From 2efd1b41757ee63ab8d0c8a970586926e11e6f70 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sat, 10 Oct 2020 16:47:34 +0200 Subject: [PATCH] UI Tracker initial GitOrigin-RevId: ee04e511ebff2bd5438fdbc41ff5de4543f1ad5a --- .../src/com/intellij/ide/IdeEventQueue.java | 1 + .../src/com/intellij/ide/UIMouseTracker.kt | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 platform/platform-impl/src/com/intellij/ide/UIMouseTracker.kt diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 20346667ae56..db1bc073f871 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -219,6 +219,7 @@ public final class IdeEventQueue extends EventQueue { addDispatcher(new WindowsUpMaximizer(), null); } addDispatcher(new EditingCanceller(), null); + //addDispatcher(new UIMouseTracker(), null); abracadabraDaberBoreh(); diff --git a/platform/platform-impl/src/com/intellij/ide/UIMouseTracker.kt b/platform/platform-impl/src/com/intellij/ide/UIMouseTracker.kt new file mode 100644 index 000000000000..52b04967d115 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/UIMouseTracker.kt @@ -0,0 +1,62 @@ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ide + +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.openapi.wm.impl.IdeGlassPaneImpl +import java.awt.* +import java.awt.event.MouseEvent +import javax.swing.SwingUtilities +import kotlin.math.sqrt + +/** + * @author Konstantin Bulenkov + */ +class UIMouseTracker : IdeEventQueue.EventDispatcher { + var mouseCoordinates = MouseInfo.getPointerInfo().location ?: Point(0,0) + var totalMouseTrack = 0f + + override fun dispatch(e: AWTEvent): Boolean { + if (e is MouseEvent) { + when (e.id) { + MouseEvent.MOUSE_RELEASED -> onMouseClicked(e) + MouseEvent.MOUSE_MOVED -> onMouseMove(e) + } + } + + return false + } + + private fun onMouseMove(e: MouseEvent) { + val dX = (e.xOnScreen - mouseCoordinates.x).toFloat() + val dY = (e.yOnScreen - mouseCoordinates.y).toFloat() + mouseCoordinates.x = e.xOnScreen + mouseCoordinates.y = e.yOnScreen + totalMouseTrack += sqrt(dX*dX + dY*dY) + } + + private fun onMouseClicked(e: MouseEvent) { + if (e.clickCount == 0) return + + val component = e.component + val clickedComponent = if (component is Container) component.findComponentAt(e.point) else null + + if (clickedComponent != null) { + if (clickedComponent is IdeGlassPaneImpl) { + val dialog = DialogWrapper.findInstance(clickedComponent) + if (dialog != null) { + val pointOnDialog = SwingUtilities.convertPoint(e.component, e.point, dialog.contentPane) + val comp = dialog.contentPane.findComponentAt(pointOnDialog.x, pointOnDialog.y) + if (comp != null) { + componentClicked(comp) + } + } + } else { + componentClicked(clickedComponent) + } + } + } + + private fun componentClicked(comp: Component) { + //todo[kb] API with UI components to report stats + } +} \ No newline at end of file