-
Notifications
You must be signed in to change notification settings - Fork 27
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
Normalizing MouseWheel in different browsers/platforms #10
Comments
Thanks for reporting this!
I completely agree that
I'll look into that and think about it. Off the top of my head, I can't confirm if that value makes the most sense. Edit: I've realized we have glfw itself on desktop to follow, so we'll normalize on whatever value it provides on desktop.
Thanks for listing these. I like 3 the most. That file seems to have great information, assuming as it's decently up to date. Even if not, we can still use it as a great starting point and update any issues as people report them. I think it would make a lot of sense to port that JS code into a small Go package, and then import it in For information, I primarily used macOS and Chrome during development, so
Can you file another issue that's specific to that problem, and include full details (OS, browser, etc.). Let's continue to use this issue for the high level discussion of the problem. |
By the way, I have the following small test program for testing scroll events in the browser: https://dmitri.shuralyov.com/projects/touch/scroll.html Then there's glfw events test application: https://godoc.org/github.com/goxjs/glfw/test/events That can be used to compare scroll events on desktop and in browser. The browser version (might be out of date though) is up at: https://dmitri.shuralyov.com/projects/glfw-events/ (see console for output) |
Thanks for the helper utilities. I translated the js function and put it in https://github.com/Omustardo/wheel In doing the translation, I made a one logic change in the code, and one restructure to fit with Golang requirements.
I did this because we can't support I also needed to modify goxjs/glfw/browser.go's wheel handler locally in order to apply the change:
I can submit a PR with that if everything looks good. I also attempted unit tests, but haven't yet figured out how to avoid panics when using a js.Object's Get function. |
I did a bit more manual testing, and I think either I did something very wrong, or the facebook solution doesn't work in all common cases. Testing on windows 10 + chrome on my laptop resulted in a delta value of 150, which normalized to 1.25. I'm more and more convinced that simply checking the sign and returning -1, 0, or 1 is the most effective. The downside would be:
On the other hand, it's likely the most future proof solution since it doesn't look at any javascript object fields and doesn't try to be "smart" about it. |
Doing that should be absolutely fine in this case, since it's needed.
I don't think that would be acceptable. I want to preserve smooth, high-precision scrolling with momentum, which currently works fine on macOS.
Would you mind doing that? |
Done. The code still doesn't handle all situations but at least it follows the existing code more closely. I haven't yet found any better way to deal with all of these different environments.
Yea. That's another situation that it definitely wouldn't work for.
Done. |
Related discussions and solutions: http://stackoverflow.com/a/11738705/3184079 jquery/jquery-mousewheel#36 https://github.com/monospaced/hamster.js https://groups.google.com/forum/#!topic/gwt-forplay/1_JqN9EXCvg darsain/sly#67 https://github.com/cubiq/iscroll/blob/master/src/wheel/wheel.js#L16 |
Thanks for providing those references. From looking over that, I'm starting to see that the situation is a hot mess, and it's likely some different browsers on different OSes report different values. I've done some testing on macOS, using I've asked for more specific information about the issue you ran into in #11. Let's avoid trying to do too much too quickly, and focus on resolving a specific reproducible issue first. |
The 0.1 minimum value for trackpad input on the desktop is likely due to the change a few years ago which specifically affects MacOS inputs: Here's another little info dump:
Here are the bug trackers for implementing |
At this point I don't think there's any "good" way to solve this issue. There are just too many settings and inputs that the browser "simplifies" for us - leaving us with too little information to get back to the original OS event. One example is the number of lines scrolled per mouse step. Now if you change your OS to scroll one line per mouse step: The problem is that we have no way of detecting what the OS level scroll settings are, much less dealing with how each browser interprets them. That leaves bad solutions - the effective of which I can think of at this point is to keep track of the minimum value seen so far, assume that it is the base delta value, and use it to normalize other deltas.
In general I'm surprised by the lack of existing solutions for this issue. It seems like a common problem - in particular for existing cross-browser projects. Maybe I'm just searching for the wrong things, but all of the solutions seem to be very incorrect - dividing wheelDelta's by 120 in Chrome, etc. Edit: I realized that this solution doesn't maintain the behavior seen with |
Hehe, I wonder if you noticed, I'm the author of that PR. :)
Thanks for those, good to have for reference.
I've done some investigation for #11 and I'm arriving at a similar conclusion. I personally feel the best thing to do is wait and let the browsers sort out their inconsistencies. Given most (all?) browsers today are evergreen, meaning they forcibly-auto-update on regular intervals, it seems plausible that the situation will improve over time. Also, given that many browsers are open source, it may be a wiser investment of time to try to fix problems at the root, in the browsers, than to try to apply hacks at a higher application layer. Let me ask what's your stance on this, since you're quite active on this issue. Is resolving this and #11 a curiosity for you, and are you looking for a good, simple, general end solution? Or are you motivated to resolve #11 in a shorter time frame because of a critical business need, i.e., the inconsistency is blocking you from making progress on a project? That'd be helpful for me to know. |
Yea, although to be fair, you've contributed to nearly every github repo I visit so it wasn't much of a surprise :P
I agree we should wait for browsers to converge on standards. The only solutions we can do by looking at
Answered in #11 Thanks for being so responsive on this issue. I'm glad to have gone through the effort to do it right, even if a fix isn't currently feasible. |
This mostly accounts for different behavior of mouse scroll wheels on different systems / hardware. See goxjs/glfw#10 for more detail and why this is not feasible to fix in a nice way.
are you aware of this neat little piece of work: https://github.com/d4nyll/lethargy ? |
Thanks for sharing @krisj. I did not know about it. I tried it just now, and the demo did not work at all reliably for me. In fact, it worked very poorly and did not detect many valid scroll events I made. From https://github.com/d4nyll/lethargy#how-does-it-work:
It's just an approximation that tries to work out whether a scroll event is inertial or not. That's not even a problem we care about solving for our issue. So, this doesn't change our status, which is that we're not doing much aside waiting for browsers to sort out this mess, and/or contributing there ourselves. |
Related web spec issue: |
This issue is to discuss the difference, and possible reconciliation, between mouse scrolling on different platforms and browsers.
Relevant code: https://github.com/goxjs/glfw/blob/master/browser.go#L234
When run on desktop, the scroll wheel has a delta of 1 per tick in my experience. When run in the browser I experience a delta of 10 per tick. It seems that the tick value also varies by browser according to:
http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers
Looking into it further, it appears my browser actually uses 120 per tick. http://phrogz.net/js/wheeldelta.html
Given the ideal of a single piece of code being able to run in the same fashion on both desktop and canvas, I suggest scroll wheel ticks be normalized to a delta of 1 per tick.
Possible solutions:
In the stack overflow link above, the top suggestion of simplifying the delta to -1, 0, or 1 seems reasonable at a glance, but based on comments it seems there are issues with different hardware like track pads that also uses the wheel event. It would also limit extremely fast scrolling to one tick per callback. I tested how often this might occur by spinning my mouse wheel as fast as I could manage while recording events in the chrome dev console. The most concentrated snippet of multiple events was:
14 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
35 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
39 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
6 syscall.go:43 http:0: got scroll event: 0 -10
syscall.go:43 http:0: got scroll event: 0 -20
32 syscall.go:43 http:0: got scroll event: 0 -10
The number of events with multiple mouse wheel ticks in a single callback is relatively small. It isn't negligible though.
Per browser support. Infeasible unless there's list that can be automatically kept up to date and imported statically.
http://stackoverflow.com/a/30134826/3184079
Facebook published a solution licensed under BSD-3. Many of the stackoverflow comments recommend it, and it could be translated to Go without difficulty.
https://github.com/facebook/fixed-data-table/blob/master/src/vendor_upstream/dom/normalizeWheel.js
Keep track of the smallest delta seen, and divide all others by its absolute value. Simple, but I don't know if it works in all cases.
I'm going to sleep on this and give it more thought.
The text was updated successfully, but these errors were encountered: