SDL_PollEvent() and GetRelativeMouseState()

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.

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?

Yes, SDL_GetRelativeMouseState() only returns the current state for the
frame. If you want each event that gets you there, you should process
the events.

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.

You can’t query it with SDL_GetMouseState()?

We can certainly add it to the event, for SDL 1.3 if you want.
http://bugzilla.libsdl.org/

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam Lantinga, le Tue 26 Feb 2008 04:17:34 -0800, a ?crit :

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?

Yes, SDL_GetRelativeMouseState() only returns the current state for the
frame. If you want each event that gets you there, you should process
the events.

Ok.

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.

You can’t query it with SDL_GetMouseState()?

Yes, but again, that will give me the current button status, not the
button status corresponding to the event.

We can certainly add it to the event, for SDL 1.3 if you want.
http://bugzilla.libsdl.org/

Samuel