Quick question.... when does the IdleEvent fire? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
jmason1182
Earned some good credits
Earned some good credits
Posts: 149
Joined: Fri Dec 14, 2007 3:40 pm
Location: Midland, TX
Contact:

Quick question.... when does the IdleEvent fire?

Post by jmason1182 » Tue Sep 23, 2008 9:02 pm

I am building an application that needs a user to login in order to use the system. BUT I need it to auto-lock if the user walks away from the terminal.

I know of plenty of ways to do this, but am open to suggestions.

First off, if i use the IdleEvent to start a timer to disable the interface, I need to know when the IdleEvent fires. If, say, on windows, the IdleEvent fires when the screensaver kicks in, then it is pointless because the total time from the user walking away to it disabling would be the time for the screensaver PLUS whatever my timer is.

So, when does the IdleEvent fire? How could I interrupt the timer if it was started during the IdleEvent? (is there a WakeEvent?) And more importantly, what would you do to basically make a "screensaver" for JUST your application?
John A. Mason
Midland, TX

jmason1182
Earned some good credits
Earned some good credits
Posts: 149
Joined: Fri Dec 14, 2007 3:40 pm
Location: Midland, TX
Contact:

Post by jmason1182 » Tue Sep 23, 2008 9:08 pm

I just found this in some mailing list:
Kevin Altis wrote:

>AFAIK, it isn't a "true idle" where the event fires when your app isn't
>doing anything. Instead, idle fires when the event queue empties. That means
>you'll get an idle after a mouse move event, which I find annoying since it
>means that my idle handler definitely needs some kind of flag and check for
>the last time it ran so that whatever I really wanted to doesn't eat up all
>the CPU by running a lot.
>
>Anyway, what you'll need to do is use an event timer instead. Or you can
>bind a timer that guarantees idle fires say once a second, but again it
>isn't a true idle. Hmm, maybe idle should be renamed to EventQueueEmpty?
>
>ka
So apparently the IdleEvent is NOT what I need. So what could work better?
John A. Mason
Midland, TX

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Wed Sep 24, 2008 7:24 am

wxTimerEvent is what you need. Use a wxTimer, check every second / minute if the user didn't perform any mouse movement / keystroke and then lock the screen. You should also catch EVT_MOUSE and simply update the last time (wxDateTime) that an event occured. Then don't event.Skip() the event handler to le wxWidgets call other handlers for that event. Same goes for the keystroke events.

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

rkubrick
Earned a small fee
Earned a small fee
Posts: 17
Joined: Sat Aug 30, 2008 12:29 am

Post by rkubrick » Wed Sep 24, 2008 11:59 am

Jorg wrote:wxTimerEvent is what you need. Use a wxTimer, check every second / minute if the user didn't perform any mouse movement / keystroke and then lock the screen. You should also catch EVT_MOUSE and simply update the last time (wxDateTime) that an event occured. Then don't event.Skip() the event handler to le wxWidgets call other handlers for that event. Same goes for the keystroke events.

Regards,
- Jorgen
Definitely idleProc is not designed for this kind of work. Look for EVT_MOUSE_EVENTS(), EVT_CHAR() and EVT_KEY_DOWN() to handle keyboard events.

jmason1182
Earned some good credits
Earned some good credits
Posts: 149
Joined: Fri Dec 14, 2007 3:40 pm
Location: Midland, TX
Contact:

Post by jmason1182 » Wed Sep 24, 2008 2:05 pm

I've accepted the answer, but I would like some more clarification.

If I use EVT_KEY_DOWN() do I need EVT_CHAR()? Having done a lot of javascript not too long ago for our company website, I am now a little confused as to the purpose of EVT_KEY_DOWN, EVT_KEY_UP and EVT_CHAR.... because that project just needed key_up and key_down to keep track of it all.
John A. Mason
Midland, TX

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Thu Sep 25, 2008 11:48 am

No, you won't need the EVT_CHAR.

For the original purpose of this topic, I would like to share an experience:

Once I put the updating work of a wxGauge in the idle event handling function, like this:

myGuage->Update(myGuage->Value()+a_delta);

or

myGuage->Pulse();

I found that the faster I move my mouse, the faster the progress of the guage grows. It's interesting. I guess the conclusion is that the idle event will be fired everytime the event queue is emptied.

Regards,

Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

jmason1182
Earned some good credits
Earned some good credits
Posts: 149
Joined: Fri Dec 14, 2007 3:40 pm
Location: Midland, TX
Contact:

Post by jmason1182 » Fri Sep 26, 2008 4:19 pm

A quick note: DON'T USE THE IDLE EVENTS UNLESS YOU ARE SURE YOU NEED TO. MY APP BROKE BECAUSE OF 1 STATEMENT...

Code: Select all

wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); 
See I use lots of the wxTreeListCtrl (enhanced version from twinforms.com) and they require idle events to refresh the display.... but I didn't know that until it broke.

After three days of figuring it out I am allowed to make a general statement... IDLE EVENTS SHOULD ONLY BE USED IF YOU ARE CERTAIN YOU NEED THEM. These really should not be called Idle events anyway... they are EventQueueEmpty events. In any case, be sure to save a backup before and after you try to use Idle Events. That way if anything breaks, you can start adding wxWS_EX_PROCESS_IDLE to any windows that need it. In my case, that was EVERY window.

Hope this helps SOMEONE... probably won't though.

... Oh yeah.And I fixed my app by removing the SetMode line above... I didn't need the IdleEvents and didn't want to go through all my windows to put the wxWS_EX_PROCESS_IDLE flag for each so they would get the idle event. [/b]
John A. Mason
Midland, TX

Post Reply