Hi,
I dont’t understand how there can be more than one event when I use
SDL_PollEvent(&event) to handle each single event. And if there are more
than one, how do I know which one of them is gained or lost?
As I said, checkout the ‘testwm.c’ example program:
http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/test/testwm.c
and choose download. Look for the function FilterEvents().
Figure out how to compile it and see what it does. If you are using windows,
you need to make it a console app so you can see the messages when the mouse
moves over the app window etc.
Hmmm.
I still need to check out the SDL source to get to the bottom of this. But
this is an open-source project so that’s not a problem - hurray!
This kind of thing is reminiscent of my early Win3.1 days when the
documentation was rubbish and the actual sequence of window messages was
obscure but of vital importance when releasing data structures (objects). All
that time and stress I could have avoided by being able to quickly scan the
source ...
Ok. The code is (potentially) platform dependent and revolves around calls to
SDL_PrivateAppActive() (a private internal-use-only type deal).
The following ‘events’ can occur:
SDL_APPACTIVE, gain 0/1
SDL_APPINPUTFOCUS, gain 0/1
SDL_APPMOUSEFOCUS, gain 0/1
SDL_APPACTIVE|SDL_APPINPUTFOCUS, gain 0 only
So there you go: an SDL application can instantaneously lose input focus and
its active status, and the two events get ‘packed’ into one.
If there’s anything I’ve missed here you know what to do …
cheers,
John.>
From: John Popplewell <@John_Popplewell>
Organization: John Popplewell
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_APPACTIVE
Date: Wed, 29 Oct 2003 00:12:00 +0000
Reply-To: sdl at libsdl.org
Hi,
the docs are a bit vague here, but I believe event.active.state can be a
bitwise-OR of the three flags SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS and
SDL_APPACTIVE (check their values in ‘SDL_active.h’). This means that
these
events can happen simultaneously.
You need to change your tests to:
if (event.active.state & SDL_APPMOUSEFOCUS)
etc.
if (event.active.state & SDL_APPINPUTFOCUS)
etc.
if (event.active.state & SDL_APPACTIVE)
etc.
to deal with this possibility. Check out the example code 'testwm.c’
that is
distributed with the SDL source,
cheers,
John.
I’m trying to take care of a SDL_APPACTIVE event as this code
demonstrates. But the SDL_APPACTIVE event never happens. I’ve tried
using SDL_GetActiveState with success so don’t give me such a
solution.
Well, here is my code:
bool loop = true;
SDL_Event event;
while (loop) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_ACTIVEEVENT) {
if (event.active.state == SDL_APPMOUSEFOCUS)
std::cout << “MOUSEFOCUS” << std::endl;
if (event.active.state == SDL_APPINPUTFOCUS)
std::cout << “INPUTFOCUS” << std::endl;
if (event.active.state == SDL_APPACTIVE)
std::cout << “ACTIVE” << std::endl;
if (event.active.gain)
std::cout << " - Gained" << std::endl;
else
std::cout << " - Lost" << std::endl;
}
}
if (event.type == SDL_QUIT)
loop = false;
}
You will see that an event is produced, gained or lost, but it will
not
be identified as SDL_APPACTIVE.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl