We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 933

Summary: Two SDL_ACTIVEEVENT SDL_APPMOUSEFOCUS events precede each SDL_MOUSEBUTTONDOWN
Product: SDL Reporter: Kalle Olavi Niemitalo <kon>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 1.2.14   
Hardware: x86_64   
OS: Linux   
URL: https://savannah.nongnu.org/bugs/index.php?27982
Attachments: event trace with xtrace --relative-timestamps and Bos Wars patched to display SDL events

Description Kalle Olavi Niemitalo 2010-01-17 07:37:10 UTC
Bos Wars 2.5.1 in windowed mode seems to be getting too many SDL_ACTIVEEVENT events from SDL 1.2.14.  There is no such problem with SDL 1.2.14 in full-screen mode, nor with SDL 1.2.13.  Reverting SDL r4872 solves the problem.  That change was intended to fix SDL bug #716.

Before each SDL_MOUSEBUTTONDOWN event, SDL is reporting two SDL_ACTIVEEVENT events:

1. type=SDL_ACTIVEEVENT, gain=0, state=SDL_APPMOUSEFOCUS
2. type=SDL_ACTIVEEVENT, gain=1, state=SDL_APPMOUSEFOCUS

xtrace shows the X server is reporting EnterNotify and LeaveNotify events, which also look spurious; so perhaps the problem is at a lower level than SDL.  Anyway, upgrading SDL from 1.2.13 to 1.2.14 (the "last planned release for SDL 1.2") seems harmful to Bos Wars.
Comment 1 Kalle Olavi Niemitalo 2010-01-17 08:25:40 UTC
Created attachment 479 [details]
event trace with xtrace --relative-timestamps and Bos Wars patched to display SDL events
Comment 2 Kalle Olavi Niemitalo 2010-01-17 09:32:51 UTC
It seems this is caused by the Metacity 2.28.0 window manager grabbing mouse events.  Metacity then calls XAllowEvents with ReplayPointer, letting the event through to SDL in Bos Wars; but the grab has already caused the X server to report LeaveNotify and EnterNotify, which then cause SDL to report to Bos Wars that it lost and regained the mouse focus.  The Openbox 3.4.10 window manager causes the same problem; IceWm 1.3.6 however doesn't.

Because the LeaveNotify events received by SDL do indicate that the application isn't going to receive mouse events, I suppose SDL is right to report loss of mouse focus to the application.  The EnterNotify then soon follows but I suppose that can be arbitrarily delayed, in particular if the window manager is not running on the same host as the X server.  (In which case, the mouse events to the application will also be delayed, so having a window manager grab the mouse like that seems a bad idea.)  So I don't how to change SDL not to report those events while remaining correct.  I'm thus resolving my own bug report as INVALID.
Comment 3 Sam Lantinga 2010-01-18 06:23:55 UTC
Thanks for the info!