mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-01 19:52:35 +02:00
cocoa: restoring windows order after reactivating the application #34630
git-svn-id: trunk@61397 -
This commit is contained in:
parent
b2b15a813e
commit
6f8ac4d6a1
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user