Hello,
Qemu uses SDL roughly this way:
while(!quit) {
select(a lot of fds, 30ms timeout);
while (SDL_PollEvent(&ev)) {
switch(ev.type) {
…
case SDL_MOUSEMOTION:
int dx, dy, state;
state = SDL_GetRelativeMouseState(&dx, &dy);
send_mouse_event(dx, dy, state);
}
}
}
And in my case, SDL is using X11, and hence what happens is:
select();
SDL_PollEvent()
-> X11_PumpEvents()
while(X11_Pending(SDL_Display))
X11_DispatchEvent()
-> SDL_PrivateMouseMotion()
SDL_DeltaX += Xrel;
X11_DispatchEvent()
-> SDL_PrivateMouseMotion()
SDL_DeltaX += Xrel;
X11_DispatchEvent()
-> SDL_PrivateMouseMotion()
SDL_DeltaX += Xrel;
SDL_PeepEvent()
send_mouse_event(dx, dy, state);
SDL_PollEvent()
-> X11_PumpEvents()
while(X11_Pending(SDL_Display)), but nothing left
SDL_PeepEvent()
SDL_GetRelativeMouseState();
send_mouse_event(0, 0, state);
SDL_PollEvent()
-> X11_PumpEvents()
while(X11_Pending(SDL_Display)), but nothing left
SDL_PeepEvent()
SDL_GetRelativeMouseState();
send_mouse_event(0, 0, state);
and back to select() again.
I.e. since select() has slept 30ms, 3 X11 mouse motion events were
pending and they are all processed in one go on the first call to
SDL_PollEvent(). In response to the first SDL event, the main loop hence
sends a mouse event which is the combination of the three X11 events,
and in response to the other SDL events, the main loop just sends
no-move events. The result is that the mouse doesn’t move so smoothly.
Could this be considered as a bug of SDL, or should qemu be fixed to
just use the values from the events instead of calling
SDL_GetRelativeMouseState?
Samuel
PS: There is also a missing feature in the events: the button events
don’t provide the current button status, so that you have to record it.