Skip to content

Commit 71f0782

Browse files
authored
Merge pull request #589 from emoacht/develop
Develop
2 parents b9f3ae8 + a4e824a commit 71f0782

File tree

9 files changed

+75
-15
lines changed

9 files changed

+75
-15
lines changed

Source/Installer/Product.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3-
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.6.11"
3+
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.6.12"
44
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
55
<Package Id="*" InstallerVersion="500" Compressed="yes"
66
InstallScope="perMachine" InstallPrivileges="elevated"

Source/Monitorian.Core/Models/Monitor/DisplayConfig.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ private static extern int QueryDisplayConfig(
3232
private static extern int DisplayConfigGetDeviceInfo(
3333
ref DISPLAYCONFIG_TARGET_DEVICE_NAME requestPacket);
3434

35+
[DllImport("User32.dll")]
36+
private static extern int DisplayConfigGetDeviceInfo(
37+
ref DISPLAYCONFIG_SOURCE_DEVICE_NAME requestPacket);
38+
3539
// All derived from wingdi.h
3640
[StructLayout(LayoutKind.Sequential)]
3741
private struct DISPLAYCONFIG_PATH_INFO
@@ -80,6 +84,15 @@ private struct DISPLAYCONFIG_TARGET_DEVICE_NAME
8084
public string monitorDevicePath;
8185
}
8286

87+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
88+
private struct DISPLAYCONFIG_SOURCE_DEVICE_NAME
89+
{
90+
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
91+
92+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
93+
public string viewGdiDeviceName;
94+
}
95+
8396
[StructLayout(LayoutKind.Sequential)]
8497
private struct DISPLAYCONFIG_PATH_SOURCE_INFO
8598
{

Source/Monitorian.Core/Models/Monitor/DisplayMonitorProvider.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
35
using System.Runtime.Serialization;
46
using System.Threading.Tasks;
57
using System.Windows;
8+
using Windows.Devices.Display.Core;
69

710
namespace Monitorian.Core.Models.Monitor;
811

@@ -147,6 +150,21 @@ public static async Task<DisplayItem[]> GetDisplayMonitorsAsync()
147150
isInternal: (displayMonitor.ConnectionKind == Windows.Devices.Display.DisplayMonitorConnectionKind.Internal),
148151
connectionDescription: GetConnectionDescription(displayMonitor.ConnectionKind, displayMonitor.PhysicalConnector)));
149152
}
153+
154+
#if DEBUG
155+
using var manager = DisplayManager.Create(DisplayManagerOptions.None);
156+
var state = manager.TryReadCurrentStateForAllTargets().State;
157+
foreach (var target in state.Views
158+
.SelectMany(x => x.Paths)
159+
.Select(x => x.Target)
160+
.Where(x => x.IsConnected))
161+
{
162+
var displayMonitor = target.TryGetMonitor();
163+
var deviceInstanceId = DeviceConversion.ConvertToDeviceInstanceId(displayMonitor.DeviceId);
164+
Debug.Assert(items.Any(x => x.DeviceInstanceId == deviceInstanceId));
165+
}
166+
#endif
167+
150168
return items.ToArray();
151169
}
152170
}

Source/Monitorian.Core/Models/Monitor/MonitorManager.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,31 @@ private static HashSet<string> GetOptionIds(string option)
7272
#endregion
7373

7474
private static HashSet<string> _foundIds;
75+
private static bool _isDisplayMonitorAvailable = true; // Default
76+
77+
private static async Task<DisplayMonitorProvider.DisplayItem[]> GetDisplayMonitorsAsync()
78+
{
79+
if (OsVersion.Is10Build17134OrGreater && _isDisplayMonitorAvailable)
80+
{
81+
try
82+
{
83+
return await DisplayMonitorProvider.GetDisplayMonitorsAsync();
84+
}
85+
catch (FileNotFoundException)
86+
{
87+
_isDisplayMonitorAvailable = false;
88+
}
89+
}
90+
return null;
91+
}
7592

