diff --git a/Source/IconImage/App.config b/Source/IconImage/App.config index 3a4868fb..73b295be 100644 --- a/Source/IconImage/App.config +++ b/Source/IconImage/App.config @@ -1,6 +1,6 @@ - + - - - - \ No newline at end of file + + + + diff --git a/Source/IconImage/IconImage.csproj b/Source/IconImage/IconImage.csproj index 1c5a0f45..94ea7ee2 100644 --- a/Source/IconImage/IconImage.csproj +++ b/Source/IconImage/IconImage.csproj @@ -9,7 +9,8 @@ Properties IconImage IconImage - v4.6.2 + v4.7.2 + 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 diff --git a/Source/IconImage/Properties/Resources.Designer.cs b/Source/IconImage/Properties/Resources.Designer.cs index e236d0c3..f3aad43c 100644 --- a/Source/IconImage/Properties/Resources.Designer.cs +++ b/Source/IconImage/Properties/Resources.Designer.cs @@ -8,64 +8,56 @@ // //------------------------------------------------------------------------------ -namespace IconImage.Properties -{ - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("IconImage.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } +namespace IconImage.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("IconImage.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } } diff --git a/Source/IconImage/Properties/Settings.Designer.cs b/Source/IconImage/Properties/Settings.Designer.cs index 68af65e4..3cef0a69 100644 --- a/Source/IconImage/Properties/Settings.Designer.cs +++ b/Source/IconImage/Properties/Settings.Designer.cs @@ -8,23 +8,19 @@ // //------------------------------------------------------------------------------ -namespace IconImage.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } +namespace IconImage.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } } diff --git a/Source/Installer/Product.wxs b/Source/Installer/Product.wxs index 4db31b9a..77ac3867 100644 --- a/Source/Installer/Product.wxs +++ b/Source/Installer/Product.wxs @@ -1,6 +1,6 @@  - Properties Monitorian.Supplement Monitorian.Supplement - v4.6.2 + v4.7.2 + 10.0.17134.0 10.0.17134.0 512 diff --git a/Source/Monitorian.Test/Monitorian.Test.csproj b/Source/Monitorian.Test/Monitorian.Test.csproj index 7dd5be54..81ca770d 100644 --- a/Source/Monitorian.Test/Monitorian.Test.csproj +++ b/Source/Monitorian.Test/Monitorian.Test.csproj @@ -10,7 +10,8 @@ Properties Monitorian.Test Monitorian.Test - v4.6.2 + v4.7.2 + 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15.0 @@ -18,8 +19,6 @@ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest - - true diff --git a/Source/Monitorian/App.config b/Source/Monitorian/App.config index 3d45803f..cc5ac077 100644 --- a/Source/Monitorian/App.config +++ b/Source/Monitorian/App.config @@ -1,12 +1,12 @@ - + - + - + - + - \ No newline at end of file + diff --git a/Source/Monitorian/Models/Monitor/DdcMonitorItem.cs b/Source/Monitorian/Models/Monitor/DdcMonitorItem.cs index c1fe702d..f652957e 100644 --- a/Source/Monitorian/Models/Monitor/DdcMonitorItem.cs +++ b/Source/Monitorian/Models/Monitor/DdcMonitorItem.cs @@ -34,12 +34,24 @@ public DdcMonitorItem( private readonly object _lock = new object(); + private uint _minimum = 0; // Raw minimum brightness (not always 0) + private uint _maximum = 100; // Raw maximum brightness (not always 100) + public override bool UpdateBrightness(int brightness = -1) { lock (_lock) { - this.Brightness = MonitorConfiguration.GetBrightness(_handle, _useLowLevel); - return (0 <= this.Brightness); + var (success, minimum, current, maximum) = MonitorConfiguration.GetBrightness(_handle, _useLowLevel); + + if (!success || !(minimum < maximum) || !(minimum <= current) || !(current <= maximum)) + { + this.Brightness = -1; + return false; + } + this.Brightness = (int)Math.Round((double)(current - minimum) / (maximum - minimum) * 100D, MidpointRounding.AwayFromZero); + this._minimum = minimum; + this._maximum = maximum; + return true; } } @@ -50,7 +62,9 @@ public override bool SetBrightness(int brightness) lock (_lock) { - if (MonitorConfiguration.SetBrightness(_handle, brightness, _useLowLevel)) + var buffer = (uint)Math.Round(brightness / 100D * (_maximum - _minimum) + _minimum, MidpointRounding.AwayFromZero); + + if (MonitorConfiguration.SetBrightness(_handle, buffer, _useLowLevel)) { this.Brightness = brightness; return true; diff --git a/Source/Monitorian/Models/Monitor/MonitorConfiguration.cs b/Source/Monitorian/Models/Monitor/MonitorConfiguration.cs index cb399822..a978790a 100644 --- a/Source/Monitorian/Models/Monitor/MonitorConfiguration.cs +++ b/Source/Monitorian/Models/Monitor/MonitorConfiguration.cs @@ -329,15 +329,32 @@ IEnumerable EnumerateCodes() } } - public static int GetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle, bool useLowLevel = false) + /// + /// Gets raw brightnesses not represented in percentage. + /// + /// Physical monitor handle + /// Whether to use low level function + /// + /// success: True if successfully got + /// minimum: Raw minimum brightness (not always 0) + /// current: Raw current brightness (not always 0 to 100) + /// maximum: Raw maximum brightness (not always 100) + /// + /// + /// Raw minimum and maximum brightnesses will become meaningful when they are not standard + /// values (0 and 100) and so raw current brightness needs to be converted to brightness + /// in percentage using those values. They are used to convert brightness in percentage + /// back to raw brightness when settings brightness as well. + /// + public static (bool success, uint minimum, uint current, uint maximum) GetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle, bool useLowLevel = false) { if (physicalMonitorHandle is null) throw new ArgumentNullException(nameof(physicalMonitorHandle)); if (physicalMonitorHandle.IsClosed) { - Debug.WriteLine("Failed to get brightness. The physical monitor handle has been closed."); - return -1; + Debug.WriteLine("Failed to get brightnesses. The physical monitor handle has been closed."); + return (success: false, 0, 0, 0); } if (!useLowLevel) @@ -348,33 +365,44 @@ public static int GetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle, out uint currentBrightness, out uint maximumBrightness)) { - Debug.WriteLine($"Failed to get brightness. {Error.CreateMessage()}"); - return -1; + Debug.WriteLine($"Failed to get brightnesses. {Error.CreateMessage()}"); + return (success: false, 0, 0, 0); } - return (int)currentBrightness; + return (success: true, + minimum: minimumBrightness, + current: currentBrightness, + maximum: maximumBrightness); } else { if (!GetVCPFeatureAndVCPFeatureReply( physicalMonitorHandle, LuminanceCode, - out LPMC_VCP_CODE_TYPE _, + out _, out uint currentValue, out uint maximumValue)) { - Debug.WriteLine($"Failed to get brightness (Low level). {Error.CreateMessage()}"); - return -1; + Debug.WriteLine($"Failed to get brightnesses (Low level). {Error.CreateMessage()}"); + return (success: false, 0, 0, 0); } - return (int)currentValue; + return (success: true, + minimum: 0, + current: currentValue, + maximum: maximumValue); } } - public static bool SetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle, int brightness, bool useLowLevel = false) + /// + /// Sets raw brightness not represented in percentage. + /// + /// Physical monitor handle + /// Raw brightness (not always 0 to 100) + /// Whether to use low level function + /// True if successfully set + public static bool SetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle, uint brightness, bool useLowLevel = false) { if (physicalMonitorHandle is null) throw new ArgumentNullException(nameof(physicalMonitorHandle)); - if ((brightness < 0) || (100 < brightness)) - throw new ArgumentOutOfRangeException(nameof(brightness), $"{nameof(brightness)} must be in the range of 0 to 100."); if (physicalMonitorHandle.IsClosed) { @@ -386,7 +414,7 @@ public static bool SetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle { if (!SetMonitorBrightness( physicalMonitorHandle, - (uint)brightness)) + brightness)) { Debug.WriteLine($"Failed to set brightness. {Error.CreateMessage()}"); return false; @@ -397,7 +425,7 @@ public static bool SetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle if (!SetVCPFeature( physicalMonitorHandle, LuminanceCode, - (uint)brightness)) + brightness)) { Debug.WriteLine($"Failed to set brightness (Low level). {Error.CreateMessage()}"); return false; diff --git a/Source/Monitorian/Monitorian.csproj b/Source/Monitorian/Monitorian.csproj index 0464d3a9..3d0a5aee 100644 --- a/Source/Monitorian/Monitorian.csproj +++ b/Source/Monitorian/Monitorian.csproj @@ -9,7 +9,8 @@ Properties Monitorian Monitorian - v4.6.2 + v4.7.2 + 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 diff --git a/Source/Monitorian/Properties/AssemblyInfo.cs b/Source/Monitorian/Properties/AssemblyInfo.cs index 51381d51..0180f0b5 100644 --- a/Source/Monitorian/Properties/AssemblyInfo.cs +++ b/Source/Monitorian/Properties/AssemblyInfo.cs @@ -51,8 +51,8 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.11.0.0")] -[assembly: AssemblyFileVersion("1.11.0.0")] +[assembly: AssemblyVersion("1.12.0.0")] +[assembly: AssemblyFileVersion("1.12.0.0")] [assembly: Guid("9e001d5b-6d18-48ba-a1d9-f1e2410a52d3")] // For unit test diff --git a/Source/Monitorian/Properties/Settings.Designer.cs b/Source/Monitorian/Properties/Settings.Designer.cs index e39f6242..e3f5cd0d 100644 --- a/Source/Monitorian/Properties/Settings.Designer.cs +++ b/Source/Monitorian/Properties/Settings.Designer.cs @@ -8,23 +8,19 @@ // //------------------------------------------------------------------------------ -namespace Monitorian.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } +namespace Monitorian.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } } diff --git a/Source/ScreenFrame/ScreenFrame.csproj b/Source/ScreenFrame/ScreenFrame.csproj index 023e7a38..e0a6ed0c 100644 --- a/Source/ScreenFrame/ScreenFrame.csproj +++ b/Source/ScreenFrame/ScreenFrame.csproj @@ -9,7 +9,8 @@ Properties ScreenFrame ScreenFrame - v4.6.2 + v4.7.2 + 512 diff --git a/Source/StartupAgency/StartupAgency.csproj b/Source/StartupAgency/StartupAgency.csproj index 6bc3845f..9088c224 100644 --- a/Source/StartupAgency/StartupAgency.csproj +++ b/Source/StartupAgency/StartupAgency.csproj @@ -9,7 +9,8 @@ Properties StartupAgency StartupAgency - v4.6.2 + v4.7.2 + 512 @@ -33,7 +34,7 @@ bin\Unlimited\ - TRACE + TRACE true pdbonly AnyCPU diff --git a/Source/StartupBridge/StartupBridge.csproj b/Source/StartupBridge/StartupBridge.csproj index 323151db..3d309193 100644 --- a/Source/StartupBridge/StartupBridge.csproj +++ b/Source/StartupBridge/StartupBridge.csproj @@ -9,7 +9,8 @@ Properties StartupBridge StartupBridge - v4.6.2 + v4.7.2 + 10.0.17134.0 10.0.14393.0 512