settings: get "reduced motion" setting from WinApi

This commit is contained in:
goaaats 2024-03-20 22:14:24 +01:00
parent 95defa200f
commit f9847398d2
5 changed files with 62 additions and 5 deletions

View file

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Game.Text;
using Dalamud.Interface.FontIdentifier;
@ -370,7 +372,7 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
/// <summary>
/// Gets or sets a value indicating whether to reduce motions (animations).
/// </summary>
public bool ReduceMotions { get; set; } = false;
public bool? ReduceMotions { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not market board data should be uploaded.
@ -486,6 +488,15 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
deserialized ??= new DalamudConfiguration();
deserialized.configPath = path;
try
{
deserialized.SetDefaults();
}
catch (Exception e)
{
Log.Error(e, "Failed to set defaults for DalamudConfiguration");
}
return deserialized;
}
@ -527,6 +538,31 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
}
}
private void SetDefaults()
{
// "Reduced motion"
if (!this.ReduceMotions.HasValue)
{
// https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/animation/animation_win.cc;l=29?q=ReducedMotion&ss=chromium
var winAnimEnabled = 0;
var success = NativeFunctions.SystemParametersInfo(
(uint)NativeFunctions.AccessibilityParameter.SPI_GETCLIENTAREAANIMATION,
0,
ref winAnimEnabled,
0);
if (!success)
{
Log.Warning("Failed to get Windows animation setting, assuming reduced motion is off (GetLastError: {GetLastError:X})", Marshal.GetLastPInvokeError());
this.ReduceMotions = false;
}
else
{
this.ReduceMotions = winAnimEnabled == 0;
}
}
}
private void Save()
{
ThreadSafety.AssertMainThread();