Skip to content
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

Ignore AWT mouse events during window resize #949

Merged
merged 3 commits into from
Dec 19, 2023

Conversation

m-sasha
Copy link
Member

@m-sasha m-sasha commented Dec 18, 2023

While resizing the window by dragging it by its edge, AWT (at least on macOS) sends mouse enter/exit events that report the primary button as pressed. This causes PointerInputScope.detectTapAndPress to falsely detect a tap.

Proposed Changes

Ignore mouse events that signal a change in the pressed state of the primary mouse button, but aren't mouse press/release events.

Testing

Test: tested manually that resizing the window no longer triggers PointerInputScope.detectTapAndPress.

Issues Fixed

Fixes: JetBrains/compose-multiplatform#2850

@m-sasha m-sasha requested a review from igordmn December 18, 2023 11:26
@@ -279,9 +279,43 @@ internal abstract class ComposeBridge(
})
}

// Decides which AWT events should be delivered, and which should be filtered out
private val awtEventFilter = object {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need an extra object here? It seems like it can be just private functions

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need it, but I think it's cleaner to bundle it into a "filter" object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This also looks cleaner to me

return !isDisposed
}
}

private fun onMouseEvent(event: MouseEvent): Unit = catchExceptions {
Copy link
Member

Choose a reason for hiding this comment

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

It's called from several places including mouseEntered/mouseExited events, so it looks like we need to filter it only there and drop additional bool storage

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to know the current pressed state of the primary mouse button in order to filter correctly.

@@ -279,9 +279,43 @@ internal abstract class ComposeBridge(
})
}

// Decides which AWT events should be delivered, and which should be filtered out
private val awtEventFilter = object {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also looks cleaner to me

@m-sasha m-sasha requested a review from igordmn December 19, 2023 13:17
@m-sasha m-sasha force-pushed the m-sasha/filter-awt-mouse-events branch from b361f3d to d4749a5 Compare December 19, 2023 15:09
@m-sasha m-sasha requested a review from igordmn December 19, 2023 15:20
@m-sasha m-sasha force-pushed the m-sasha/filter-awt-mouse-events branch from d4749a5 to 55ee365 Compare December 19, 2023 15:25
@m-sasha m-sasha merged commit 14af0a1 into jb-main Dec 19, 2023
4 checks passed
@m-sasha m-sasha deleted the m-sasha/filter-awt-mouse-events branch December 19, 2023 16:35
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.

Resizing window on desktop sometimes triggers onClick handlers of Composables
3 participants