Here’s a enjoyable one I simply mounted…
In an software the place I can click on and drag the mouse to rotate a 3D digicam, I used to be noticing that each infrequently, beginning a drag would trigger a sudden leap within the digicam’s rotation, far more than it ought to have been from the quantity that I used to be transferring the mouse. Some experimentation revealed that I might make it occur extra usually if I used to be already transferring the mouse earlier than I pressed the button, although nonetheless solely round 10% of the time. This was occurring each on Windows and Linux.
I had a hunch that this had one thing to do with setting mouse delta mode from a mouse down occasion. Since that is for 3D rotation, I need to have the ability to proceed dragging infinitely in a single path with out immediately being unable to maneuver additional because of the mouse cursor hitting a display screen edge, so when a drag gesture begins, I activate a mode that processes mouse occasions in another way and returns movement deltas with out really transferring the cursor. My present implementation of this on the 2 platforms the place the issue happens is a bit of bit janky – I conceal the mouse cursor, warp the pointer location to the middle of the window, then subtract the cursor place from the window heart on each transfer occasion and warp it to the middle once more.
One factor this necessitates is to disregard the massive delta of movement that is registered from the warp itself – in any other case, the massive leap would occur each time mouse delta mode was activated or deactivated, relying on how shut the cursor had been to the window heart. My dealing with for this was to set an express display screen location to disregard from an upcoming mouse occasion, in order that when the movement occasion that was brought on by warping the cursor got here into the occasion queue, I’d simply discard it. This did appear to work more often than not, so why was I nonetheless getting massive deltas each infrequently?
I managed to verify my hunch that the massive deltas have been coming from movement occasions that have been already within the occasion queue earlier than the cursor was warped, so when processing occasions so as, the place I used to be awaiting to discard the occasion did not are available in till after I’d processed one with a special place. Since there’s some variance in timing between when the working system inserts mouse occasions into the occasion queue and when my run loop empties it, it could hardly ever have already inserted a non-delta-mode movement occasion into the queue after the mouse down occasion the place I used to be activating delta mode.
The repair was only a small adjustment to when and the way I discard occasions generated by pointer warping, nevertheless it was a little bit of an journey to get there. It additionally made me notice that there are another points with this method – if I activate delta mode on a window whose heart is offscreen, pointer warping does not work in any respect since I’m attempting to warp to an offscreen location. A small window near the display screen edge will get a lowered vary of movement within the path of the sting, because the invisible cursor will hit it and be stopped. I ought to in all probability discover a extra direct technique to measure mouse deltas than with pointer warping, however possibly I might do a band-aid repair by warping to the middle of the display screen as an alternative of the middle of the window…