Bug 194143 - WM_MOUSEWHEEL can send fractional deltas
Summary: WM_MOUSEWHEEL can send fractional deltas
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows Vista
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 M4   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 212642 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-06-24 15:29 EDT by Daniel Potter CLA
Modified: 2020-07-22 08:27 EDT (History)
4 users (show)

See Also:


Attachments
Patch against latest SWT to support fractional deltas (2.08 KB, patch)
2007-06-24 15:30 EDT, Daniel Potter CLA
no flags Details | Diff
Proof of concept patch for free-spin logitech mousewheels (2.03 KB, patch)
2008-01-15 18:41 EST, Francois CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Potter CLA 2007-06-24 15:29:15 EDT
The currently handlers for WM_MOUSEWHEEL in both Scrollable and Widget assume that the delta value for the scroll event will always be a multiple of OS.WHEEL_DELTA, or 120.

Windows Vista changes this behavior, making WM_MOUSEWHEEL send "fractional" wheel deltas, which are slightly smaller than that. Watching the WM_MOUSEWHEEL events demonstrates that Vista frequently sends more WM_MOUSEWHEEL events with smaller deltas - for example, a delta of 90 followed by a delta of 60.

SWT needs to handle these smaller fractional scroll events.

Note that not all mice will cause this effect - it's only been observed in "smooth scroll" mice. Generic mice with the traditional "click"-style wheel that effectively send button presses for scrolling up and down will continue to send OS.WHEEL_DELTA increments.
Comment 1 Daniel Potter CLA 2007-06-24 15:30:57 EDT
Created attachment 72296 [details]
Patch against latest SWT to support fractional deltas

I've created a patch against the current CVS version of SWT to handle fractional wheel deltas. Essentially it just stores the fractional amounts, holding onto them until a full OS.WHEEL_DELTA is encountered and then it functions as normal.
Comment 2 Steve Northover CLA 2007-06-25 12:30:20 EDT
Felipe, didn't you recently have some trouble with your mouse on Vista.  Note that the patch adds a field to Scrollable that we would probably put in Display.
Comment 3 Steve Northover CLA 2007-06-25 13:01:28 EDT
See http://msdn2.microsoft.com/en-us/library/ms645617.aspx for a description of fractional deltas.
Comment 4 Felipe Heidrich CLA 2007-06-25 15:31:18 EDT
I found a good article about this:
http://msdn2.microsoft.com/en-us/library/ms997498.aspx

If we decide to implement smooth scrolling I think we would have to handle fractional lines, in this case the fix would be tottaly different.
see Bug 67137.

The other option is the patch (save the fractional part and add it to the delta of the next message). The patch is a bit incomplete, according to the article:
"The remainder must be zeroed when the wheel rotation switches directions or when window focus changes."
Comment 5 Felipe Heidrich CLA 2007-06-25 17:41:37 EDT
Daniel Potter, what is your mouse ?
If you plug the same mouse to a WinXp box you don't get "fractional" wheel deltas ?
Comment 6 Daniel Potter CLA 2007-06-25 19:26:00 EDT
It's a Microsoft "Wireless IntelliMouse Explorer 2.0", and no, it didn't occur under Windows XP with the same mouse - although I haven't tried it on the same computer with the OS being the only variable.

