Determining if `mouseMove` is caused by mouse or component

Hi there,

I’ve bumped into an issue regarding the way mouseMove is handled with regards to components changing position. I’m using a ListBox, and I need to be able to differentiate between mouseMove callbacks that occur because the mouse actually moved on the desktop vs. those that occur because the Viewport has scrolled, causing a mouseMove call due to the change in relative mouse position. My use case is that I generally want mouseMove to trigger row selection, but not when the list scrolling was triggered by the up/down arrow keys.

I came across this thread in my research, but obviously there wasn’t much fruitful discussion going on there. I haven’t seen the problem mentioned otherwise.

My current solution is to use a flag to ignore the next mouseMove event that occurs after any listWasScrolled callback, but obviously this is far from ideal. I can’t determine any way to query the MouseEvent for its cause which would be ideal. I’d appreciate any suggestions, and if no facilities exist for separating these types of events I’d also like to suggest that that feature be added!

I haven’t looked into this at all but I wonder if you could have a component that lives on top of the viewport (but not over the scrollbars) that could consume mouse events and perform the required action on the contents of the viewport? I think that would mean the mouse moves would only occur when the cursor changes position.

1 Like

By “consume” mouse events, do you mean consume and not pass to the component itself, as can happen when returning true from KeyListener::KeyPressed? If so, I wasn’t aware there was a way to do that. However, what I assume you mean is that there’s a component that’s physically on top of the viewport in the z-order. That does sound like a good solution, as it is possible to do listbox->getViewport()->addChildComponent().

I won’t be trying this method out because our product’s design has changed in a way that doesn’t require this behavior anymore, but thank you for the help!