Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(domain): add `ContainerService` getter for whether focus in synced with the OS

Lars Bergercaa514e96c71
diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.cs
index ea09c618..5ecf130b 100644
--- a/GlazeWM.Domain/Containers/ContainerService.cs
+++ b/GlazeWM.Domain/Containers/ContainerService.cs
@@ -4,6 +4,7 @@ using System.Linq;
using GlazeWM.Domain.Common.Enums;
using GlazeWM.Domain.UserConfigs;
using GlazeWM.Domain.Windows;
+using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;
namespace GlazeWM.Domain.Containers
{
@@ -39,6 +40,25 @@ namespace GlazeWM.Domain.Containers
/// </summary>
public Container PendingFocusContainer = null;
+ /// <summary>
+ /// Whether the window focused by the OS is managed by the WM. Windows that are ignored by the
+ /// user's window rules or run with elevated permissions are not managed by the WM.
+ /// </summary>
+ public bool IsForegroundManaged
+ {
+ get
+ {
+ var foregroundHandle = GetForegroundWindow();
+ var focusedContainer = FocusedContainer;
+
+ if (focusedContainer is Window)
+ return (focusedContainer as Window).Hwnd == foregroundHandle;
+
+ else
+ return IntPtr.Zero == foregroundHandle;
+ }
+ }
+
private UserConfigService _userConfigService;
public ContainerService(UserConfigService userConfigService)