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

Dragging prevents pointer move events. #134

Closed
Cybermaxke opened this issue Nov 22, 2020 · 2 comments
Closed

Dragging prevents pointer move events. #134

Cybermaxke opened this issue Nov 22, 2020 · 2 comments
Assignees
Labels
bug Something isn't working input Touch, mouse, keyboard input related

Comments

@Cybermaxke
Copy link

Cybermaxke commented Nov 22, 2020

Affects: 0.2.0-build127

While dragging it's not possible to receive any other mouse move events, I traced the issue back to the MouseMotionListener that is being registered. mouseMoved will not be called while dragging is active, mouseDragged is called in that case.

I currently have the following temporary workaround:

fun main() = Window(title = "Porygen", size = IntSize(600, 1000)) {
  Root()

  // Get the wrapped ComposeLayer
  val window = AppWindowAmbient.current!!.window.contentPane.getComponent(0)
  // Get the original motion listener
  val listener = window.mouseMotionListeners.first()
  window.addMouseMotionListener(object : MouseMotionListener {
    override fun mouseDragged(e: MouseEvent) {
      // Also trigger mouse moved so we don't get locked
      // out of other pointer events while dragging
      listener.mouseMoved(e)
    }
    override fun mouseMoved(e: MouseEvent) {
    }
  })
}
@igordmn igordmn added the bug Something isn't working label Nov 25, 2020
@olonho olonho added the input Touch, mouse, keyboard input related label Dec 8, 2020
@wooodenleg
Copy link

Thanks for the MouseMotionListener tip 👍

Any progress on this issue?

copybara-service bot pushed a commit to androidx/androidx that referenced this issue May 7, 2021
Difference between Swing drag and move events:
- move events are fired only in the bounds of the window and when mouse isn't pressed
- drag events are fired when mouse is pressed and can be fired even if the mouse outside of the pressed window

Currently we treat drag events only as Modifier.pointerInput events.
And move events only as Modifier.onPointerMove events

This CL allows:
- handle any mouse move/drag events with Modifier.pointerInput
- use mouse hover (Modifier.onPointerMove) with the pressed mouse button

But after this some components should handle Modifier.onPointerMove(onExit={}) differently.
For example, we need to keep scrollbar highlighted when we move mouse outside of the scrollbar.

Before this CL this was handled automatically, because we didn't send move events when we drag the mouse.
But it shouldn't be handled automatically, developer should explicitly write this logic
(keep scrollbar highlighted when we drag it)

Fixes:
JetBrains/compose-multiplatform#134
JetBrains/compose-multiplatform#530

Change-Id: If510840c2c7e4bf2e192f9990e5a05cec592635a
Test: manual ./gradlew :compose:desktop:desktop:desktop-samples:run1 -Pandroidx.compose.multiplatformEnabled=true
Test: drag Scrollbar and move mouse outside
@igordmn
Copy link
Collaborator

igordmn commented May 12, 2021

Should be fixed in 0.4.0-build190.

Now both Swing's mouseDragged/mouseMoved events are treated as Modifier.pointerInput and Modifier.pointerMove events (we plan to integrate pointerMove onExit/onEnter into pointerInput in the future).

@igordmn igordmn closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working input Touch, mouse, keyboard input related
Projects
None yet
Development

No branches or pull requests

4 participants