Skip to content

Commit 408ca45

Browse files
emmaussMrJul
authored andcommitted
dismiss popups when toplevel deactivates in embedded scenarios (#18527)
1 parent c0f2c33 commit 408ca45

File tree

1 file changed

+17
-2
lines changed
  • src/Avalonia.Controls/Primitives

1 file changed

+17
-2
lines changed

src/Avalonia.Controls/Primitives/Popup.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Avalonia.Platform;
1515
using Avalonia.VisualTree;
1616
using Avalonia.Media;
17+
using Avalonia.Interactivity;
1718

1819
namespace Avalonia.Controls.Primitives
1920
{
@@ -460,13 +461,13 @@ public void Open()
460461
SubscribeToEventHandler<Control, EventHandler<VisualTreeAttachmentEventArgs>>(placementTarget, TargetDetached,
461462
(x, handler) => x.DetachedFromVisualTree += handler,
462463
(x, handler) => x.DetachedFromVisualTree -= handler).DisposeWith(handlerCleanup);
463-
464+
464465
if (topLevel is Window window && window.PlatformImpl != null)
465466
{
466467
SubscribeToEventHandler<Window, EventHandler>(window, WindowDeactivated,
467468
(x, handler) => x.Deactivated += handler,
468469
(x, handler) => x.Deactivated -= handler).DisposeWith(handlerCleanup);
469-
470+
470471
SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus,
471472
(x, handler) => x.LostFocus += handler,
472473
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
@@ -500,6 +501,12 @@ public void Open()
500501
(x, handler) => x.Closed -= handler).DisposeWith(handlerCleanup);
501502
}
502503
}
504+
else if (topLevel is { } tl && tl.PlatformImpl is ITopLevelImpl pimpl)
505+
{
506+
SubscribeToEventHandler<ITopLevelImpl, Action>(pimpl, TopLevelLostPlatformFocus,
507+
(x, handler) => x.LostFocus += handler,
508+
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
509+
}
503510

504511
InputManager.Instance?.Process.Subscribe(ListenForNonClientClick).DisposeWith(handlerCleanup);
505512

@@ -963,6 +970,14 @@ private void ParentClosed(object? sender, EventArgs e)
963970
}
964971
}
965972

973+
private void TopLevelLostPlatformFocus()
974+
{
975+
if (IsLightDismissEnabled)
976+
{
977+
Close();
978+
}
979+
}
980+
966981
private void PlacementTargetTransformChanged(Visual v, Matrix? matrix)
967982
{
968983
if (_openState is not null)

0 commit comments

Comments
 (0)