display: clamp coordinates to framebuffer range#186
Open
gaberudy wants to merge 1 commit intokasmtech:masterfrom
Open
display: clamp coordinates to framebuffer range#186gaberudy wants to merge 1 commit intokasmtech:masterfrom
gaberudy wants to merge 1 commit intokasmtech:masterfrom
Conversation
absX/absY and clientToElement could produce negative or out-of-range values when the cursor leaves the primary screen on a side with no adjacent virtual screen. Without clamping, the negative value got packed into a uint16 on the wire and the server saw a huge positive coord, snapping the cursor to the far edge. Clamps to [0, fbWidth-1] and [0, fbHeight-1] in absX, absY, and clientToElement (multi-screen path).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
absX,absY, and the multi-screen branch ofclientToElementcan producenegative or out-of-range values when the cursor exits the primary screen on
a side with no adjacent virtual screen (e.g. dragging a window's title bar
above the top edge so the pointer's logical Y goes < 0).
The negative
intresult reachesRFB.messages.pointerEventand gets packedas a
uint16on the wire. The server decodes it as a huge positive coord andsnaps the cursor to the far edge of the framebuffer.
In practice this manifests as: drag a window upward, pointer touches the top
of the canvas, cursor jumps to the bottom edge, drag glitches.
Fix
Clamp the result of each coordinate transform to
[0, fbWidth-1]/[0, fbHeight-1]before returning. The clamp is applied in three places:absX(x)— single-screen pathabsY(y)— single-screen pathclientToElement(...)— multi-screen extension path (which can also yieldnegative values for the same reason)
_fbWidth/_fbHeightmay be 0 before resize negotiation completes; theupper-bound check is gated on truthy width/height to preserve current behavior
during connect.
Repro
Connect via kasmweb to a session, grab a window's title bar, drag upward past
the top of the canvas. The window snaps to the bottom of the screen. With this patch the cursor stays clamped at y=0 and the drag behaves as expected (window stays pinned to the top of the screen).