Skip to content

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

feat: show floating on top (#203)

lars-bergerd8866d542bad
diff --git a/GlazeWM.Bootstrapper/sample-config.yaml b/GlazeWM.Bootstrapper/sample-config.yaml
index 690ee7c9..04b5b1eb 100644
--- a/GlazeWM.Bootstrapper/sample-config.yaml
+++ b/GlazeWM.Bootstrapper/sample-config.yaml
@@ -2,6 +2,10 @@ gaps:
inner_gap: 20
outer_gap: 20
+general:
+ # Whether to show floating windows as always on top.
+ show_floating_on_top: true
+
bar:
height: "30px"
position: "top"
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs
index 91bcd493..694f58f0 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using GlazeWM.Domain.Containers.Commands;
+using GlazeWM.Domain.UserConfigs;
using GlazeWM.Domain.Windows;
using GlazeWM.Infrastructure.Bussing;
using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;
@@ -10,10 +11,14 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
internal class RedrawContainersHandler : ICommandHandler<RedrawContainersCommand>
{
private readonly ContainerService _containerService;
+ private readonly UserConfigService _userConfigService;
- public RedrawContainersHandler(ContainerService containerService)
+ public RedrawContainersHandler(
+ ContainerService containerService,
+ UserConfigService userConfigService)
{
_containerService = containerService;
+ _userConfigService = userConfigService;
}
public CommandResponse Handle(RedrawContainersCommand command)
@@ -40,22 +45,14 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
foreach (var window in windowsToRedraw)
{
- var flags = SWP.SWP_FRAMECHANGED | SWP.SWP_NOACTIVATE | SWP.SWP_NOCOPYBITS |
- SWP.SWP_NOZORDER | SWP.SWP_NOOWNERZORDER | SWP.SWP_NOSENDCHANGING;
+ SetWindowPosition(window);
- if (window.IsDisplayed)
- flags |= SWP.SWP_SHOWWINDOW;
- else
- flags |= SWP.SWP_HIDEWINDOW;
-
- SetWindowPosition(window, flags);
-
- // When there's a mismatch between the DPI of the monitor and the window, `SetWindowPos`
- // might size the window incorrectly. By calling `SetWindowPos` twice, inconsistencies after
- // the first move are resolved.
+ // When there's a mismatch between the DPI of the monitor and the window,
+ // `SetWindowPos` might size the window incorrectly. By calling `SetWindowPos`
+ // twice, inconsistencies after the first move are resolved.
if (window.HasPendingDpiAdjustment)
{
- SetWindowPosition(window, flags);
+ SetWindowPosition(window);
window.HasPendingDpiAdjustment = false;
}
}
@@ -65,32 +62,50 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
return CommandResponse.Ok;
}
- private static void SetWindowPosition(Window window, SWP flags)
+ private void SetWindowPosition(Window window)
{
+ var defaultFlags =
+ SWP.SWP_FRAMECHANGED |
+ SWP.SWP_NOACTIVATE |
+ SWP.SWP_NOCOPYBITS |
+ SWP.SWP_NOSENDCHANGING;
+
+ // Show or hide the window depending on whether the workspace is displayed.
+ if (window.IsDisplayed)
+ defaultFlags |= SWP.SWP_SHOWWINDOW;
+ else
+ defaultFlags |= SWP.SWP_HIDEWINDOW;
+
if (window is TilingWindow)
{
SetWindowPos(
window.Handle,
- IntPtr.Zero,
+ new IntPtr((int)ZOrderFlags.NoTopMost),
window.X - window.BorderDelta.Left,
window.Y - window.BorderDelta.Top,
window.Width + window.BorderDelta.Left + window.BorderDelta.Right,
window.Height + window.BorderDelta.Top + window.BorderDelta.Right,
- flags
+ defaultFlags
);
return;
}
- // Avoid adjusting the borders of floating windows. Otherwise the window will increase in size
- // from its original placement.
+ // Get z-order to set for floating windows.
+ var shouldShowOnTop = _userConfigService.GeneralConfig.ShowFloatingOnTop;
+ var floatingZOrder = shouldShowOnTop
+ ? ZOrderFlags.TopMost
+ : ZOrderFlags.NoTopMost;
+
+ // Avoid adjusting the borders of floating windows. Otherwise the window will
+ // increase in size from its original placement.
SetWindowPos(
window.Handle,
- IntPtr.Zero,
+ new IntPtr((int)floatingZOrder),
window.X,
window.Y,
window.Width,
window.Height,
- flags
+ defaultFlags
);
}
}
diff --git a/GlazeWM.Domain/UserConfigs/GeneralConfig.cs b/GlazeWM.Domain/UserConfigs/GeneralConfig.cs
new file mode 100644
index 00000000..90cae50a
--- /dev/null
+++ b/GlazeWM.Domain/UserConfigs/GeneralConfig.cs
@@ -0,0 +1,10 @@
+namespace GlazeWM.Domain.UserConfigs
+{
+ public class GeneralConfig
+ {
+ /// <summary>
+ /// Whether to show floating windows as always on top.
+ /// </summary>
+ public bool ShowFloatingOnTop { get; set; } = true;
+ }
+}
diff --git a/GlazeWM.Domain/UserConfigs/UserConfig.cs b/GlazeWM.Domain/UserConfigs/UserConfig.cs
index dfb624fc..a44bc995 100644
--- a/GlazeWM.Domain/UserConfigs/UserConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/UserConfig.cs
@@ -6,6 +6,8 @@ namespace GlazeWM.Domain.UserConfigs
{
public GapsConfig Gaps { get; set; } = new GapsConfig();
+ public GeneralConfig General { get; set; } = new GeneralConfig();
+
public BarConfig Bar { get; set; } = new BarConfig();
public List<WorkspaceConfig> Workspaces { get; set; } = new();
diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.cs
index 1359686b..67463c3f 100644
--- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs
+++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs
@@ -15,6 +15,7 @@ namespace GlazeWM.Domain.UserConfigs
public UserConfig UserConfig { private get; set; }
public GapsConfig GapsConfig => UserConfig.Gaps;
+ public GeneralConfig GeneralConfig => UserConfig.General;
public BarConfig BarConfig => UserConfig.Bar;
public List<WorkspaceConfig> WorkspaceConfigs => UserConfig.Workspaces;
public List<WindowRuleConfig> WindowRules => UserConfig.WindowRules;
diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs
index 834a4825..a4af651f 100644
--- a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs
+++ b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs
@@ -26,6 +26,31 @@ namespace GlazeWM.Infrastructure.WindowsApi
SWP_ASYNCWINDOWPOS = 0x4000
}
+ /// <summary>
+ /// Flags that can be passed as `hWndInsertAfter` to `SetWindowPos`.
+ /// </summary>
+ public enum ZOrderFlags
+ {
+ /// <summary>
+ /// Places the window above all non-topmost windows (that is, behind all topmost
+ /// windows). This flag has no effect if the window is already a non-topmost window.
+ /// </summary>
+ NoTopMost = -2,
+ /// <summary>
+ /// Places the window above all non-topmost windows. The window maintains its
+ /// topmost position even when it is deactivated.
+ /// </summary>
+ TopMost = -1,
+ /// <summary>
+ /// Places the window at the top of the Z order.
+ /// </summary>
+ Top = 0,
+ /// <summary>
+ /// Places the window at the bottom of the Z order.
+ /// </summary>
+ Bottom = 1,
+ }
+
/// <summary>
/// Window styles
/// </summary>