You are not logged in.

#1 2011-06-27 09:25:26

jelari
Member
Registered: 2011-06-27
Posts: 1

Would like to invoke my App while idle.

Hey guys,
I need my application get invoked while my linux box is idle, as in invoking screen saver ?. 
What is the logic to figure out the system idle.  Any clue much appreciated!!!.

Thanks.

Offline

#2 2011-06-27 09:59:07

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Would like to invoke my App while idle.

'ionice -c3' is one way of doing it although the screensaver does it another way: http://www.shallowsky.com/linux/x-screen-blanking.html

Last edited by karol (2011-06-27 10:00:30)

Offline

#3 2011-06-27 14:48:12

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: Would like to invoke my App while idle.

If you're using XScreenSaver, you can use "xscreensaver-command -time" to figure out if the screen is blanked or not.

Offline

#4 2011-06-27 15:12:30

Guff
Member
Registered: 2009-09-30
Posts: 158
Website

Re: Would like to invoke my App while idle.

You can make use of X11's screensaver extension to get a system's idle time:

(taken from the code for sinac)

#include <X11/extensions/scrnsaver.h>

static XScreenSaverInfo* xss_info = NULL; 

int 
seconds_idle(Display *d)
{
  if (! xss_info ) 
    xss_info = XScreenSaverAllocInfo();
  XScreenSaverQueryInfo(d, DefaultRootWindow(d), xss_info);
  return xss_info->idle / 1000;

}

Of course, that only gives you the duration of the idle time. To do something after a specified timeout of x seconds, you could make use of a loop that checks the time spent idle, then sleeps for (x - seconds_idle(d)) seconds. On the next iteration of the loop, if the system has been idle long enough, whatever action you want to do can be triggered.

I don't know what you're coding this in, though.

Offline

Board footer

Powered by FluxBB