From 83bb573223a2fb7e17c609ec82c175e434ba629d Mon Sep 17 00:00:00 2001 From: Laszlo Nemeth <57342539+donlaci@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:25:24 +0200 Subject: [PATCH] [Accessibility]Turn animations off based on Windows settings (#28128) * FindMyMouse: switch animations on/off based on global windows settings * Fancy Zones: enable/disable animations based on global Windows settings * Shortcut Guide: enabling/disabling animations based on global Windows settings * spell checker * Making MouseUtils settings dependent on global windows settings, AnimationEffects. If the global settings is disabled the MouseUtils animation settings is disabled too, description shows the reason. * Adding error detection, log on SystemParametersInfo call. * Adding infobar instead of changing description of the settingsbar. * spell checker * moving native constant into NativeMethods class --- .github/actions/spell-check/expect.txt | 1 + PowerToys.sln | 1 + src/common/utils/MsWindowsSettings.h | 13 +++++++++++++ .../MouseUtils/FindMyMouse/FindMyMouse.cpp | 3 +++ .../ShortcutGuide/overlay_window.cpp | 8 +++++--- .../fancyzones/FancyZonesLib/ZonesOverlay.cpp | 7 +++++++ .../SettingsXAML/Views/MouseUtilsPage.xaml | 12 ++++++++++-- .../Settings.UI/Strings/en-us/Resources.resw | 3 +++ .../Settings.UI/Utilities/NativeMethods.cs | 6 ++++++ .../ViewModels/MouseUtilsViewModel.cs | 19 +++++++++++++++++++ 10 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/common/utils/MsWindowsSettings.h diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index f86d415841..69f51bbaf8 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -619,6 +619,7 @@ gdi gdiplus GDISCALED GEmoji +GETCLIENTAREAANIMATION GETDESKWALLPAPER GETDLGCODE GETDPISCALEDSIZE diff --git a/PowerToys.sln b/PowerToys.sln index 01508db104..f0d4f78656 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -281,6 +281,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "utils", "utils", "{B39DC643 src\common\utils\logger_helper.h = src\common\utils\logger_helper.h src\common\utils\modulesRegistry.h = src\common\utils\modulesRegistry.h src\common\utils\MsiUtils.h = src\common\utils\MsiUtils.h + src\common\utils\MsWindowsSettings.h = src\common\utils\MsWindowsSettings.h src\common\utils\os-detect.h = src\common\utils\os-detect.h src\common\utils\package.h = src\common\utils\package.h src\common\utils\ProcessWaiter.h = src\common\utils\ProcessWaiter.h diff --git a/src/common/utils/MsWindowsSettings.h b/src/common/utils/MsWindowsSettings.h new file mode 100644 index 0000000000..ceb54e41c2 --- /dev/null +++ b/src/common/utils/MsWindowsSettings.h @@ -0,0 +1,13 @@ +#pragma once + +inline bool GetAnimationsEnabled() +{ + BOOL enabled = 0; + BOOL fResult; + fResult = SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &enabled, 0); + if (!fResult) + { + Logger::error("SystemParametersInfo SPI_GETCLIENTAREAANIMATION failed."); + } + return enabled; +} \ No newline at end of file diff --git a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp index f5f3ff2e00..29ab5419ec 100644 --- a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp +++ b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp @@ -7,6 +7,7 @@ #include "common/utils/game_mode.h" #include "common/utils/process_path.h" #include "common/utils/excluded_apps.h" +#include "common/utils/MsWindowsSettings.h" #include #ifdef COMPOSITION @@ -648,6 +649,8 @@ struct CompositionSpotlight : SuperSonar void SetSonarVisibility(bool visible) { m_batch = m_compositor.GetCommitBatch(winrt::CompositionBatchTypes::Animation); + BOOL isEnabledAnimations = GetAnimationsEnabled(); + m_animation.Duration(std::chrono::milliseconds{ isEnabledAnimations ? m_fadeDuration : 1 }); m_batch.Completed([hwnd = m_hwnd](auto&&, auto&&) { PostMessage(hwnd, WM_OPACITY_ANIMATION_COMPLETED, 0, 0); }); diff --git a/src/modules/ShortcutGuide/ShortcutGuide/overlay_window.cpp b/src/modules/ShortcutGuide/ShortcutGuide/overlay_window.cpp index 0a2c899e7d..a589da85e4 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/overlay_window.cpp +++ b/src/modules/ShortcutGuide/ShortcutGuide/overlay_window.cpp @@ -5,6 +5,7 @@ #include "start_visible.h" #include #include +#include #include "shortcut_guide.h" #include "trace.h" @@ -269,11 +270,12 @@ D2D1_RECT_F D2DOverlaySVG::get_snap_right() const D2DOverlayWindow::D2DOverlayWindow() : total_screen({}), - background_animation(0.3), - global_windows_shortcuts_animation(0.3), - taskbar_icon_shortcuts_animation(0.3), D2DWindow() { + BOOL isEnabledAnimations = GetAnimationsEnabled(); + background_animation = isEnabledAnimations? 0.3f : 0.f; + global_windows_shortcuts_animation = isEnabledAnimations ? 0.3f : 0.f; + taskbar_icon_shortcuts_animation = isEnabledAnimations ? 0.3f : 0.f; tasklist_thread = std::thread([&] { while (running) { diff --git a/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp b/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp index ada45b5d5c..d7c9b537fd 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp +++ b/src/modules/fancyzones/FancyZonesLib/ZonesOverlay.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace { @@ -125,6 +126,12 @@ ZonesOverlay::RenderResult ZonesOverlay::Render() return RenderResult::AnimationEnded; } + BOOL isEnabledAnimations = GetAnimationsEnabled(); + if (!isEnabledAnimations) + { + animationAlpha = 1.f; + } + m_renderTarget->BeginDraw(); // Draw backdrop diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseUtilsPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseUtilsPage.xaml index 4db60c56e4..db8db47282 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseUtilsPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseUtilsPage.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls" + xmlns:converters="using:Microsoft.PowerToys.Settings.UI.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:labs="using:CommunityToolkit.Labs.WinUI" xmlns:localConverters="using:Microsoft.PowerToys.Settings.UI.Converters" @@ -12,6 +13,8 @@ mc:Ignorable="d"> + - - + Time before the spotlight appears (ms) ms = milliseconds + + Animations are disabled by OS. See Settings > Accessibility > Visual effects + Shake minimum distance diff --git a/src/settings-ui/Settings.UI/Utilities/NativeMethods.cs b/src/settings-ui/Settings.UI/Utilities/NativeMethods.cs index 270a60451f..ae29cf35d1 100644 --- a/src/settings-ui/Settings.UI/Utilities/NativeMethods.cs +++ b/src/settings-ui/Settings.UI/Utilities/NativeMethods.cs @@ -22,5 +22,11 @@ namespace Microsoft.PowerToys.Settings.Utilities [System.Runtime.InteropServices.DllImport("User32.dll")] public static extern bool IsIconic(IntPtr handle); + + [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] + internal static extern bool SystemParametersInfo(int uiAction, int uiParam, ref int pvParam, int fWinIni); + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")] + public const int SPI_GETCLIENTAREAANIMATION = 0x1042; } } diff --git a/src/settings-ui/Settings.UI/ViewModels/MouseUtilsViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/MouseUtilsViewModel.cs index ebac1c6b35..0120fd3591 100644 --- a/src/settings-ui/Settings.UI/ViewModels/MouseUtilsViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/MouseUtilsViewModel.cs @@ -9,6 +9,7 @@ using global::PowerToys.GPOWrapper; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.Utilities; namespace Microsoft.PowerToys.Settings.UI.ViewModels { @@ -114,6 +115,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels _mousePointerCrosshairsFixedLength = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsFixedLength.Value; _mousePointerCrosshairsAutoActivate = MousePointerCrosshairsSettingsConfig.Properties.AutoActivate.Value; + int isEnabled = 0; + NativeMethods.SystemParametersInfo(NativeMethods.SPI_GETCLIENTAREAANIMATION, 0, ref isEnabled, 0); + _isAnimationEnabledBySystem = isEnabled != 0; + // set the callback functions value to handle outgoing IPC message. SendConfigMSG = ipcMSGCallBackFunc; } @@ -327,6 +332,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } + public bool IsAnimationEnabledBySystem + { + get + { + return _isAnimationEnabledBySystem; + } + + set + { + _isAnimationEnabledBySystem = value; + } + } + public int FindMyMouseAnimationDurationMs { get @@ -970,5 +988,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels private bool _mousePointerCrosshairsIsFixedLengthEnabled; private int _mousePointerCrosshairsFixedLength; private bool _mousePointerCrosshairsAutoActivate; + private bool _isAnimationEnabledBySystem; } }