This would benefit from a split between xinput 2.1 request (as attached for example) and the original raw-input related patch.
Also, I believe you can completely replace the existing code with you raw input version, and remove all the "extra" level used for cursor clipping.
This also means that the "Don't react to small slow mouse movements." patch may now be obsolete as the raw values will directly be passed to the server.
As a related note, also for the next patch in the serie, AFAICS Windows raw values for X/Y movements are the same between Windows and XInput2, but I see a 8x scaling factor for the mouse wheel values that may be missing.