diff --git a/delphi-backend/Source/PM.Bridge.pas b/delphi-backend/Source/PM.Bridge.pas index c0f4585..55d72f5 100644 --- a/delphi-backend/Source/PM.Bridge.pas +++ b/delphi-backend/Source/PM.Bridge.pas @@ -726,7 +726,11 @@ begin // captured our own window as its target. Callers that already placed the // foreground themselves (post-autofill) pass False. CaptureForegroundOwner; - if AReturnForeground and (FPrevForeground <> 0) and IsWindow(FPrevForeground) then + // Not when it is minimised: ForceForegroundWindow un-minimises its target, and + // popping another application's window back open is not ours to decide. The + // user put it away — leave the foreground to Windows. + if AReturnForeground and (FPrevForeground <> 0) and IsWindow(FPrevForeground) and + (not IsIconic(FPrevForeground)) then ForceForegroundWindow(FPrevForeground); // 1. Hide the visible form via both FMX state and Win32 ShowWindow. diff --git a/delphi-backend/UMainForm.pas b/delphi-backend/UMainForm.pas index b6922a7..475d3ad 100644 --- a/delphi-backend/UMainForm.pas +++ b/delphi-backend/UMainForm.pas @@ -369,7 +369,9 @@ begin TThread.ForceQueue(nil, procedure begin - FBridge.MinimizeToTray; + // No foreground handback: a -tray launch never took the foreground from + // anyone, so there is nobody to give it back to. + FBridge.MinimizeToTray(True, False); // Hidden now — safe to pay the startup cost. btnStartClick(Nil); LogLine('Launched with --tray, started hidden (balloon suppressed)');