MacOS idle time in gtkidle.c

Evan Schoenberg evan.s at dreskin.net
Thu Jun 28 12:53:16 EDT 2007


On Jun 28, 2007, at 12:48 PM, Stephen More wrote:

> I created a dynamic library on Mac OS X ( 10.3.9 ) that displays  
> the idle time.
> 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 CGEventSourceSecondsSinceLastEventType()
	 * 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;
}


-Evan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pidgin.im/pipermail/devel/attachments/20070628/c14e2b98/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://pidgin.im/pipermail/devel/attachments/20070628/c14e2b98/attachment.sig>


More information about the Devel mailing list