diff --git a/src/ManagedShell.AppBar/AppBarWindow.cs b/src/ManagedShell.AppBar/AppBarWindow.cs index bdfcf7a5..1cd4df66 100644 --- a/src/ManagedShell.AppBar/AppBarWindow.cs +++ b/src/ManagedShell.AppBar/AppBarWindow.cs @@ -328,8 +328,20 @@ protected virtual void OnAutoHideAnimationComplete(bool isHiding) } } - protected virtual void OnFullScreenEnter() + protected virtual void OnFullScreenEnter(FullScreenApp app) { + if (AppBarMode != AppBarMode.Normal && app.fromTasksService) + { + // If we are not reserving space, then some maximized windows could be mistaken as full-screen. + // Use the same strict bounds checks as full-screen apps with fromTasksService=false. + if (!(app.rect.Top == app.screen.Bounds.Top && app.rect.Left == app.screen.Bounds.Left && + app.rect.Bottom == app.screen.Bounds.Bottom && app.rect.Right == app.screen.Bounds.Right)) + { + ShellLogger.Debug($"AppBarWindow: {Name} on {Screen.DeviceName} ignoring full-screen app"); + return; + } + } + ShellLogger.Debug($"AppBarWindow: {Name} on {Screen.DeviceName} conceding to full-screen app"); Topmost = false; @@ -369,23 +381,23 @@ private void OnClosing(object sender, CancelEventArgs e) private void FullScreenApps_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { - bool found = false; + FullScreenApp app = null; - foreach (FullScreenApp app in _fullScreenHelper.FullScreenApps) + foreach (FullScreenApp _app in _fullScreenHelper.FullScreenApps) { - if (app.screen.DeviceName == Screen.DeviceName || app.screen.IsVirtualScreen) + if (_app.screen.DeviceName == Screen.DeviceName || _app.screen.IsVirtualScreen) { - // we need to not be on top now - found = true; + // there is a full screen app on our screen + app = _app; break; } } - if (found && Topmost) + if (app != null && Topmost) { - OnFullScreenEnter(); + OnFullScreenEnter(app); } - else if (!found && !Topmost) + else if (app == null && !Topmost) { OnFullScreenLeave(); } diff --git a/src/ManagedShell.AppBar/FullScreenApp.cs b/src/ManagedShell.AppBar/FullScreenApp.cs index 6171c454..70d1cdb1 100644 --- a/src/ManagedShell.AppBar/FullScreenApp.cs +++ b/src/ManagedShell.AppBar/FullScreenApp.cs @@ -1,4 +1,5 @@ -using System; +using ManagedShell.Interop; +using System; namespace ManagedShell.AppBar { @@ -6,6 +7,7 @@ public class FullScreenApp { public IntPtr hWnd; public ScreenInfo screen; + public NativeMethods.Rect rect; public string title; public bool fromTasksService; } diff --git a/src/ManagedShell.AppBar/FullScreenHelper.cs b/src/ManagedShell.AppBar/FullScreenHelper.cs index 6d13434b..fb67b6ab 100644 --- a/src/ManagedShell.AppBar/FullScreenHelper.cs +++ b/src/ManagedShell.AppBar/FullScreenHelper.cs @@ -49,6 +49,12 @@ private void TasksService_Event(object sender, EventArgs e) private void TasksService_FullScreenChanged(object sender, FullScreenEventArgs e) { + if (InactiveFullScreenApps.Count > 0 && InactiveFullScreenApps.Any(app => app.hWnd == e.Handle)) + { + // If this window is in the inactive list, remove it--the message that triggered this event takes precedence + InactiveFullScreenApps.Remove(InactiveFullScreenApps.First(app => app.hWnd == e.Handle)); + } + if (FullScreenApps.Any(app => app.hWnd == e.Handle) == e.IsEntering) { if (e.IsEntering) @@ -63,12 +69,6 @@ private void TasksService_FullScreenChanged(object sender, FullScreenEventArgs e return; } - if (InactiveFullScreenApps.Count > 0 && InactiveFullScreenApps.Any(app => app.hWnd == e.Handle)) - { - // If this window is in the inactive list, remove it because it is no longer needed - InactiveFullScreenApps.Remove(InactiveFullScreenApps.First(app => app.hWnd == e.Handle)); - } - if (e.IsEntering) { // When TasksService gives us a full-screen window handle, trust that it is full-screen in terms of bounds @@ -224,10 +224,10 @@ private void updateFullScreenWindows() private FullScreenApp getFullScreenApp(IntPtr hWnd, bool fromTasksService = false) { ScreenInfo screenInfo = null; + Rect rect = GetEffectiveWindowRect(hWnd); if (!fromTasksService) { - Rect rect = GetEffectiveWindowRect(hWnd); var allScreens = Screen.AllScreens.Select(ScreenInfo.Create).ToList(); if (allScreens.Count > 1) allScreens.Add(ScreenInfo.CreateVirtualScreen()); @@ -260,7 +260,7 @@ private FullScreenApp getFullScreenApp(IntPtr hWnd, bool fromTasksService = fals } // this is a full screen app - return new FullScreenApp { hWnd = hWnd, screen = screenInfo, title = win.Title, fromTasksService = fromTasksService }; + return new FullScreenApp { hWnd = hWnd, screen = screenInfo, rect = rect, title = win.Title, fromTasksService = fromTasksService }; } private Rect GetEffectiveWindowRect(IntPtr hWnd)