Browse Source

dismiss popups when toplevel deactivates in embedded scenarios (#18527)

pull/18538/head
Emmanuel Hansen 11 months ago
committed by GitHub
parent
commit
c9f6b8dd51
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 19
      src/Avalonia.Controls/Primitives/Popup.cs

19
src/Avalonia.Controls/Primitives/Popup.cs

@ -15,6 +15,7 @@ using Avalonia.Metadata;
using Avalonia.Platform;
using Avalonia.VisualTree;
using Avalonia.Media;
using Avalonia.Interactivity;
namespace Avalonia.Controls.Primitives
{
@ -495,13 +496,13 @@ namespace Avalonia.Controls.Primitives
SubscribeToEventHandler<Control, EventHandler<VisualTreeAttachmentEventArgs>>(placementTarget, TargetDetached,
(x, handler) => x.DetachedFromVisualTree += handler,
(x, handler) => x.DetachedFromVisualTree -= handler).DisposeWith(handlerCleanup);
if (topLevel is Window window && window.PlatformImpl != null)
{
SubscribeToEventHandler<Window, EventHandler>(window, WindowDeactivated,
(x, handler) => x.Deactivated += handler,
(x, handler) => x.Deactivated -= handler).DisposeWith(handlerCleanup);
SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus,
(x, handler) => x.LostFocus += handler,
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
@ -535,6 +536,12 @@ namespace Avalonia.Controls.Primitives
(x, handler) => x.Closed -= handler).DisposeWith(handlerCleanup);
}
}
else if (topLevel is { } tl && tl.PlatformImpl is ITopLevelImpl pimpl)
{
SubscribeToEventHandler<ITopLevelImpl, Action>(pimpl, TopLevelLostPlatformFocus,
(x, handler) => x.LostFocus += handler,
(x, handler) => x.LostFocus -= handler).DisposeWith(handlerCleanup);
}
InputManager.Instance?.Process.Subscribe(ListenForNonClientClick).DisposeWith(handlerCleanup);
@ -988,6 +995,14 @@ namespace Avalonia.Controls.Primitives
}
}
private void TopLevelLostPlatformFocus()
{
if (IsLightDismissEnabled)
{
Close();
}
}
private void PlacementTargetTransformChanged(Visual v, Matrix? matrix)
{
if (_openState is not null)

Loading…
Cancel
Save