7693
public static async Task<IEnumerable<IMonitor>> EnumerateMonitorsAsync(TimeSpan timeout, CancellationToken cancellationToken = default)
7794
{
7895
var deviceItems = DeviceContext.EnumerateMonitorDevices().ToArray();
7996
_foundIds = new HashSet<string>(deviceItems.Select(x => x.DeviceInstanceId));
8097

81-
IDisplayItem[] displayItems = OsVersion.Is10Build17134OrGreater
82-
? await DisplayMonitorProvider.GetDisplayMonitorsAsync()
83-
: DisplayConfig.EnumerateDisplayConfigs().ToArray();
98+
IDisplayItem[] displayItems = await GetDisplayMonitorsAsync();
99+
displayItems ??= DisplayConfig.EnumerateDisplayConfigs().ToArray();
84100

85101
IEnumerable<BasicItem> EnumerateBasicItems()
86102
{
@@ -341,10 +357,7 @@ public async Task PopulateAsync()
341357
DeviceItems = DeviceContext.EnumerateMonitorDevices().ToArray()),
342358

343359
GetTask(nameof(DisplayMonitorItems), async () =>
344-
{
345-
if (OsVersion.Is10Build17134OrGreater)
346-
DisplayMonitorItems = await DisplayMonitorProvider.GetDisplayMonitorsAsync();
347-
}),
360+
DisplayMonitorItems = await GetDisplayMonitorsAsync()),
348361

349362
GetTask(nameof(DisplayConfigItems), () =>
350363
DisplayConfigItems = DisplayConfig.EnumerateDisplayConfigs().ToArray()),

Source/Monitorian.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("4.6.11.0")]
37-
[assembly: AssemblyFileVersion("4.6.11.0")]
36+
[assembly: AssemblyVersion("4.6.12.0")]
37+
[assembly: AssemblyFileVersion("4.6.12.0")]
3838
[assembly: NeutralResourcesLanguage("en-US")]
3939

4040
// For unit test

Source/Monitorian.Core/ViewModels/MonitorViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void DecrementContrast(int tickSize)
351351
SetContrast(contrast);
352352
}
353353

354-
private bool SetContrast(int contrast)
354+
public bool SetContrast(int contrast)
355355
{
356356
contrast = Math.Min(100, Math.Max(0, contrast));
357357

Source/Monitorian/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("4.6.11.0")]
55-
[assembly: AssemblyFileVersion("4.6.11.0")]
54+
[assembly: AssemblyVersion("4.6.12.0")]
55+
[assembly: AssemblyFileVersion("4.6.12.0")]
5656
[assembly: Guid("a4cc5362-9b08-465b-ad64-5cfabc72a4c7")]
5757
[assembly: NeutralResourcesLanguage("en-US")]

Source/ScreenFrame/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("4.6.5.0")]
37-
[assembly: AssemblyFileVersion("4.6.5.0")]
36+
[assembly: AssemblyVersion("4.6.12.0")]
37+
[assembly: AssemblyFileVersion("4.6.12.0")]
3838
[assembly: NeutralResourcesLanguage("en-US")]

Source/ScreenFrame/VisualTreeHelperAddition.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Runtime.InteropServices;
45
using System.Windows;
56
using System.Windows.Interop;
@@ -67,6 +68,11 @@ private enum MONITOR_DPI_TYPE
6768
MDT_Default = MDT_Effective_DPI
6869
}
6970

71+
[DllImport("Shcore.dll")]
72+
private static extern int GetScaleFactorForMonitor(
73+
IntPtr hMon,
74+
out uint pScale);
75+
7076
#endregion
7177

7278
#region DPI
@@ -196,6 +202,16 @@ private static DpiScale GetDpi(IntPtr monitorHandle)
196202
if (result != S_OK)
197203
return SystemDpi;
198204

205+
#if DEBUG
206+
result = GetScaleFactorForMonitor(
207+
monitorHandle,
208+
out uint factor);
209+
if (result == S_OK)
210+
{
211+
Debug.Assert(factor == (dpiX / DefaultPixelsPerInch * 100));
212+
}
213+
#endif
214+
199215
return new DpiScale(dpiX / DefaultPixelsPerInch, dpiY / DefaultPixelsPerInch);
200216
}
201217

0 commit comments

Comments
 (0)