mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
settings: get "reduced motion" setting from WinApi
This commit is contained in:
parent
95defa200f
commit
f9847398d2
5 changed files with 62 additions and 5 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
using Dalamud.Interface.FontIdentifier;
|
using Dalamud.Interface.FontIdentifier;
|
||||||
|
|
@ -370,7 +372,7 @@ internal sealed class DalamudConfiguration : IInternalDisposableService
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether to reduce motions (animations).
|
/// Gets or sets a value indicating whether to reduce motions (animations).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ReduceMotions { get; set; } = false;
|
public bool? ReduceMotions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether or not market board data should be uploaded.
|
/// 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 ??= new DalamudConfiguration();
|
||||||
deserialized.configPath = path;
|
deserialized.configPath = path;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deserialized.SetDefaults();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "Failed to set defaults for DalamudConfiguration");
|
||||||
|
}
|
||||||
|
|
||||||
return deserialized;
|
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()
|
private void Save()
|
||||||
{
|
{
|
||||||
ThreadSafety.AssertMainThread();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
|
||||||
|
|
@ -456,7 +456,7 @@ internal sealed partial class ActiveNotification
|
||||||
|
|
||||||
private void DrawExpiryPie(bool warrantsExtension, Vector2 offset, Vector2 size)
|
private void DrawExpiryPie(bool warrantsExtension, Vector2 offset, Vector2 size)
|
||||||
{
|
{
|
||||||
if (!Service<DalamudConfiguration>.Get().ReduceMotions)
|
if (!Service<DalamudConfiguration>.Get().ReduceMotions ?? false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// circle here; 0 means 0deg; 1 means 360deg
|
// circle here; 0 means 0deg; 1 means 360deg
|
||||||
|
|
@ -536,7 +536,7 @@ internal sealed partial class ActiveNotification
|
||||||
|
|
||||||
private void DrawExpiryBar(bool warrantsExtension)
|
private void DrawExpiryBar(bool warrantsExtension)
|
||||||
{
|
{
|
||||||
if (Service<DalamudConfiguration>.Get().ReduceMotions)
|
if (Service<DalamudConfiguration>.Get().ReduceMotions ?? false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float barL, barR;
|
float barL, barR;
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ internal sealed partial class ActiveNotification : IActiveNotification
|
||||||
set => this.newProgress = value;
|
set => this.newProgress = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ReducedMotions => Service<DalamudConfiguration>.Get().ReduceMotions;
|
private static bool ReducedMotions => Service<DalamudConfiguration>.Get().ReduceMotions ?? false;
|
||||||
|
|
||||||
/// <summary>Gets the eased progress.</summary>
|
/// <summary>Gets the eased progress.</summary>
|
||||||
private float ProgressEased
|
private float ProgressEased
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ public class SettingsTabLook : SettingsTab
|
||||||
new SettingsEntry<bool>(
|
new SettingsEntry<bool>(
|
||||||
Loc.Localize("DalamudSettingReducedMotion", "Reduce motions"),
|
Loc.Localize("DalamudSettingReducedMotion", "Reduce motions"),
|
||||||
Loc.Localize("DalamudSettingReducedMotion", "This will suppress certain animations from Dalamud, such as the notification popup."),
|
Loc.Localize("DalamudSettingReducedMotion", "This will suppress certain animations from Dalamud, such as the notification popup."),
|
||||||
c => c.ReduceMotions,
|
c => c.ReduceMotions ?? false,
|
||||||
(v, c) => c.ReduceMotions = v),
|
(v, c) => c.ReduceMotions = v),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -826,6 +826,27 @@ internal static partial class NativeFunctions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint Timeout;
|
public uint Timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parameters for use with SystemParametersInfo.
|
||||||
|
/// </summary>
|
||||||
|
public enum AccessibilityParameter
|
||||||
|
{
|
||||||
|
#pragma warning disable SA1602
|
||||||
|
SPI_GETCLIENTAREAANIMATION = 0x1042,
|
||||||
|
#pragma warning restore SA1602
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves or sets the value of one of the system-wide parameters. This function can also update the user profile while setting a parameter.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uiAction">The system-wide parameter to be retrieved or set.</param>
|
||||||
|
/// <param name="uiParam">A parameter whose usage and format depends on the system parameter being queried or set.</param>
|
||||||
|
/// <param name="pvParam">A parameter whose usage and format depends on the system parameter being queried or set. If not otherwise indicated, you must specify zero for this parameter.</param>
|
||||||
|
/// <param name="fWinIni">If a system parameter is being set, specifies whether the user profile is to be updated, and if so, whether the WM_SETTINGCHANGE message is to be broadcast to all top-level windows to notify them of the change.</param>
|
||||||
|
/// <returns>If the function succeeds, the return value is a nonzero value.</returns>
|
||||||
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue