Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Get friendly name for monitors
Browse files Browse the repository at this point in the history
Uses a new API introduced in Windows 10 version 1803 to get a friendly name for the monitors.
  • Loading branch information
johningve committed Aug 16, 2018
1 parent c286325 commit bed6d81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 13 additions & 2 deletions Source/Monitorian/Models/Monitor/DeviceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.Devices.Display;

namespace Monitorian.Models.Monitor
{
Expand Down Expand Up @@ -121,16 +122,21 @@ public class DeviceItem
[DataMember(Order = 3)]
public byte MonitorIndex { get; private set; }

[DataMember(Order = 4)]
public string FriendlyName { get; private set; }

public DeviceItem(
string deviceInstanceId,
string description,
byte displayIndex,
byte monitorIndex)
byte monitorIndex,
string friendlyName)
{
this.DeviceInstanceId = deviceInstanceId;
this.Description = description;
this.DisplayIndex = displayIndex;
this.MonitorIndex = monitorIndex;
this.FriendlyName = friendlyName;
}
}

Expand Down Expand Up @@ -182,11 +188,16 @@ public static IEnumerable<DeviceItem> EnumerateMonitorDevices()
if (!isActive)
continue;

var displayMonitorTask = DisplayMonitor.FromIdAsync(deviceInstanceId).AsTask();
displayMonitorTask.Wait();
var displayMonitor = displayMonitorTask.Result;

yield return new DeviceItem(
deviceInstanceId: deviceInstanceId,
description: monitor.DeviceString,
displayIndex: displayIndex,
monitorIndex: monitorIndex);
monitorIndex: monitorIndex,
friendlyName: displayMonitor.DisplayName);

monitorIndex++;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Monitorian/Models/Monitor/MonitorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static IEnumerable<IMonitor> EnumerateMonitors()
var deviceItem = deviceItems[index];
yield return new DdcMonitorItem(
deviceInstanceId: deviceItem.DeviceInstanceId,
description: deviceItem.Description,
description: deviceItem.FriendlyName,
displayIndex: deviceItem.DisplayIndex,
monitorIndex: deviceItem.MonitorIndex,
handle: physicalItem.Handle,
Expand Down Expand Up @@ -71,7 +71,7 @@ public static IEnumerable<IMonitor> EnumerateMonitors()
var deviceItem = deviceItems[index];
yield return new WmiMonitorItem(
deviceInstanceId: deviceItem.DeviceInstanceId,
description: deviceItem.Description,
description: deviceItem.FriendlyName,
displayIndex: deviceItem.DisplayIndex,
monitorIndex: deviceItem.MonitorIndex,
brightnessLevels: desktopItem.BrightnessLevels,
Expand All @@ -88,7 +88,7 @@ public static IEnumerable<IMonitor> EnumerateMonitors()
{
yield return new InaccessibleMonitorItem(
deviceInstanceId: deviceItem.DeviceInstanceId,
description: deviceItem.Description,
description: deviceItem.FriendlyName,
displayIndex: deviceItem.DisplayIndex,
monitorIndex: deviceItem.MonitorIndex);
}
Expand Down
8 changes: 8 additions & 0 deletions Source/Monitorian/Monitorian.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml" />
Expand All @@ -68,6 +72,10 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand Down

0 comments on commit bed6d81

Please sign in to comment.