Skip to content

Normalizing MouseWheel in different browsers/platforms #10

@Omustardo

Description

@Omustardo

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:

  1. 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.

  2. Per browser support. Infeasible unless there's list that can be automatically kept up to date and imported statically.

  3. 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

  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions