cocoa: changing the way application object goes into a loop and being initialized. fixes KVO exception for macOS10.15. Based on patch by David Jenkins. (original patch suggests removal of the existing code, the change introduces COCOALOOPOVERRIDE switch). #35702

git-svn-id: trunk@61354 -
This commit is contained in:
dmitry 2019-06-11 12:53:37 +00:00
parent deb2cde704
commit 7f6412df7e
3 changed files with 23 additions and 0 deletions

View File

@ -14,3 +14,10 @@
{$define BOOLFIX}
// Originally LCL-Cocoa would override "run" method and have direct control
// over the event loop. However that presumed to cause issues in macOS 10.15
// The code was changed not to override "run" loop, but instead override
// the first request to process an event, and run LCL loop from there.
// Such approach is some what an ugly solution, yet it's reliable, in a sense
// that Cocoa performs ALL of this methods.
{.$define COCOALOOPOVERRIDE}

View File

@ -70,8 +70,10 @@ type
modals : NSMutableDictionary;
procedure dealloc; override;
{$ifdef COCOALOOPOVERRIDE}
function isRunning: LCLObjCBoolean; override;
procedure run; override;
{$endif}
procedure sendEvent(theEvent: NSEvent); override;
function nextEventMatchingMask_untilDate_inMode_dequeue(mask: NSUInteger; expiration: NSDate; mode: NSString; deqFlag: LCLObjCBoolean): NSEvent; override;
@ -397,6 +399,7 @@ begin
inherited dealloc;
end;
{$ifdef COCOALOOPOVERRIDE}
function TCocoaApplication.isRunning: LCLObjCBoolean;
begin
Result:=isrun;
@ -407,6 +410,7 @@ begin
isrun:=true;
aloop();
end;
{$endif}
procedure ForwardMouseMove(app: NSApplication; theEvent: NSEvent);
var
@ -503,6 +507,16 @@ function TCocoaApplication.nextEventMatchingMask_untilDate_inMode_dequeue(
var
cb : ICommonCallback;
begin
{$ifndef COCOALOOPOVERRIDE}
if not isrun then begin
isrun := True;
Result := nil;
aloop();
terminate(nil);
exit;
end;
{$endif}
{$ifdef BOOLFIX}
Result:=inherited nextEventMatchingMask_untilDate_inMode_dequeue_(
mask,

View File

@ -67,7 +67,9 @@ end;
------------------------------------------------------------------------------}
procedure TCocoaWidgetSet.AppRun(const ALoop: TApplicationMainLoop);
begin
{$ifndef COCOALOOPOVERRIDE}
NSApp.finishLaunching;
{$endif}
if Assigned(ALoop) then
begin
TCocoaApplication(NSApp).aloop:=ALoop;