diff --git a/src/modules/colorPicker/ColorPickerUI.UnitTests/Mouse/DisplayRefreshRateTest.cs b/src/modules/colorPicker/ColorPickerUI.UnitTests/Mouse/DisplayRefreshRateTest.cs new file mode 100644 index 0000000000..58f6cc1237 --- /dev/null +++ b/src/modules/colorPicker/ColorPickerUI.UnitTests/Mouse/DisplayRefreshRateTest.cs @@ -0,0 +1,23 @@ +// 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 ColorPicker.Mouse; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ColorPicker.UnitTests.Mouse +{ + [TestClass] + public class DisplayRefreshRateTest + { + [TestMethod] + [DataRow(0, 60.0)] + [DataRow(1, 60.0)] + [DataRow(60, 60.0)] + [DataRow(144, 144.0)] + public void GetDisplayRefreshRateOrDefault_HandlesDefaultRefreshRateSentinels(int displayFrequency, double expectedRefreshRate) + { + Assert.AreEqual(expectedRefreshRate, MouseInfoProvider.GetDisplayRefreshRateOrDefault((uint)displayFrequency)); + } + } +} diff --git a/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs b/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs index 2aa4e273ad..c6c333a27b 100644 --- a/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs +++ b/src/modules/colorPicker/ColorPickerUI/Bootstrapper.cs @@ -7,6 +7,7 @@ using System.ComponentModel.Composition.Hosting; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("UnitTest-ColorPickerUI")] +[assembly: InternalsVisibleTo("ColorPickerUI.UnitTests")] namespace ColorPicker { diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs index 4d6596bc3f..e58bc3bc58 100644 --- a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs +++ b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseInfoProvider.cs @@ -21,6 +21,8 @@ namespace ColorPicker.Mouse [PartCreationPolicy(CreationPolicy.Shared)] public class MouseInfoProvider : IMouseInfoProvider { + private const double DefaultDisplayRefreshRate = 60.0; + private readonly double _mousePullInfoIntervalInMs; private readonly DispatcherTimer _timer = new DispatcherTimer(); private readonly MouseHook _mouseHook; @@ -123,13 +125,13 @@ namespace ColorPicker.Mouse private static double GetMainDisplayRefreshRate() { - double refreshRate = 60.0; + double refreshRate = DefaultDisplayRefreshRate; foreach (var monitor in MonitorResolutionHelper.AllMonitors) { if (monitor.IsPrimary && EnumDisplaySettingsW(monitor.Name, ENUM_CURRENT_SETTINGS, out DEVMODEW lpDevMode)) { - refreshRate = (double)lpDevMode.dmDisplayFrequency; + refreshRate = GetDisplayRefreshRateOrDefault(lpDevMode.dmDisplayFrequency); break; } } @@ -137,6 +139,10 @@ namespace ColorPicker.Mouse return refreshRate; } + // EnumDisplaySettings uses 0 and 1 to represent the hardware default refresh rate. + internal static double GetDisplayRefreshRateOrDefault(uint displayFrequency) + => displayFrequency > 1 ? displayFrequency : DefaultDisplayRefreshRate; + private void AppStateMonitor_AppClosed(object sender, EventArgs e) { DisposeHook();