https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
d

dimsuz

03/25/2023, 4:45 PM
Is there a way to "query" current pointer (cursor) position? For example: user clicks, I query and do some stuff depending on where the cursor is. I know I can constantly track it using
Modifier.onPointerEvent
and save it to mutableStateOf, but that sounds like a bit of an overkill for cases when I want to only react on clicks.
a

Alexander Maryanovsky

03/25/2023, 5:48 PM
You can save it when you detect the click
m

mikehearn

03/27/2023, 11:52 AM
java.awt.MouseInfo.getPointerInfo().getLocation()
a

Alexander Maryanovsky

03/27/2023, 12:46 PM
It’s tricky to use that correctly. You don’t want to access it directly in a composition.
We’re getting rid of that internally in compose-for-desktop in favor of having the mouse event that triggers the action also store the location and pass it to the composition via state hoisting.
25 Views