From 5609ee67d65c035c8a03d4791567d9e72fa0df8b Mon Sep 17 00:00:00 2001 From: SerVB Date: Tue, 25 Aug 2020 17:36:46 +0300 Subject: [PATCH] PRJ-106 Fix cursor for overlapping windows --- .../main/kotlin/org/jetbrains/projector/awt/PWindow.kt | 4 ---- .../org/jetbrains/projector/awt/peer/PComponentPeer.kt | 4 ++-- .../org/jetbrains/projector/awt/peer/PMouseInfoPeer.kt | 5 +++-- .../org/jetbrains/projector/server/ProjectorServer.kt | 10 ++++++++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/PWindow.kt b/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/PWindow.kt index 5a294763..dcad2da3 100644 --- a/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/PWindow.kt +++ b/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/PWindow.kt @@ -168,10 +168,6 @@ class PWindow(val target: Component) { } fun getWindow(windowId: Int): PWindow? = windows.find { it.id == windowId } - - fun findWindowAt(x: Int, y: Int): PWindow? { - return windows.lastOrNull { it.target.isShowing && it.target.bounds.contains(x, y) } - } } class Descriptor(val windowId: Int) diff --git a/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PComponentPeer.kt b/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PComponentPeer.kt index 089f77c5..25c61de7 100644 --- a/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PComponentPeer.kt +++ b/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PComponentPeer.kt @@ -131,9 +131,9 @@ abstract class PComponentPeer(target: Component, private val isFocusable: Boolea } override fun updateCursorImmediately() { - // todo: delegate to GlobalCursorManager (like in XComponentPeer) and change logic (don't search for container under mouse) + // todo: delegate to GlobalCursorManager (like in XComponentPeer) val mousePoint = PMouseInfoPeer.lastMouseCoords - val containerUnderMouse = PWindow.findWindowAt(mousePoint.x, mousePoint.y)?.target as? Container + val containerUnderMouse = PMouseInfoPeer.lastWindowUnderMouse as? Container val cursorUnderMouse = containerUnderMouse?.let { val location = it.location diff --git a/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PMouseInfoPeer.kt b/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PMouseInfoPeer.kt index 3554b815..0a773ffa 100644 --- a/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PMouseInfoPeer.kt +++ b/projector-awt/src/main/kotlin/org/jetbrains/projector/awt/peer/PMouseInfoPeer.kt @@ -20,7 +20,7 @@ package org.jetbrains.projector.awt.peer -import org.jetbrains.projector.awt.PWindow +import java.awt.Component import java.awt.Point import java.awt.Window import java.awt.peer.MouseInfoPeer @@ -30,6 +30,7 @@ object PMouseInfoPeer : MouseInfoPeer { private const val PRIMARY_SCREEN_DEVICE_ID = 0 val lastMouseCoords = Point() + var lastWindowUnderMouse: Component? = null override fun fillPointWithCoords(point: Point): Int { point.location = lastMouseCoords @@ -37,6 +38,6 @@ object PMouseInfoPeer : MouseInfoPeer { } override fun isWindowUnderMouse(w: Window): Boolean { - return PWindow.findWindowAt(lastMouseCoords.x, lastMouseCoords.y)?.target == w + return w == lastWindowUnderMouse } } diff --git a/projector-server/src/main/kotlin/org/jetbrains/projector/server/ProjectorServer.kt b/projector-server/src/main/kotlin/org/jetbrains/projector/server/ProjectorServer.kt index 6a38476e..8dc6f499 100644 --- a/projector-server/src/main/kotlin/org/jetbrains/projector/server/ProjectorServer.kt +++ b/projector-server/src/main/kotlin/org/jetbrains/projector/server/ProjectorServer.kt @@ -263,7 +263,10 @@ class ProjectorServer private constructor( PMouseInfoPeer.lastMouseCoords.setLocation(shiftedMessage.x, shiftedMessage.y) - val window = PWindow.getWindow(message.windowId)?.target ?: return@invokeLater + val window = PWindow.getWindow(message.windowId)?.target + PMouseInfoPeer.lastWindowUnderMouse = window + + window ?: return@invokeLater fun isEnoughDeltaForScrolling(previousTouchState: TouchState.Scrolling, newX: Int, newY: Int): Boolean { // reduce number of scroll events to make deltas bigger. @@ -299,7 +302,10 @@ class ProjectorServer private constructor( val shiftedMessage = message.shift(PGraphicsDevice.clientShift) PMouseInfoPeer.lastMouseCoords.setLocation(shiftedMessage.x, shiftedMessage.y) - val window = PWindow.getWindow(message.windowId)?.target ?: return@invokeLater + val window = PWindow.getWindow(message.windowId)?.target + PMouseInfoPeer.lastWindowUnderMouse = window + + window ?: return@invokeLater val mouseWheelEvent = createMouseWheelEvent(window, shiftedMessage, clientSettings.connectionMillis) laterInvokator(mouseWheelEvent)