A pain point with this code is how the Lisp-side mwheel code assumes that the wheel event will always be mouse-4 to 8 under X, so the code tries to emulate the legacy Core Input behaviour instead of generating WHEEL_EVENTs. To properly support XInput 2 scrolling, mwheel.el will have to be modified to support using both kinds of events under the same session.