Skip to content

Commit

Permalink
feat: option to disable window transition animations (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger authored Sep 17, 2023
1 parent 6ec79d2 commit d675244
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions GlazeWM.App.Watcher/WatcherStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace GlazeWM.App.Watcher
{
public sealed class WatcherStartup
{
/// <summary>
/// Watcher is responsible for restoring all managed handles when the main process is
/// killed unexpectedly.
/// </summary>
public static async Task<ExitCode> Run(int ipcServerPort)
{
var client = new IpcClient(ipcServerPort);
Expand Down
10 changes: 10 additions & 0 deletions GlazeWM.App.WindowManager/WmStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public ExitCode Run()
_systemTrayIcon = new SystemTrayIcon(systemTrayIconConfig);
_systemTrayIcon.Show();

var windowAnimations = _userConfigService.GeneralConfig.WindowAnimations;

// Enable/disable window transition animations.
if (windowAnimations is not WindowAnimations.Unchanged)
{
SystemSettings.SetWindowAnimationsEnabled(
windowAnimations is WindowAnimations.True
);
}

if (_userConfigService.FocusBorderConfig.Active.Enabled ||
_userConfigService.FocusBorderConfig.Inactive.Enabled)
{
Expand Down
4 changes: 4 additions & 0 deletions GlazeWM.App/Resources/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ general:
floating_window_move_amount: "5%"
# When enabled, switching to the current workspace activates the previously focused workspace
toggle_workspace_on_refocus: false
# *Strongly* recommended to set to 'false'. Whether to globally enable/disable
# window transition animations (on minimize, close, etc). Set to 'unchanged'
# to make no setting changes.
window_animations: "unchanged"

bar:
height: "30px"
Expand Down
5 changes: 4 additions & 1 deletion GlazeWM.Domain/UserConfigs/GeneralConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class GeneralConfig
public bool ShowFloatingOnTop { get; set; }
/// <summary>
/// Center the cursor in the middle of a newly focused window
/// TODO: Not officially released because implementation is buggy. Use at own risk.
/// </summary>
public bool CursorFollowsFocus { get; set; }
/// <summary>
Expand All @@ -23,5 +22,9 @@ public class GeneralConfig
/// If activated, by switching to the current workspace the previous focused workspace is activated.
/// </summary>
public bool ToggleWorkspaceOnRefocus { get; set; }
/// <summary>
/// Whether to enable window transition animations (on minimize, close, etc).
/// </summary>
public WindowAnimations WindowAnimations { get; set; } = WindowAnimations.Unchanged;
}
}
9 changes: 9 additions & 0 deletions GlazeWM.Domain/UserConfigs/WindowAnimations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GlazeWM.Domain.UserConfigs
{
public enum WindowAnimations
{
Unchanged,
True,
False
}
}
22 changes: 22 additions & 0 deletions GlazeWM.Infrastructure/WindowsApi/SystemSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;

namespace GlazeWM.Infrastructure.WindowsApi
{
public static class SystemSettings
{
/// <summary>
/// Modify global setting for whether window transition animations are enabled.
/// </summary>
public static void SetWindowAnimationsEnabled(bool enabled)
{
var animationInfo = AnimationInfo.Create(enabled);

SystemParametersInfo(
SystemParametersInfoFlags.SetAnimation,
animationInfo.CallbackSize,
ref animationInfo,
0
);
}
}
}
31 changes: 31 additions & 0 deletions GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,37 @@ public struct SystemPowerStatus
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr handle, uint attribute, ref uint value, uint size);

[StructLayout(LayoutKind.Sequential)]
public struct AnimationInfo
{
public uint CallbackSize;
public int MinAnimate;

public bool IsEnabled
{
readonly get => MinAnimate != 0;
set => MinAnimate = value ? 1 : 0;
}

public static AnimationInfo Create(bool isEnabled)
{
return new()
{
IsEnabled = isEnabled,
CallbackSize = (uint)Marshal.SizeOf(typeof(AnimationInfo))
};
}
}

public enum SystemParametersInfoFlags : uint
{
GetAnimation = 72,
SetAnimation = 73,
}

[DllImport("User32.dll", SetLastError = true)]
public static extern bool SystemParametersInfo(SystemParametersInfoFlags uiAction, uint uiParam, ref AnimationInfo pvParam, uint fWinIni);

[DllImport("kernel32.dll")]
internal static extern bool AttachConsole(uint dwProcessId);

Expand Down

0 comments on commit d675244

Please sign in to comment.