handle esc to dismiss dock flyout

This commit is contained in:
Mike Griese
2025-10-31 12:06:45 -05:00
parent bc6b2af03c
commit 64ea63b77d
3 changed files with 32 additions and 16 deletions

View File

@@ -16,7 +16,7 @@ using Microsoft.UI.Xaml.Controls.Primitives;
namespace Microsoft.CmdPal.UI.Dock;
public sealed partial class DockControl : UserControl, INotifyPropertyChanged
public sealed partial class DockControl : UserControl, INotifyPropertyChanged, IRecipient<CloseContextMenuMessage>
{
private DockViewModel _viewModel;
@@ -104,6 +104,7 @@ public sealed partial class DockControl : UserControl, INotifyPropertyChanged
// MainViewModel mainModel = (MainViewModel)DataContext;
_viewModel = viewModel;
InitializeComponent();
WeakReferenceMessenger.Default.Register<CloseContextMenuMessage>(this);
}
internal void UpdateSettings(DockSettings settings)
@@ -200,4 +201,12 @@ public sealed partial class DockControl : UserControl, INotifyPropertyChanged
// at its search box. The control isn't in the UI tree before that
ContextControl.FocusSearchBox();
}
public void Receive(CloseContextMenuMessage message)
{
if (ContextMenuFlyout.IsOpen)
{
ContextMenuFlyout.Hide();
}
}
}

View File

@@ -128,8 +128,6 @@ internal sealed partial class NowDockBand : CommandItem
Title = timeString;
Subtitle = dateString;
//// TODO! This is a hack - we shouldn't need to set a Name on band items to get them to appear. We should be able to figure it out if there's a Icon OR HasText
// ((NoOpCommand)Command).Name = $"{Title}\n{Subtitle}";
_copyDateCommand.Text = dateString;
_copyTimeCommand.Text = timeString;
}

View File

@@ -295,21 +295,30 @@ internal sealed class Window
/// <returns>The state (none, app, ...) of the window</returns>
internal WindowCloakState GetWindowCloakState()
{
_ = NativeMethods.DwmGetWindowAttribute(Hwnd, (int)DwmWindowAttributes.Cloaked, out var isCloakedState, sizeof(uint));
switch (isCloakedState)
try
{
case (int)DwmWindowCloakStates.None:
return WindowCloakState.None;
case (int)DwmWindowCloakStates.CloakedApp:
return WindowCloakState.App;
case (int)DwmWindowCloakStates.CloakedShell:
return WindowWalkerCommandsProvider.VirtualDesktopHelperInstance.IsWindowCloakedByVirtualDesktopManager(hwnd, Desktop.Id) ? WindowCloakState.OtherDesktop : WindowCloakState.Shell;
case (int)DwmWindowCloakStates.CloakedInherited:
return WindowCloakState.Inherited;
default:
return WindowCloakState.Unknown;
_ = NativeMethods.DwmGetWindowAttribute(Hwnd, (int)DwmWindowAttributes.Cloaked, out var isCloakedState, sizeof(uint));
switch (isCloakedState)
{
case (int)DwmWindowCloakStates.None:
return WindowCloakState.None;
case (int)DwmWindowCloakStates.CloakedApp:
return WindowCloakState.App;
case (int)DwmWindowCloakStates.CloakedShell:
return WindowWalkerCommandsProvider.VirtualDesktopHelperInstance.IsWindowCloakedByVirtualDesktopManager(hwnd, Desktop.Id) ? WindowCloakState.OtherDesktop : WindowCloakState.Shell;
case (int)DwmWindowCloakStates.CloakedInherited:
return WindowCloakState.Inherited;
default:
return WindowCloakState.Unknown;
}
}
catch
{
// Log?
}
return WindowCloakState.Unknown;
}
/// <summary>