From 45f121b8bc0e80b6ecd5d39a96576edea9846a07 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 4 Mar 2022 12:28:11 +0000 Subject: [PATCH] [FindMyMouse]setting for minimum shake distance (#16756) * [FindMyMouse]setting for minimum shake distance * Group inside Activation method --- .../MouseUtils/FindMyMouse/FindMyMouse.cpp | 10 +++- .../MouseUtils/FindMyMouse/FindMyMouse.h | 2 + .../MouseUtils/FindMyMouse/dllmain.cpp | 11 ++++ .../FindMyMouseProperties.cs | 4 ++ .../ViewModels/MouseUtilsViewModel.cs | 20 ++++++++ ...ationShakeMouseIntToVisibilityConverter.cs | 33 ++++++++++++ .../Settings.UI/Settings.UI.csproj | 1 + .../Settings.UI/Strings/en-us/Resources.resw | 6 +++ .../Settings.UI/Views/MouseUtilsPage.xaml | 51 ++++++++++++++----- 9 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 src/settings-ui/Settings.UI/Converters/FindMyMouseActivationShakeMouseIntToVisibilityConverter.cs diff --git a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp index 7eb5698fa5..450310b1a6 100644 --- a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp +++ b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp @@ -69,6 +69,7 @@ protected: DWORD m_fadeDuration = FIND_MY_MOUSE_DEFAULT_ANIMATION_DURATION_MS; int m_finalAlphaNumerator = FIND_MY_MOUSE_DEFAULT_OVERLAY_OPACITY; std::vector m_excludedApps; + int m_shakeMinimumDistance = FIND_MY_MOUSE_DEFAULT_SHAKE_MINIMUM_DISTANCE; static constexpr int FinalAlphaDenominator = 100; winrt::DispatcherQueueController m_dispatcherQueueController{ nullptr }; @@ -403,6 +404,11 @@ void SuperSonar::DetectShake() maxY = max(currentY, maxY); } + if (distanceTravelled < m_shakeMinimumDistance) + { + return; + } + // Size of the rectangle the pointer moved in. double rectangleWidth = (double)maxX - minX; double rectangleHeight = (double)maxY - minY; @@ -423,7 +429,7 @@ void SuperSonar::OnSonarMouseInput(RAWINPUT const& input) { LONG relativeX = 0; LONG relativeY = 0; - if ((input.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) == MOUSE_MOVE_ABSOLUTE) + if ((input.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) == MOUSE_MOVE_ABSOLUTE && (input.data.mouse.lLastX!=0 || input.data.mouse.lLastY!=0)) { // Getting absolute mouse coordinates. Likely inside a VM / RDP session. if (m_seenAnAbsoluteMousePosition) @@ -736,6 +742,7 @@ public: m_finalAlphaNumerator = settings.overlayOpacity; m_sonarZoomFactor = settings.spotlightInitialZoom; m_excludedApps = settings.excludedApps; + m_shakeMinimumDistance = settings.shakeMinimumDistance; } else { @@ -762,6 +769,7 @@ public: m_finalAlphaNumerator = localSettings.overlayOpacity; m_sonarZoomFactor = localSettings.spotlightInitialZoom; m_excludedApps = localSettings.excludedApps; + m_shakeMinimumDistance = localSettings.shakeMinimumDistance; UpdateMouseSnooping(); // For the shake mouse activation method // Apply new settings to runtime composition objects. diff --git a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.h b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.h index cb9650b585..bf70ee3279 100644 --- a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.h +++ b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.h @@ -16,6 +16,7 @@ constexpr int FIND_MY_MOUSE_DEFAULT_SPOTLIGHT_RADIUS = 100; constexpr int FIND_MY_MOUSE_DEFAULT_ANIMATION_DURATION_MS = 500; constexpr int FIND_MY_MOUSE_DEFAULT_SPOTLIGHT_INITIAL_ZOOM = 9; constexpr FindMyMouseActivationMethod FIND_MY_MOUSE_DEFAULT_ACTIVATION_METHOD = FindMyMouseActivationMethod::DoubleControlKey; +constexpr int FIND_MY_MOUSE_DEFAULT_SHAKE_MINIMUM_DISTANCE = 1000; struct FindMyMouseSettings { @@ -27,6 +28,7 @@ struct FindMyMouseSettings int spotlightRadius = FIND_MY_MOUSE_DEFAULT_SPOTLIGHT_RADIUS; int animationDurationMs = FIND_MY_MOUSE_DEFAULT_ANIMATION_DURATION_MS; int spotlightInitialZoom = FIND_MY_MOUSE_DEFAULT_SPOTLIGHT_INITIAL_ZOOM; + int shakeMinimumDistance = FIND_MY_MOUSE_DEFAULT_SHAKE_MINIMUM_DISTANCE; std::vector excludedApps; }; diff --git a/src/modules/MouseUtils/FindMyMouse/dllmain.cpp b/src/modules/MouseUtils/FindMyMouse/dllmain.cpp index c46f3797bd..39bd14e2ee 100644 --- a/src/modules/MouseUtils/FindMyMouse/dllmain.cpp +++ b/src/modules/MouseUtils/FindMyMouse/dllmain.cpp @@ -21,6 +21,7 @@ namespace const wchar_t JSON_KEY_ANIMATION_DURATION_MS[] = L"animation_duration_ms"; const wchar_t JSON_KEY_SPOTLIGHT_INITIAL_ZOOM[] = L"spotlight_initial_zoom"; const wchar_t JSON_KEY_EXCLUDED_APPS[] = L"excluded_apps"; + const wchar_t JSON_KEY_SHAKING_MINIMUM_DISTANCE[] = L"shaking_minimum_distance"; } extern "C" IMAGE_DOS_HEADER __ImageBase; @@ -300,6 +301,16 @@ void FindMyMouse::parse_settings(PowerToysSettings::PowerToyValues& settings) { Logger::warn("Failed to initialize Excluded Apps from settings. Will use default value"); } + try + { + // Parse Shaking Minimum Distance + auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_SHAKING_MINIMUM_DISTANCE); + findMyMouseSettings.shakeMinimumDistance = (UINT)jsonPropertiesObject.GetNamedNumber(JSON_KEY_VALUE); + } + catch (...) + { + Logger::warn("Failed to initialize Shaking Minimum Distance from settings. Will use default value"); + } } else { diff --git a/src/settings-ui/Settings.UI.Library/FindMyMouseProperties.cs b/src/settings-ui/Settings.UI.Library/FindMyMouseProperties.cs index 4c0a1d142c..d30b9307b8 100644 --- a/src/settings-ui/Settings.UI.Library/FindMyMouseProperties.cs +++ b/src/settings-ui/Settings.UI.Library/FindMyMouseProperties.cs @@ -35,6 +35,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library [JsonPropertyName("excluded_apps")] public StringProperty ExcludedApps { get; set; } + [JsonPropertyName("shaking_minimum_distance")] + public IntProperty ShakingMinimumDistance { get; set; } + public FindMyMouseProperties() { ActivationMethod = new IntProperty(0); @@ -46,6 +49,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library AnimationDurationMs = new IntProperty(500); SpotlightInitialZoom = new IntProperty(9); ExcludedApps = new StringProperty(); + ShakingMinimumDistance = new IntProperty(1000); } } } diff --git a/src/settings-ui/Settings.UI.Library/ViewModels/MouseUtilsViewModel.cs b/src/settings-ui/Settings.UI.Library/ViewModels/MouseUtilsViewModel.cs index a8325667fb..de646cd8f4 100644 --- a/src/settings-ui/Settings.UI.Library/ViewModels/MouseUtilsViewModel.cs +++ b/src/settings-ui/Settings.UI.Library/ViewModels/MouseUtilsViewModel.cs @@ -61,6 +61,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels _findMyMouseAnimationDurationMs = FindMyMouseSettingsConfig.Properties.AnimationDurationMs.Value; _findMyMouseSpotlightInitialZoom = FindMyMouseSettingsConfig.Properties.SpotlightInitialZoom.Value; _findMyMouseExcludedApps = FindMyMouseSettingsConfig.Properties.ExcludedApps.Value; + _findMyMouseShakingMinimumDistance = FindMyMouseSettingsConfig.Properties.ShakingMinimumDistance.Value; if (mouseHighlighterSettingsRepository == null) { @@ -285,6 +286,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels } } + public int FindMyMouseShakingMinimumDistance + { + get + { + return _findMyMouseShakingMinimumDistance; + } + + set + { + if (value != _findMyMouseShakingMinimumDistance) + { + _findMyMouseShakingMinimumDistance = value; + FindMyMouseSettingsConfig.Properties.ShakingMinimumDistance.Value = value; + NotifyFindMyMousePropertyChanged(); + } + } + } + public void NotifyFindMyMousePropertyChanged([CallerMemberName] string propertyName = null) { OnPropertyChanged(propertyName); @@ -633,6 +652,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels private int _findMyMouseAnimationDurationMs; private int _findMyMouseSpotlightInitialZoom; private string _findMyMouseExcludedApps; + private int _findMyMouseShakingMinimumDistance; private bool _isMouseHighlighterEnabled; private string _highlighterLeftButtonClickColor; diff --git a/src/settings-ui/Settings.UI/Converters/FindMyMouseActivationShakeMouseIntToVisibilityConverter.cs b/src/settings-ui/Settings.UI/Converters/FindMyMouseActivationShakeMouseIntToVisibilityConverter.cs new file mode 100644 index 0000000000..ac0cbbfa70 --- /dev/null +++ b/src/settings-ui/Settings.UI/Converters/FindMyMouseActivationShakeMouseIntToVisibilityConverter.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Data; + +namespace Microsoft.PowerToys.Settings.UI.Converters +{ + public sealed class FindMyMouseActivationShakeMouseIntToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, string language) + { + var activationShake = (int)value; + + // Assumes 1 is the index for the shake mouse option in the activation method combo box + if (activationShake == 1) + { + return Visibility.Visible; + } + else + { + return Visibility.Collapsed; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/settings-ui/Settings.UI/Settings.UI.csproj b/src/settings-ui/Settings.UI/Settings.UI.csproj index 2950e0ba06..0ac8aced5a 100644 --- a/src/settings-ui/Settings.UI/Settings.UI.csproj +++ b/src/settings-ui/Settings.UI/Settings.UI.csproj @@ -125,6 +125,7 @@ + diff --git a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw index 83c70fe8ef..e06a495fab 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -1825,6 +1825,12 @@ From there, simply click on one of the supported files in the File Explorer and Time before the spotlight appears (ms) ms = milliseconds + + Shake minimum distance + + + The minimum distance for mouse shaking activation, for adjusting sensitivity + Mouse Highlighter Refers to the utility name diff --git a/src/settings-ui/Settings.UI/Views/MouseUtilsPage.xaml b/src/settings-ui/Settings.UI/Views/MouseUtilsPage.xaml index 1f1d9aa6e6..ed8dfd91ed 100644 --- a/src/settings-ui/Settings.UI/Views/MouseUtilsPage.xaml +++ b/src/settings-ui/Settings.UI/Views/MouseUtilsPage.xaml @@ -7,8 +7,11 @@ mc:Ignorable="d" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls" + xmlns:localConverters="using:Microsoft.PowerToys.Settings.UI.Converters" AutomationProperties.LandmarkType="Main"> - + + + @@ -22,24 +25,46 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + -