Skip to content

Fix missing mouse release event scenario with magic mouse#2909

Merged
Alexander Maryanovsky (m-sasha) merged 8 commits into
jb-mainfrom
m-sasha/fix-magic-mouse-scenario
Apr 1, 2026
Merged

Fix missing mouse release event scenario with magic mouse#2909
Alexander Maryanovsky (m-sasha) merged 8 commits into
jb-mainfrom
m-sasha/fix-magic-mouse-scenario

Conversation

@m-sasha

@m-sasha Alexander Maryanovsky (m-sasha) commented Mar 24, 2026

Copy link
Copy Markdown

Fix SyntheticEventSender's sendMissingPresses and sendMissingReleases to send all missing presses/releases.

Fixes https://youtrack.jetbrains.com/issue/CMP-9964

Follow-up task: CMP-10029 Rework native events access in PointerInputEvent

Testing

Added unit tests and tested manually on Amazon Corretto 21.0.10 with:

fun Modifier.myClickable(onClick: () -> Unit): Modifier =
    pointerInput(Unit) {
        awaitEachGesture {
            val down = awaitFirstDown()
            println("DOWN: $down")
            down.consume()

            while (true) {
                val event = awaitPointerEvent()

                if (event.changes.fastAny { it.changedToUp() }) {
                    println("UP: $event")
                    onClick()
                    break
                } else {
                    println("event: $event")
                }
            }
        }
    }

@Composable
fun ClickTestWindow(onCloseRequest: () -> Unit) {
    Window(
        onCloseRequest = onCloseRequest,
        state = rememberWindowState(size = DpSize.Unspecified),
        title = "Click test",
    ) {
        var clickCount by remember { mutableStateOf(0) }

        DisposableEffect(Unit) {
            val mouseListener =  object : MouseAdapter() {
                override fun mousePressed(e: MouseEvent) = println("AWT: Mouse pressed: $e")
                override fun mouseReleased(e: MouseEvent) = println("AWT: Mouse released: $e")
                override fun mouseMoved(e: MouseEvent) = println("AWT: Mouse moved: $e")
                override fun mouseDragged(e: MouseEvent?) = println("AWT: Mouse dragged: $e")
            }

            window.addMouseListener(mouseListener)
            window.addMouseMotionListener(mouseListener)
            onDispose {
                window.removeMouseListener(mouseListener)
                window.removeMouseMotionListener(mouseListener)
            }
        }

        Column(
            modifier = Modifier.padding(16.dp),
            verticalArrangement = Arrangement.spacedBy(16.dp),
        ) {
            Text(text = "Click count: $clickCount")
            Box(
                modifier =
                    Modifier
                        .requiredSize(400.dp)
                        .background(Color.Red)
                        .myClickable {
                            println("--- Increase click count to: ${++clickCount} ---")
                        },
            )
        }
    }
}

fun main() = application {
    ClickTestWindow(
        onCloseRequest = ::exitApplication
    )
}

This should be tested by QA

Release Notes

Fixes - Multiple Platforms

  • Fixed occasional mouse-clicks being missed (typically when using Apple's Magic Mouse).

@m-sasha Alexander Maryanovsky (m-sasha) force-pushed the m-sasha/fix-magic-mouse-scenario branch from 083aaed to 99a9b83 Compare April 1, 2026 10:21

@igordmn Igor Demin (igordmn) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with any decision regarding the opened comments

@m-sasha Alexander Maryanovsky (m-sasha) merged commit 6cbdd56 into jb-main Apr 1, 2026
21 checks passed
@m-sasha Alexander Maryanovsky (m-sasha) deleted the m-sasha/fix-magic-mouse-scenario branch April 1, 2026 15:48
Vlad Konstantinov (Kpotko) added a commit that referenced this pull request Apr 13, 2026
Fix SyntheticEventSender's sendMissingPresses and sendMissingReleases to
send all missing presses/releases.

This is a cherry-pick of
#2909

## Testing
N/A

## Release Notes
### Fixes - Multiple Platforms
- Fixed occasional mouse-clicks being missed (typically when using
Apple's Magic Mouse).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants