mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 11:19:26 +02:00
Cocoa: Fix #40569: Merge branch 'cocoa/ontop', fsStayOnTop improved
This commit is contained in:
commit
f35f68c5b6
@ -70,8 +70,8 @@ type
|
||||
procedure application_openFiles(sender: NSApplication; filenames: NSArray);
|
||||
procedure applicationDidHide(notification: NSNotification);
|
||||
procedure applicationDidUnhide(notification: NSNotification);
|
||||
procedure applicationWillBecomeActive(notification: NSNotification);
|
||||
procedure applicationDidBecomeActive(notification: NSNotification);
|
||||
procedure applicationWillResignActive(notification: NSNotification);
|
||||
procedure applicationDidResignActive(notification: NSNotification);
|
||||
procedure applicationDidChangeScreenParameters(notification: NSNotification);
|
||||
procedure applicationWillFinishLaunching(notification: NSNotification);
|
||||
|
@ -599,49 +599,23 @@ begin
|
||||
Application.IntfAppRestore;
|
||||
end;
|
||||
|
||||
procedure TAppDelegate.applicationWillBecomeActive(notification: NSNotification
|
||||
);
|
||||
{$ifdef COCOA_ACTIVATION_REORDER}
|
||||
var
|
||||
app : NSApplication;
|
||||
i: integer;
|
||||
vis: Boolean;
|
||||
info: PWinLevelOrder;
|
||||
ord: NSArray;
|
||||
{$endif}
|
||||
begin
|
||||
{$ifdef COCOA_ACTIVATION_REORDER}
|
||||
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;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure TAppDelegate.applicationDidBecomeActive(notification: NSNotification);
|
||||
var
|
||||
i : integer;
|
||||
begin
|
||||
{$ifdef COCOA_ACTIVATION_REORDER}
|
||||
// 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
|
||||
for i := orderArrayCount-1 downto 0 do
|
||||
begin
|
||||
if not orderArray^[i].vis then continue;
|
||||
if not orderArray^[i].vis then
|
||||
continue;
|
||||
if orderArray^[i].lvl=NSNormalWindowLevel then
|
||||
continue;
|
||||
orderArray^[i].win.setLevel( orderArray^[i].lvl );
|
||||
orderArray^[i].win.setOrderedIndex( orderArray^[i].ord );
|
||||
orderArray^[i].win.orderFrontRegardless;
|
||||
end;
|
||||
orderArrayCount := 0;
|
||||
@ -650,11 +624,52 @@ begin
|
||||
Freemem(orderArray);
|
||||
orderArray := nil;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
Application.IntfAppActivate;
|
||||
end;
|
||||
|
||||
procedure TAppDelegate.applicationWillResignActive(notification: NSNotification
|
||||
);
|
||||
var
|
||||
baseWindowNumber: NSInteger;
|
||||
windows: NSArray;
|
||||
window: NSWindow;
|
||||
form: TObject;
|
||||
info: PWinLevelOrder;
|
||||
begin
|
||||
windows := NSApp.orderedWindows;
|
||||
|
||||
baseWindowNumber:= 0;
|
||||
for window in windows do begin
|
||||
if window.level=NSNormalWindowLevel then begin
|
||||
baseWindowNumber:= window.windowNumber;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
orderArrayCount:= windows.count;
|
||||
orderArray:= GetMem(orderArrayCount * sizeof(TWinLevelOrder));
|
||||
|
||||
info:= orderArray^;
|
||||
for window in windows do begin
|
||||
info^.win := window;
|
||||
info^.lvl := window.level;
|
||||
info^.ord := window.orderedIndex;
|
||||
info^.vis := window.isVisible;
|
||||
inc( info );
|
||||
end;
|
||||
|
||||
for window in windows do begin
|
||||
form:= window.lclGetTarget;
|
||||
if form is TCustomForm then begin
|
||||
if TCustomForm(form).FormStyle=fsStayOnTop then begin
|
||||
window.setLevel( NSNormalWindowLevel );
|
||||
window.orderWindow_relativeTo( NSWindowAbove, baseWindowNumber );
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAppDelegate.applicationDidResignActive(notification: NSNotification);
|
||||
begin
|
||||
Application.IntfAppDeactivate;
|
||||
|
@ -214,17 +214,6 @@ const
|
||||
{ fsSplash } kCGFloatingWindowLevelKey,
|
||||
{ fsSystemStayOnTop } kCGFloatingWindowLevelKey // NSModalPanelWindowLevel
|
||||
);
|
||||
// Window levels make the form always stay on top, so if it is supposed to
|
||||
// stay on top of the app only, then a workaround is to hide it while the app
|
||||
// is deactivated
|
||||
FormStyleToHideOnDeactivate: array[TFormStyle] of Boolean = (
|
||||
{ fsNormal } False,
|
||||
{ fsMDIChild } False,
|
||||
{ fsMDIForm } False,
|
||||
{ fsStayOnTop } True,
|
||||
{ fsSplash } false,
|
||||
{ fsSystemStayOnTop } False
|
||||
);
|
||||
|
||||
HintWindowLevel = 11; // NSPopUpMenuWindowLevel
|
||||
|
||||
@ -241,11 +230,6 @@ var
|
||||
lvl : NSInteger;
|
||||
begin
|
||||
lvl := CGWindowLevelForKey(FormStyleToWindowLevelKey[AFormStyle]);
|
||||
{$ifdef BOOLFIX}
|
||||
win.setHidesOnDeactivate_(Ord(FormStyleToHideOnDeactivate[AFormStyle]));
|
||||
{$else}
|
||||
win.setHidesOnDeactivate(FormStyleToHideOnDeactivate[AFormStyle]);
|
||||
{$endif}
|
||||
win.setLevel(lvl);
|
||||
if win.isKindOfClass(TCocoaWindow) then
|
||||
TCocoaWindow(win).keepWinLevel := lvl;
|
||||
|
Loading…
Reference in New Issue
Block a user