The only other information of note is the use of Microsoft's IntelliPoint 6 software, although it happened under Vista before I installed IntelliPoint. (At least, I think it did - I haven't tried uninstalling it, and I'm pretty sure one of the reasons I installed it was that the scroll wheel was working erratically in a bunch of programs, Eclipse included. A lot of programs have this problem.)
Comment 7 Felipe Heidrich CLA 2007-06-27 17:35:21 EDT
Daniel, I got a Logitech Revolution and unfortunately this mouse does not send fractional deltas.
I don't think I'll get approval to order a "Microsoft Wireless IntelliMouse Explorer 2.0" so I'll write the code I'll give it to you for testing. Can you help us with that ?
Comment 8 Daniel Potter CLA 2007-08-08 00:02:55 EDT
Sorry, I meant to respond to this literally a month ago. (A lot of stuff happened around the 4th and then I've been meaning to respond since.) I can help test the bug, although it would be helpful if someone could point me to documentation on how to set up SWT out of CVS, since I sort of faked my way through that when trying to create the original patch.
Comment 9 Kevin Barnes CLA 2007-08-08 09:15:47 EDT
There are instructions on how to run SWT from CVS on the website. http://www.eclipse.org/swt/cvs.php
Comment 10 Felipe Heidrich CLA 2007-11-08 14:15:43 EST
Daniel, do you think this problem is causing Bug 205648 ?
When you scroll at normal speed do you get the same problem they get ?
Comment 11 Felipe Heidrich CLA 2007-11-08 14:50:06 EST
Daniel, in http://www.microsoft.com/hardware/oempartners/ProductList.aspx?Type=Mouse
I found "IntelliMouse Explorer 4.0A", is that the mouse you have ?
Comment 12 Felipe Heidrich CLA 2007-11-09 15:52:15 EST
Fixed in HEAD > 20071109
Comment 13 Felipe Heidrich CLA 2007-12-11 18:03:39 EST
*** Bug 212642 has been marked as a duplicate of this bug. ***
Comment 14 Francois CLA 2008-01-15 18:40:14 EST
I had issues with my free-spin (otherwise called "smooth scroll", which is a very bad name considering the actual behavior) mouse (logitech MX revolution), and I suggest you re-consider this fix.

Basically this mousewheel isn't working at all with any of the implementation (tested 3.3 as well as 3.4M4, which includes this bug fix).

Bug detail:
- scrolling amount is a short (maximum 273 lines = SHORT_MAX/120)
- using free spin, a single scroll event can easily scroll more than 10 lines
- swt Scrollable implementation generates n LINEDOWN messages per scroll event
- eclipse java editor can't consume those events faster than Scrollable is generating them
- the result being:
 o eclipse uses full CPU when scrolling this mode
 o scrolling ends tens of seconds after you stop the wheel (because of the loop)
 o because the WM_MOUSEWHEEL isn't consumed fast enough, Win32/Logitech drivers generates less messages with even bigger values (hence making the situation even worse)
 o short overflow isn't handled in Win32/Logitech message generation, and when the SHORT_MAX is reach, the amount suddendly gets negative, making the scrolling the other way (as I said, highly unusable)

So one overflow bug in Win or Logitech side (didn't check further) who never thought the short limit could be reached with click-by-click mousewheels.

But more importantly, mousewheel message in SWT should be consumed in one go, and not changed to X LINE(UP/DOWN). That's fine for the usual 120/240 amounts you get with click-by-click devices, but don't count on it any longer (no standard Win32 application does).

I attached the working little patch I did for my 3.3.1.1 eclipse plaform for reference, but don't expect a lot from it (apart from being simple), as it's a dirty hack probably breaking a lot of other applications.

Some comments about this patch and logitech devices:
 - MX Revolutions base wheel amounts in free-spin are -80 for down and 180 for up (different probably because spinning the wheel downwards is easier)
 - those aren't exact values and they can differ with acceleration setup in logitech driver
 - the 9/4 ratio (180/80) that you see is a personnal touch because I don't like the difference between up/down amounts, and I wanted to hack a way around it (not configurable in logitech driver)
 - what my patch does is that I send only one LINEUP/LINEDOWN message, but when handling it in wmScroll(), I actually scroll by the required (dirtily saved) amount, and both skips the rounding to line number (could replace your "remaining" fix that I don't find so clean either) and the multiplication of messages
 - best solution to me would be to entirely avoid the LINEUP/DOWN messages and really implement the wmMouseWheel, but my Win32/SWT knowledge didn't allow me to do that

Result seems fully working (today was my first day of SWT, so I probably missed a lot of things, let me know), and I can finally scroll through pages and pages of java code.
(overflow bug from logitech remains but only if I set the acceleration at max value, and that's not really a useful setup anyway).

Thanks for reading, I'm available to validate any fix you might find to this problem.
Comment 15 Francois CLA 2008-01-15 18:41:30 EST
Created attachment 86994 [details]
Proof of concept patch for free-spin logitech mousewheels
Comment 16 Felipe Heidrich CLA 2008-01-16 11:35:27 EST
Francois, thanks for the comments and patch.
But you post them in the wrong bug. I've copied it to Bug 184063.