Пример #1
0
/*
  void IdleTimerAction (EventLoopTimerRef inTimer, void *inUserData, EventIdleAction inAction );
*/
SEXP
R_carbonInstallIdle(R_IdleFunc f, void *userData)
{
  EventLoopRef loop = GetCurrentEventLoop();
  EventTimerInterval delay, time;
  EventLoopTimerUPP proc;
  EventLoopTimerRef out;
  OSSStatus status;

  delay = 0;
  time = 0;

/* 
  This is not quite what we want. It will not detect other events such as input onf
  streams, etc. 
  And it is only available on OS X 10.2.
*/
  status = InstallEventLoopIdleTimer(loop, delay, time, proc, userData, &out);
  if(status != noErr) {
   PROBLEM "Can't register idle task"
   ERROR;
  }

  return(createRCarbonTimer(out));
}
Пример #2
0
void Shell::EventLoop(ShellIdleFunction idle_function)
{
	OSStatus error;
	error = InstallApplicationEventHandler(NewEventHandlerUPP(InputMacOSX::EventHandler),
										   GetEventTypeCount(INPUT_EVENTS),
										   INPUT_EVENTS,
										   NULL,
										   NULL);
	if (error != noErr)
		DisplayError("Unable to install handler for input events, error: %d.", error);

	error = InstallWindowEventHandler(window,
									  NewEventHandlerUPP(EventHandler),
									  GetEventTypeCount(WINDOW_EVENTS),
									  WINDOW_EVENTS,
									  NULL,
									  NULL);
	if (error != noErr)
		DisplayError("Unable to install handler for window events, error: %d.", error);

	EventLoopTimerRef timer;
	error = InstallEventLoopIdleTimer(GetMainEventLoop(),							// inEventLoop
									  0,											// inFireDelay
									  5 * kEventDurationMillisecond,				// inInterval (200 Hz)
									  NewEventLoopIdleTimerUPP(IdleTimerCallback),	// inTimerProc
									  (void*) idle_function,						// inTimerData,
									  &timer										// outTimer
									  );
	if (error != noErr)
		DisplayError("Unable to install Carbon event loop timer, error: %d.", error);

	RunApplicationEventLoop();
}