GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add window effects for hiding title bar and changing corner style (#735)
JonasWischeropp4e5c662d6dcc
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rsindex 4440b1a9..8f3ebd3c 100644--- a/packages/wm/src/app_command.rs+++ b/packages/wm/src/app_command.rs@@ -1,7 +1,7 @@use std::{iter, path::PathBuf};use anyhow::{bail, Context};-use clap::{error::KindFormatter, Args, Parser, ValueEnum};+use clap::{error::KindFormatter, ArgAction, Args, Parser, ValueEnum};use serde::{Deserialize, Deserializer, Serialize};use tracing::{warn, Level};use uuid::Uuid;@@ -26,7 +26,8 @@ use crate::{windows::{commands::{ignore_window, move_window_in_direction, move_window_to_workspace,- resize_window, set_window_size, update_window_state,+ resize_window, set_title_bar_visibility, set_window_size,+ update_window_state,},traits::WindowGetters,WindowState,@@ -205,6 +206,10 @@ pub enum InvokeCommand {},SetMinimized,SetTiling,+ SetTitleBarVisibility {+ #[clap(required = true, action = ArgAction::Set)]+ visible: bool,+ },ShellExec {#[clap(required = true, trailing_var_arg = true)]command: Vec<String>,@@ -485,6 +490,9 @@ impl InvokeCommand {_ => Ok(()),}}+ InvokeCommand::SetTitleBarVisibility { visible } => {+ set_title_bar_visibility(*visible, subject_container)+ }InvokeCommand::ShellExec { command } => {shell_exec(&command.join(" "))}diff --git a/packages/wm/src/common/commands/platform_sync.rs b/packages/wm/src/common/commands/platform_sync.rsindex d56f0a77..9f1493f0 100644--- a/packages/wm/src/common/commands/platform_sync.rs+++ b/packages/wm/src/common/commands/platform_sync.rs@@ -7,7 +7,7 @@ use crate::{traits::{CommonGetters, PositionGetters},Container, WindowContainer,},- user_config::{CursorJumpTrigger, UserConfig},+ user_config::{CursorJumpTrigger, UserConfig, WindowEffectConfig},windows::traits::WindowGetters,wm_event::WmEvent,wm_state::WmState,@@ -176,22 +176,57 @@ fn apply_window_effects(let window_effects = &config.value.window_effects;+ let effect_config = match is_focused {+ true => &window_effects.focused_window,+ false => &window_effects.other_windows,+ };+// Skip if both focused + non-focused window effects are disabled.- if !window_effects.focused_window.border.enabled- && !window_effects.other_windows.border.enabled+ if window_effects.focused_window.border.enabled+ || window_effects.other_windows.border.enabled{- return;+ apply_border_effect(&window, effect_config);};- let border_config = match is_focused {- true => &config.value.window_effects.focused_window.border,- false => &config.value.window_effects.other_windows.border,- };+ if window_effects.focused_window.hide_title_bar.enabled+ || window_effects.other_windows.hide_title_bar.enabled+ {+ apply_hide_title_bar_effect(&window, effect_config);+ }++ if window_effects.focused_window.corner.enabled+ || window_effects.other_windows.corner.enabled+ {+ apply_corner_effect(&window, effect_config);+ }+}- let border_color = match border_config.enabled {- true => Some(&border_config.color),+fn apply_border_effect(+ window: &WindowContainer,+ effect_config: &WindowEffectConfig,+) {+ let border_color = match effect_config.border.enabled {+ true => Some(&effect_config.border.color),false => None,};_ = window.native().set_border_color(border_color);}++fn apply_hide_title_bar_effect(+ window: &WindowContainer,+ effect_config: &WindowEffectConfig,+) {+ _ = window+ .native()+ .set_title_bar_visibility(!effect_config.hide_title_bar.enabled);+}++fn apply_corner_effect(+ window: &WindowContainer,+ effect_config: &WindowEffectConfig,+) {+ _ = window+ .native()+ .set_corner_style(effect_config.corner.style.clone());+}diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rsindex d21c2a8a..9072d953 100644--- a/packages/wm/src/common/platform/native_window.rs+++ b/packages/wm/src/common/platform/native_window.rs@@ -7,6 +7,8 @@ use windows::{Graphics::Dwm::{DwmGetWindowAttribute, DwmSetWindowAttribute, DWMWA_BORDER_COLOR,DWMWA_CLOAKED, DWMWA_COLOR_NONE, DWMWA_EXTENDED_FRAME_BOUNDS,+ DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DEFAULT, DWMWCP_DONOTROUND,+ DWMWCP_ROUND, DWMWCP_ROUNDSMALL,},System::Threading::{OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32,@@ -21,14 +23,15 @@ use windows::{EnumWindows, GetClassNameW, GetWindow, GetWindowLongPtrW,GetWindowRect, GetWindowTextW, GetWindowThreadProcessId, IsIconic,IsWindowVisible, IsZoomed, SendNotifyMessageW,- SetForegroundWindow, SetWindowPos, ShowWindowAsync, GWL_EXSTYLE,- GWL_STYLE, GW_OWNER, HWND_NOTOPMOST, HWND_TOPMOST,- SWP_ASYNCWINDOWPOS, SWP_FRAMECHANGED, SWP_HIDEWINDOW,- SWP_NOACTIVATE, SWP_NOCOPYBITS, SWP_NOSENDCHANGING,+ SetForegroundWindow, SetWindowLongPtrW, SetWindowPos,+ ShowWindowAsync, GWL_EXSTYLE, GWL_STYLE, GW_OWNER, HWND_NOTOPMOST,+ HWND_TOPMOST, SWP_ASYNCWINDOWPOS, SWP_FRAMECHANGED,+ SWP_HIDEWINDOW, SWP_NOACTIVATE, SWP_NOCOPYBITS, SWP_NOMOVE,+ SWP_NOOWNERZORDER, SWP_NOSENDCHANGING, SWP_NOSIZE, SWP_NOZORDER,SWP_SHOWWINDOW, SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE, SW_RESTORE,SW_SHOWNA, WINDOW_EX_STYLE, WINDOW_STYLE, WM_CLOSE, WS_CAPTION,- WS_CHILD, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_MAXIMIZEBOX,- WS_THICKFRAME,+ WS_CHILD, WS_DLGFRAME, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW,+ WS_MAXIMIZEBOX, WS_THICKFRAME,},},},@@ -36,6 +39,7 @@ use windows::{use crate::{common::{Color, LengthValue, Memo, Rect, RectDelta},+ user_config::CornerStyle,windows::WindowState,};@@ -325,6 +329,66 @@ impl NativeWindow {Ok(())}+ pub fn set_corner_style(+ &self,+ corner_type: CornerStyle,+ ) -> anyhow::Result<()> {+ let corner_preference = match corner_type {+ CornerStyle::WindowsDefault => DWMWCP_DEFAULT,+ CornerStyle::Square => DWMWCP_DONOTROUND,+ CornerStyle::Round => DWMWCP_ROUND,+ CornerStyle::SmallRound => DWMWCP_ROUNDSMALL,+ };++ unsafe {+ DwmSetWindowAttribute(+ HWND(self.handle),+ DWMWA_WINDOW_CORNER_PREFERENCE,+ &(corner_preference.0) as *const _ as _,+ std::mem::size_of::<i32>() as u32,+ )?;+ }++ Ok(())+ }++ pub fn set_title_bar_visibility(+ &self,+ visible: bool,+ ) -> anyhow::Result<()> {+ unsafe {+ let style = GetWindowLongPtrW(HWND(self.handle), GWL_STYLE);++ let new_style = match visible {+ true => style | (WS_DLGFRAME.0 as isize),+ false => style & !(WS_DLGFRAME.0 as isize),+ };++ if new_style != style {+ SetWindowLongPtrW(HWND(self.handle), GWL_STYLE, new_style);+ SetWindowPos(+ HWND(self.handle),+ HWND_NOTOPMOST,+ 0,+ 0,+ 0,+ 0,+ SWP_FRAMECHANGED+ | SWP_NOMOVE+ | SWP_NOSIZE+ | SWP_NOZORDER+ | SWP_NOOWNERZORDER+ | SWP_NOACTIVATE+ | SWP_NOCOPYBITS+ | SWP_NOSENDCHANGING+ | SWP_ASYNCWINDOWPOS,+ )?;+ }+ }++ Ok(())+ }+/// Gets the window's position, including the window's frame. Excludes/// the window's shadow borders.///diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rsindex 1472ba8f..cc27f54d 100644--- a/packages/wm/src/user_config.rs+++ b/packages/wm/src/user_config.rs@@ -505,6 +505,14 @@ pub struct WindowEffectsConfig {pub struct WindowEffectConfig {/// Config for optionally applying a colored border.pub border: BorderEffectConfig,++ /// Config for optionally hiding the title bar.+ #[serde(default)]+ pub hide_title_bar: HideTitleBarEffectConfig,++ /// Config for optionally changing the corner style.+ #[serde(default)]+ pub corner: CornerEffectConfig,}#[derive(Clone, Debug, Deserialize, Serialize)]@@ -519,6 +527,35 @@ pub struct BorderEffectConfig {pub color: Color,}+#[derive(Clone, Debug, Deserialize, Serialize)]+#[serde(rename_all(serialize = "camelCase"))]+pub struct HideTitleBarEffectConfig {+ /// Whether to enable the effect.+ #[serde(default = "default_bool::<false>")]+ pub enabled: bool,+}++#[derive(Clone, Debug, Deserialize, Serialize)]+#[serde(rename_all(serialize = "camelCase"))]+pub struct CornerEffectConfig {+ /// Whether to enable the effect.+ #[serde(default = "default_bool::<false>")]+ pub enabled: bool,++ /// Style of the window corners.+ #[serde(default)]+ pub style: CornerStyle,+}++#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]+#[serde(rename_all = "snake_case")]+pub enum CornerStyle {+ WindowsDefault,+ Square,+ Round,+ SmallRound,+}+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]#[serde(rename_all(serialize = "camelCase"))]pub struct WindowRuleConfig {@@ -611,3 +648,24 @@ const fn default_blue() -> Color {fn default_window_rule_on() -> Vec<WindowRuleEvent> {vec![WindowRuleEvent::Manage, WindowRuleEvent::TitleChange]}++impl Default for CornerStyle {+ fn default() -> Self {+ CornerStyle::WindowsDefault+ }+}++impl Default for HideTitleBarEffectConfig {+ fn default() -> Self {+ HideTitleBarEffectConfig { enabled: false }+ }+}++impl Default for CornerEffectConfig {+ fn default() -> Self {+ CornerEffectConfig {+ enabled: false,+ style: CornerStyle::WindowsDefault,+ }+ }+}diff --git a/packages/wm/src/windows/commands/mod.rs b/packages/wm/src/windows/commands/mod.rsindex 63abc576..73101cc9 100644--- a/packages/wm/src/windows/commands/mod.rs+++ b/packages/wm/src/windows/commands/mod.rs@@ -4,6 +4,7 @@ mod move_window_in_direction;mod move_window_to_workspace;mod resize_window;mod run_window_rules;+mod set_title_bar_visibility;mod set_window_size;mod unmanage_window;mod update_window_state;@@ -14,6 +15,7 @@ pub use move_window_in_direction::*;pub use move_window_to_workspace::*;pub use resize_window::*;pub use run_window_rules::*;+pub use set_title_bar_visibility::*;pub use set_window_size::*;pub use unmanage_window::*;pub use update_window_state::*;diff --git a/packages/wm/src/windows/commands/set_title_bar_visibility.rs b/packages/wm/src/windows/commands/set_title_bar_visibility.rsnew file mode 100644index 00000000..7aa75ea2--- /dev/null+++ b/packages/wm/src/windows/commands/set_title_bar_visibility.rs@@ -0,0 +1,16 @@+use crate::{+ containers::{traits::CommonGetters, Container},+ windows::traits::WindowGetters,+};++pub fn set_title_bar_visibility(+ title_bar_is_visible: bool,+ subject_container: Container,+) -> anyhow::Result<()> {+ let window = subject_container.as_window_container()?;+ window+ .native()+ .set_title_bar_visibility(title_bar_is_visible)?;++ Ok(())+}