Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
PRJ-106 Fix cursor for overlapping windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SerVB committed Aug 25, 2020
1 parent e63bc78 commit 5609ee6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,13 +30,14 @@ 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
return PRIMARY_SCREEN_DEVICE_ID
}

override fun isWindowUnderMouse(w: Window): Boolean {
return PWindow.findWindowAt(lastMouseCoords.x, lastMouseCoords.y)?.target == w
return w == lastWindowUnderMouse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5609ee6

Please sign in to comment.