cocoa: restoring windows order after reactivating the application #34630

git-svn-id: trunk@61397 -
This commit is contained in:
dmitry 2019-06-14 23:49:27 +00:00
parent b2b15a813e
commit 6f8ac4d6a1
2 changed files with 62 additions and 1 deletions

View File

@ -51,10 +51,26 @@ type
class function newWithFunc(afunc: TWSTimerProc): TCocoaTimerObject; message 'newWithFunc:';
end;
{ TAppDelegate }
TWinLevelOrder = record
win : NSWindow;
lvl : NSInteger;
ord : NSinteger;
vis : Boolean;
end;
PWinLevelOrder = ^TWinLevelOrder;
TWinLevelOrderArray = array [Word] of TWinLevelOrder;
PWinLevelOrderArray = ^TWinLevelOrderArray;
TAppDelegate = objcclass(NSObject, NSApplicationDelegateProtocol)
public
orderArray : PWinLevelOrderArray;
orderArrayCount : Integer;
procedure application_openFiles(sender: NSApplication; filenames: NSArray);
procedure applicationDidHide(notification: NSNotification);
procedure applicationDidUnhide(notification: NSNotification);
procedure applicationWillBecomeActive(notification: NSNotification);
procedure applicationDidBecomeActive(notification: NSNotification);
procedure applicationDidResignActive(notification: NSNotification);
procedure applicationDidChangeScreenParameters(notification: NSNotification);

View File

@ -517,8 +517,53 @@ begin
Application.IntfAppRestore;
end;
procedure TAppDelegate.applicationDidBecomeActive(notification: NSNotification);
procedure TAppDelegate.applicationWillBecomeActive(notification: NSNotification
);
var
app : NSApplication;
i: integer;
vis: Boolean;
info: PWinLevelOrder;
ord: NSArray;
begin
app := NSApplication(NSApp);
ord := app.orderedWindows;
orderArrayCount := ord.count;
orderArray := GetMem(orderArrayCount * sizeof(TWinLevelOrder));
for i := 0 to orderArrayCount - 1 do
begin
info := @orderArray^[i];
info^.win := ord.objectAtIndex(i);
info^.lvl := info^.win.level;
info^.ord := info^.win.orderedIndex;
info^.vis := info^.win.isVisible;
end;
end;
procedure TAppDelegate.applicationDidBecomeActive(notification: NSNotification);
var
i : integer;
begin
// Cocoa changes level and order of windows to it's liking
// (it happens between Will- and DidBecomeActive)
// for example Model windows becoming level 8,
// even if LCL set them to level 0 before.
// As a result the OrderedIndex also goes messed up.
// It's being restored here
for i := orderArrayCount -1 downto 0 do
begin
if not orderArray^[i].vis then continue;
orderArray^[i].win.setLevel( orderArray^[i].lvl );
orderArray^[i].win.setOrderedIndex( orderArray^[i].ord );
orderArray^[i].win.orderFrontRegardless;
end;
orderArrayCount := 0;
if orderArray <> nil then
begin
Freemem(orderArray);
orderArray := nil;
end;
Application.IntfAppActivate;
end;