Is there a way to "query" current pointer (cursor)...
# compose-desktop
d
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
You can save it when you detect the click
m
java.awt.MouseInfo.getPointerInfo().getLocation()
a
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.