Skip to content

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

feat: add separate `enabled` property to window border config

Lars Bergerb2d62784ee62
diff --git a/packages/wm/src/common/commands/platform_sync.rs b/packages/wm/src/common/commands/platform_sync.rs
index 0efc05fe..d675239f 100644
--- a/packages/wm/src/common/commands/platform_sync.rs
+++ b/packages/wm/src/common/commands/platform_sync.rs
@@ -159,15 +159,20 @@ fn apply_window_effects(
is_focused: bool,
config: &UserConfig,
) {
- let border_color = match is_focused {
- true => &config.value.window_effects.focused_window.border_color,
- false => &config.value.window_effects.other_windows.border_color,
- }
- .clone();
-
// TODO: Be able to add transparency to windows.
- if let Some(border_color) = border_color {
- _ = window.native().set_border_color(Some(&border_color));
+ let enable_borders = match is_focused {
+ true => config.value.window_effects.focused_window.border.enabled,
+ false => config.value.window_effects.other_windows.border.enabled,
+ };
+
+ if enable_borders {
+ let border_config = match is_focused {
+ true => &config.value.window_effects.focused_window.border,
+ false => &config.value.window_effects.other_windows.border,
+ }
+ .clone();
+
+ _ = window.native().set_border_color(Some(&border_config.color));
}
}
diff --git a/packages/wm/src/common/commands/reload_config.rs b/packages/wm/src/common/commands/reload_config.rs
index 7838b5ce..1e2e70ef 100644
--- a/packages/wm/src/common/commands/reload_config.rs
+++ b/packages/wm/src/common/commands/reload_config.rs
@@ -124,19 +124,19 @@ fn update_window_effects(
let window_effects = &config.value.window_effects;
let old_window_effects = &old_config.window_effects;
- // Window border effects are left as is if set to `null` in the config.
- // However, when transitioning from a non-null value to `null`, we have
- // to reset to the system default.
- if window_effects.focused_window.border_color.is_none()
- && old_window_effects.focused_window.border_color.is_some()
+ // Window border effects are left at system defaults if disabled in the
+ // config. However, when transitioning from colored borders to having
+ // them disabled, it's best to reset to the system defaults.
+ if !window_effects.focused_window.border.enabled
+ && old_window_effects.focused_window.border.enabled
{
if let Ok(window) = focused_container.as_window_container() {
_ = window.native().set_border_color(None);
}
}
- if window_effects.other_windows.border_color.is_none()
- && old_window_effects.other_windows.border_color.is_some()
+ if !window_effects.other_windows.border.enabled
+ && old_window_effects.other_windows.border.enabled
{
let unfocused_windows = state
.windows()
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 0957a327..53cea853 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -291,8 +291,19 @@ pub struct WindowEffectsConfig {
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct WindowEffectConfig {
- /// Optional colored border to apply.
- pub border_color: Option<Color>,
+ /// Config for optionally applying a colored border.
+ pub border: BorderEffectConfig,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct BorderEffectConfig {
+ /// Whether to enable the effect.
+ pub enabled: bool,
+
+ /// Color of the window border.
+ #[serde(default = "default_blue")]
+ pub color: Color,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -318,3 +329,13 @@ pub struct WorkspaceConfig {
const fn default_bool<const V: bool>() -> bool {
V
}
+
+/// Helper function for setting a default value for a color field.
+const fn default_blue() -> Color {
+ Color {
+ r: 0,
+ g: 0,
+ b: 255,
+ a: 255,
+ }
+}
diff --git a/resources/sample-config.yaml b/resources/sample-config.yaml
index 6deac8db..8c4c18be 100644
--- a/resources/sample-config.yaml
+++ b/resources/sample-config.yaml
@@ -33,13 +33,16 @@ gaps:
window_effects:
# Visual effects to apply to the focused window.
focused_window:
- # Highlight the window with a colored border. Exclusive to Windows 11.
- # Set to `null` to disable the effect.
- border_color: '#0000ff'
+ # Highlight the window with a colored border.
+ # ** Exclusive to Windows 11 due to API limitations.
+ border:
+ enabled: true
+ color: '#0000ff'
# Visual effects to apply to non-focused windows.
other_windows:
- border_color: null
+ border:
+ enabled: false
window_behavior:
# New windows are created in this state whenever possible.