cocoa: add Idle observer, notify application when cocoa enters Idle state

git-svn-id: trunk@38944 -
This commit is contained in:
paul 2012-10-02 03:47:58 +00:00
parent c639b7f82f
commit 983bc213aa
2 changed files with 15 additions and 1 deletions

View File

@ -42,7 +42,7 @@ uses
CocoaProc,
// LCL
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
Controls,
Controls, Forms,
IntfGraphics, Graphics, CocoaWSFactory;
type

View File

@ -43,16 +43,30 @@ begin
FNSApp.setDelegate(delegate);
end;
type
CFRunLoopObserverContextRef = ^CFRunLoopObserverContext;
function CFRunLoopObserverCreate(allocator: CFAllocatorRef; activities: CFOptionFlags; repeats: Boolean; order: CFIndex; callout: CFRunLoopObserverCallBack; context: CFRunLoopObserverContextRef): CFRunLoopObserverRef; mwpascal; external name '_CFRunLoopObserverCreate';
procedure RunLoopObserverCallback(observer: CFRunLoopObserverRef; activity: CFRunLoopActivity; info: UnivPtr); mwpascal;
begin
if activity = kCFRunLoopBeforeWaiting then
Application.Idle(False);
end;
{------------------------------------------------------------------------------
Method: TCocoaWidgetSet.AppRun
Params: ALoop
------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppRun(const ALoop: TApplicationMainLoop);
var
Observer: CFRunLoopObserverRef;
begin
{$IFDEF VerboseObject}
DebugLn('TCocoaWidgetSet.AppRun');
{$ENDIF}
Observer := CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, True, 0, @RunLoopObserverCallBack, nil);
CFRunLoopAddObserver(CFRunLoopGetCurrent, Observer, kCFRunLoopCommonModes);
{ Enters main message loop }
NSApp.run;
end;