GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: implement option on system tray icon for toggling window animations
Lars Berger92174f727e19
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rsindex 36678446..2ca19c20 100644--- a/packages/wm/src/common/platform/platform.rs+++ b/packages/wm/src/common/platform/platform.rs@@ -17,9 +17,11 @@ use windows::{CreateWindowExW, DispatchMessageW, GetAncestor, GetDesktopWindow,GetForegroundWindow, GetMessageW, PeekMessageW,PostThreadMessageW, RegisterClassW, SetCursorPos,- TranslateMessage, WindowFromPoint, CS_HREDRAW, CS_VREDRAW,- CW_USEDEFAULT, GA_ROOT, MSG, PM_REMOVE, SW_NORMAL, WM_QUIT,- WNDCLASSW, WNDPROC, WS_OVERLAPPEDWINDOW,+ SystemParametersInfoW, TranslateMessage, WindowFromPoint,+ ANIMATIONINFO, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, GA_ROOT,+ MSG, PM_REMOVE, SPI_GETANIMATION, SPI_SETANIMATION, SW_NORMAL,+ SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, WM_QUIT, WNDCLASSW, WNDPROC,+ WS_OVERLAPPEDWINDOW,},},},@@ -242,6 +244,50 @@ impl Platform {Ok(())}+ /// Gets whether window transition animations are currently enabled.+ ///+ /// Note that this is a global system setting.+ pub fn window_animations_enabled() -> anyhow::Result<bool> {+ let mut animation_info = ANIMATIONINFO {+ cbSize: std::mem::size_of::<ANIMATIONINFO>() as u32,+ iMinAnimate: 0,+ };++ unsafe {+ SystemParametersInfoW(+ SPI_GETANIMATION,+ 0,+ Some(&mut animation_info as *mut _ as _),+ SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),+ )+ }?;++ Ok(animation_info.iMinAnimate != 0)+ }++ /// Enables or disables window transition animations.+ ///+ /// Note that this is a global system setting.+ pub fn set_window_animations_enabled(+ enable: bool,+ ) -> anyhow::Result<()> {+ let mut animation_info = ANIMATIONINFO {+ cbSize: std::mem::size_of::<ANIMATIONINFO>() as u32,+ iMinAnimate: if enable { 1 } else { 0 },+ };++ unsafe {+ SystemParametersInfoW(+ SPI_SETANIMATION,+ 0,+ Some(&mut animation_info as *mut _ as _),+ SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),+ )+ }?;++ Ok(())+ }+/// Parses a command string into a program name/path and arguments. This/// also expands any environment variables found in the command string if/// they are wrapped in `%` characters. If the command string is a path, adiff --git a/packages/wm/src/sys_tray.rs b/packages/wm/src/sys_tray.rsindex f3aaac89..5377c131 100644--- a/packages/wm/src/sys_tray.rs+++ b/packages/wm/src/sys_tray.rs@@ -29,8 +29,15 @@ impl SystemTray {let config_dir_item =MenuItem::new("Show config folder", true, None);- let animations_item =- CheckMenuItem::new("Window animations", true, false, None);+ let mut animations_enabled =+ Platform::window_animations_enabled().unwrap_or(true);++ let animations_item = CheckMenuItem::new(+ "Window animations",+ true,+ animations_enabled,+ None,+ );let exit_item = MenuItem::new("Exit", true, None);@@ -60,8 +67,11 @@ impl SystemTray {// TODO: Open config directory.todo!()} else if event.id == animations_item.id() {- // TODO: Enable/disable window animations.- animations_item.set_checked(animations_item.is_checked());+ // Toggle window animations globally.+ let _ =+ Platform::set_window_animations_enabled(!animations_enabled);++ animations_enabled = !animations_enabled;} else if event.id == exit_item.id() {exit_tx.send(())?;}