-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Left/right/middle mouse click/drag #129
Comments
We added private suspend fun AwaitPointerEventScope.awaitEventFirstDown(): PointerEvent {
var event: PointerEvent
do {
event = awaitPointerEvent()
} while (
!event.changes.all { it.changedToDown() }
)
return event
}
var lastEvent by remember { mutableStateOf<MouseEvent?>(null) }
Text(
modifier = Modifier.pointerInput(Unit) {
forEachGesture {
awaitPointerEventScope {
lastEvent = awaitEventFirstDown().also {
it.changes.forEach { it.consumeDownChange() }
}.mouseEvent
}
}
},
text = "Custom mouse event button: ${lastEvent?.button}"
) |
One addition to this workaround that someone might find useful. You can user this in addition to normal
The order of modifiers matters here. Not sure why. My theory is that |
@prepor do we still have anything to do here? |
Whenever I'm inside of this code, inside of forEachGesture {
awaitPointerEventScope {
val down = awaitFirstDown()
drag(down.id) {
println(currentEvent.mouseEvent?.button)
}
}
} The printed result I get is |
Furthermore, there's no way of handling mouseUp. I really would like to handle a mouse release over an element, but that doesn't seem to be possible (only mouse down). This is so that I can implement drag & drop, releasing the mouse on a different element. |
Seems like this is also missing on the web. The info is there in the native pointer events, but it's really inconvenient to get to. Disclaimer: this modifier code here might conflict with other clicks/gestures, use with caution, the event consuming part could probably be written in a nicer way. Modifier.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
val nativeEvent = event.nativeEvent
if (nativeEvent is SkikoPointerEvent) {
if (nativeEvent.button == SkikoMouseButtons.RIGHT && nativeEvent.kind == SkikoPointerEventKind.UP) {
event.changes.forEach { it.consume() } // or similar, would need to check if this works nicely with other registered listeners
println("Right click!")
}
}
}
}
} |
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Right now its impossible to know which mouse button was used, I would like to be able to assign different behaviors to each kind of click and drag.
The text was updated successfully, but these errors were encountered: