MacOS idle time in gtkidle.c
stephen.more at gmail.com
Thu Jun 28 13:51:20 EDT 2007
Thanks. That code is much simpler, but I am not getting the results I expected:
After 10 seconds of idletime, CGSSecondsSinceLastInputEvent is returning 2.
After 60 seconds of idletime, CGSSecondsSinceLastInputEvent is returning 13.
After 120 seconds of idletime, CGSSecondsSinceLastInputEvent is returning 28.
Is this normal ?
On 6/28/07, Evan Schoenberg <evan.s at dreskin.net> wrote:
> I created a dynamic library on Mac OS X ( 10.3.9 ) that displays the idle
> It is a subset of gtkidle.c
> # ifdef HAVE_IOKIT
> # else
> I will ssh into the Mac and execute this code, and it seems to respond
> back with a cached version of idle time. I execute it over and over
> again the the idle time does not change.
> The command "ioreg -c IOHIDSystem" seems to refresh the cache.
> I am not a Mac API expert...is there and API that can be called
> instead of adding this hack ?
> system( "ioreg -c IOHIDSystem > /dev/null" );
> From Adium:
> extern CFTimeInterval CGSSecondsSinceLastInputEvent(unsigned long evType);
> * @brief Returns the current machine idle time
> * Returns the current number of seconds the machine has been idle. The
> machine is idle when there are no input
> * events from the user (such as mouse movement or keyboard input) or when
> the screen saver is active.
> * In addition to this method, the status controller sends out notifications
> when the machine becomes idle,
> * stays idle, and returns to an active state.
> - (CFTimeInterval)currentMachineIdle
> CFTimeInterval idleTime;
> /* CGSSecondsSinceLastInputEvent is a private function available in 10.2
> and later. Note that
> * should work as of 10.4 but doesn't return a sensical value.
> idleTime = CGSSecondsSinceLastInputEvent(-1);
> /* On MDD Powermacs, the above function will return a large value when the
> machine is active (perhaps a -1?).
> * Here we check for that value and correctly return a 0 idle time.
> if (idleTime >= 18446744000.0) idleTime = 0.0; //18446744073.0 is the
> lowest I've seen on my MDD -ai
> return idleTime;
More information about the Devel