Skip to content

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

feat: improvements to focus borders config (#372)

blam12614cfa9264
diff --git a/GlazeWM.App.WindowManager/WmStartup.cs b/GlazeWM.App.WindowManager/WmStartup.cs
index d1b1b311..373fcf55 100644
--- a/GlazeWM.App.WindowManager/WmStartup.cs
+++ b/GlazeWM.App.WindowManager/WmStartup.cs
@@ -46,8 +46,6 @@ namespace GlazeWM.App.WindowManager
_bus.Events.OfType<ApplicationExitingEvent>()
.Subscribe(_ => OnApplicationExit());
- _bus.Events.OfType<FocusChangedEvent>().Subscribe((@event) => _bus.InvokeAsync(new SetActiveWindowBorderCommand(@event.FocusedContainer as Window)));
-
// Populate initial monitors, windows, workspaces and user config.
_bus.Invoke(new PopulateInitialStateCommand());
@@ -76,6 +74,11 @@ namespace GlazeWM.App.WindowManager
_systemTrayIcon = new SystemTrayIcon(systemTrayIconConfig);
_systemTrayIcon.Show();
+ if (_userConfigService.FocusBorderConfig.Active.Enabled ||
+ _userConfigService.FocusBorderConfig.Inactive.Enabled)
+ _bus.Events.OfType<FocusChangedEvent>().Subscribe((@event) =>
+ _bus.InvokeAsync(new SetActiveWindowBorderCommand(@event.FocusedContainer as Window)));
+
// Hook mouse event for focus follows cursor.
if (_userConfigService.GeneralConfig.FocusFollowsCursor)
MouseEvents.MouseMoves.Sample(TimeSpan.FromMilliseconds(50)).Subscribe((@event) =>
diff --git a/GlazeWM.App/Resources/sample-config.yaml b/GlazeWM.App/Resources/sample-config.yaml
index d4e2adba..5e95fd5a 100644
--- a/GlazeWM.App/Resources/sample-config.yaml
+++ b/GlazeWM.App/Resources/sample-config.yaml
@@ -2,8 +2,17 @@ gaps:
inner_gap: 20
outer_gap: 20
+# Only supported for Windows 11 Build 22000.51 and above.
+focus_border_color:
+ active:
+ enabled: true
+ color: "#7ce38b"
+ inactive:
+ enabled: false
+
general:
focus_follows_cursor: false
+ cursor_follow_focus: false
# Whether to show floating windows as always on top.
show_floating_on_top: false
floating_window_move_amount: "5%"
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/SetActiveWindowBorderHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/SetActiveWindowBorderHandler.cs
index 78808197..b458efef 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/SetActiveWindowBorderHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/SetActiveWindowBorderHandler.cs
@@ -30,9 +30,11 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
uint BorderColorAttribute = 34;
if (_lastFocused is not null)
{
- uint defaultColor = 0xFFFFFFFF;
// Clear old window border
- _ = DwmSetWindowAttribute(_lastFocused.Handle, BorderColorAttribute, ref defaultColor, 4);
+ var inactiveColor = _userConfigService.FocusBorderConfig.Inactive.Enabled
+ ? rgbToUint(_userConfigService.FocusBorderConfig.Inactive.Color)
+ : 0xFFFFFFFF;
+ _ = DwmSetWindowAttribute(_lastFocused.Handle, BorderColorAttribute, ref inactiveColor, 4);
}
var newWindowFocused = command.TargetWindow;
@@ -41,8 +43,10 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
_lastFocused = command.TargetWindow;
// Set new window border
- var configColor = rgbToUint(_userConfigService.GeneralConfig.FocusBorderColor);
- _ = DwmSetWindowAttribute(_lastFocused.Handle, BorderColorAttribute, ref configColor, 4);
+ var activeColor = _userConfigService.FocusBorderConfig.Active.Enabled
+ ? rgbToUint(_userConfigService.FocusBorderConfig.Active.Color)
+ : 0xFFFFFFFF;
+ _ = DwmSetWindowAttribute(_lastFocused.Handle, BorderColorAttribute, ref activeColor, 4);
return CommandResponse.Ok;
}
}
diff --git a/GlazeWM.Domain/UserConfigs/FocusBorderConfig.cs b/GlazeWM.Domain/UserConfigs/FocusBorderConfig.cs
new file mode 100644
index 00000000..50e6d233
--- /dev/null
+++ b/GlazeWM.Domain/UserConfigs/FocusBorderConfig.cs
@@ -0,0 +1,28 @@
+namespace GlazeWM.Domain.UserConfigs
+{
+ public class FocusBordersConfig
+ {
+ /// <summary>
+ /// Border of the focused window.
+ /// </summary>
+ public FocusBorder Active { get; set; } = new() { Enabled = true, Color = "#7CE38B" };
+
+ /// <summary>
+ /// Border of non-focused windows.
+ /// </summary>
+ public FocusBorder Inactive { get; set; } = new() { Enabled = false };
+ }
+
+ public class FocusBorder
+ {
+ /// <summary>
+ /// Should the default transparent border be used.
+ /// </summary>
+ public bool Enabled;
+
+ /// <summary>
+ /// Border color of window.
+ /// </summary>
+ public string Color;
+ }
+}
diff --git a/GlazeWM.Domain/UserConfigs/GeneralConfig.cs b/GlazeWM.Domain/UserConfigs/GeneralConfig.cs
index 81c2dfe8..7d0f53ae 100644
--- a/GlazeWM.Domain/UserConfigs/GeneralConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/GeneralConfig.cs
@@ -20,10 +20,6 @@ namespace GlazeWM.Domain.UserConfigs
/// </summary>
public string FloatingWindowMoveAmount { get; set; } = "5%";
/// <summary>
- /// Color for border drawn around a focused window.
- /// </summary>
- public string FocusBorderColor { get; set; } = "#FFFFFFFF";
- /// <summary>
/// If activated, by switching to the current workspace the previous focused workspace is activated.
/// </summary>
public bool ToggleWorkspaceOnRefocus { get; set; }
diff --git a/GlazeWM.Domain/UserConfigs/UserConfig.cs b/GlazeWM.Domain/UserConfigs/UserConfig.cs
index 4d4c9d34..cbd4136c 100644
--- a/GlazeWM.Domain/UserConfigs/UserConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/UserConfig.cs
@@ -7,6 +7,8 @@ namespace GlazeWM.Domain.UserConfigs
{
public GapsConfig Gaps { get; set; } = new();
+ public FocusBordersConfig FocusBorderColor { get; set; } = new();
+
public GeneralConfig General { get; set; } = new();
public BarConfig Bar { get; set; } = new();
diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.cs
index 82dbd58f..3cfe30ae 100644
--- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs
+++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs
@@ -16,6 +16,7 @@ namespace GlazeWM.Domain.UserConfigs
public UserConfig UserConfig { private get; set; }
public GapsConfig GapsConfig => UserConfig.Gaps;
+ public FocusBordersConfig FocusBorderConfig => UserConfig.FocusBorderColor;
public GeneralConfig GeneralConfig => UserConfig.General;
public List<BarConfig> BarConfigs => UserConfig.BarConfigs;
public List<WorkspaceConfig> WorkspaceConfigs => UserConfig.Workspaces;