Skip to content

Commit

Permalink
add copy config button
Browse files Browse the repository at this point in the history
  • Loading branch information
mgth committed Jan 11, 2018
1 parent 0658340 commit a481d2b
Show file tree
Hide file tree
Showing 19 changed files with 542 additions and 28 deletions.
1 change: 1 addition & 0 deletions HLab/Notify-4/HLab.Notify.4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
Expand Down
2 changes: 2 additions & 0 deletions HLab/Notify-4/NotifierObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -12,6 +13,7 @@ public interface INotifierObject : INotifyPropertyChanged
Notifier Notifier { get; }
}

[DataContract]
public class NotifierObject : INotifierObject
{
public event PropertyChangedEventHandler PropertyChanged
Expand Down
12 changes: 12 additions & 0 deletions HLab/Windows.Monitors/DisplayDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
using HLab.Notify;
using HLab.Windows.API;
using Microsoft.Win32;
using Newtonsoft.Json;

namespace HLab.Windows.Monitors
{
Expand Down Expand Up @@ -102,17 +103,23 @@ public void Init(DisplayDevice parent, NativeMethods.DISPLAY_DEVICE dev, IList<D
}
}

[JsonProperty]
[TriggedOn(nameof(State))]
public bool AttachedToDesktop =>
this.Get(() => (State & NativeMethods.DisplayDeviceStateFlags.AttachedToDesktop) != 0);


[JsonProperty]
public ObservableCollection<DisplayMode> DisplayModes =>
this.Get(() => new ObservableCollection<DisplayMode>());


[JsonProperty]
public DeviceCaps DeviceCaps =>
this.Get(() => new DeviceCaps(DeviceName));


[JsonProperty]
public DisplayMode CurrentMode => this.Get(() =>
{
NativeMethods.DEVMODE devmode = new NativeMethods.DEVMODE(true);
Expand All @@ -137,6 +144,7 @@ public void UpdateDevMode()
}
}

[JsonProperty]
public string DeviceName
{
get => this.Get<string>();
Expand All @@ -158,24 +166,28 @@ public DisplayDevice Parent
protected set => this.Set(value);
}

[JsonProperty]
public string DeviceString
{
get => this.Get<string>();
protected set => this.Set(value ?? "");
}

[JsonProperty]
public NativeMethods.DisplayDeviceStateFlags State
{
get => this.Get<NativeMethods.DisplayDeviceStateFlags>();
protected set => this.Set(value);
}

[JsonProperty]
public string DeviceId
{
get => this.Get<string>();
protected set => this.Set(value);
}

[JsonProperty]
public string DeviceKey
{
get => this.Get<string>();
Expand Down
8 changes: 8 additions & 0 deletions HLab/Windows.Monitors/DisplayMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ You should have received a copy of the GNU General Public License
*/
using System.Windows;
using HLab.Windows.API;
using Newtonsoft.Json;

namespace HLab.Windows.Monitors
{
public class DisplayMode
{
[JsonProperty]
public Point Position { get; }
[JsonProperty]
public int BitsPerPixel { get; }
[JsonProperty]
public Size Pels { get; }
[JsonProperty]
public int DisplayFlags { get; }
[JsonProperty]
public int DisplayFrequency { get; }
[JsonProperty]
public int DisplayFixedOutput { get; }
[JsonProperty]
public int DisplayOrientation { get; }
public DisplayMode(NativeMethods.DEVMODE devmode)
{
Expand Down
4 changes: 4 additions & 0 deletions HLab/Windows.Monitors/HLab.Windows.Monitors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.11.0.1-beta3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
Expand Down Expand Up @@ -117,6 +120,7 @@
</ItemGroup>
<ItemGroup>
<None Include="lbm.licenseheader" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Page Include="DispalyChangesView.xaml">
Expand Down
112 changes: 107 additions & 5 deletions HLab/Windows.Monitors/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using HLab.Notify;
using HLab.Windows.API;
using Microsoft.Win32;
using Newtonsoft.Json;

namespace HLab.Windows.Monitors
{
Expand All @@ -25,33 +26,40 @@ public MonitorsService Service
private set => this.Set(value);
}

[JsonProperty]
public string DeviceKey
{
get => this.Get<string>();
internal set => this.Set(value);
}

[JsonProperty]
public string DeviceId
{
get => this.Get<string>();
internal set => this.Set(value);
}

[JsonProperty]
public string DeviceString
{
get => this.Get<string>();
internal set => this.Set(value ?? "");
}

[JsonProperty]
[TriggedOn(nameof(DeviceId))]
[TriggedOn(nameof(Service), "Devices", "Item", "DeviceId")]
public ObservableFilter<DisplayDevice> Devices => this.Get(() => new ObservableFilter<DisplayDevice>()
.AddFilter(a => a.DeviceId == DeviceId)
.Link(Service.Devices)
);

[JsonProperty]
[TriggedOn(nameof(Devices),"Item","AttachedToDesktop")]
public DisplayDevice AttachedDevice => this.Get(() => Devices.FirstOrDefault(d => d.AttachedToDesktop));

[JsonProperty]
[TriggedOn(nameof(AttachedDevice),"Parent")]
public DisplayDevice AttachedDisplay => this.Get(() => AttachedDevice?.Parent);

Expand All @@ -63,32 +71,43 @@ public void Init(IntPtr hMonitor, NativeMethods.MONITORINFOEX mi)

HMonitor = hMonitor;
}

[JsonProperty]
public Rect MonitorArea
{
get => this.Get<Rect>(); private set => this.Set(value);
get => this.Get<Rect>();
private set => this.Set(value);
}

[JsonProperty]
public Rect WorkArea
{
get => this.Get<Rect>(); private set => this.Set(value);
get => this.Get<Rect>();
private set => this.Set(value);
}

public IntPtr HMonitor
{
get => this.Get<IntPtr>(); private set => this.Set(value);
get => this.Get<IntPtr>();
private set => this.Set(value);
}

[JsonProperty]
public string HKeyName
{
get => this.Get<string>(); set => this.Set(value);
get => this.Get<string>();
set => this.Set(value);
}


[JsonProperty]
public bool AttachedToDesktop
{
get => this.Get<bool>();
internal set => this.Set(value);
}

[JsonProperty]
public bool Primary
{
get => this.Get(() => false);
Expand All @@ -106,6 +125,8 @@ internal set
this.Set(value);
}
}

[JsonProperty]
public Edid Edid => this.Get<Edid>(() =>
{
IntPtr devInfo = NativeMethods.SetupDiGetClassDevsEx(
Expand Down Expand Up @@ -200,20 +221,23 @@ private enum DpiType
Raw = 2,
} //https://msdn.microsoft.com/en-us/library/windows/desktop/dn280510.aspx

[JsonProperty]
[TriggedOn(nameof(HMonitor))]
public Vector EffectiveDpi => this.Get(() =>
{
GetDpiForMonitor(HMonitor, DpiType.Effective, out var x, out var y);
return new Vector(x, y);
});

[JsonProperty]
[TriggedOn(nameof(HMonitor))]
public Vector AngularDpi => this.Get(() =>
{
GetDpiForMonitor(HMonitor, DpiType.Angular, out var x, out var y);
return new Vector(x, y);
});

[JsonProperty]
[TriggedOn(nameof(HMonitor))]
public Vector RawDpi => this.Get(() =>
{
Expand All @@ -225,19 +249,23 @@ private enum DpiType
private static extern IntPtr GetDpiForMonitor([In]IntPtr hmonitor, [In]DpiType dpiType, [Out]out uint dpiX, [Out]out uint dpiY);

//https://msdn.microsoft.com/fr-fr/library/windows/desktop/dn302060.aspx
[JsonProperty]
[TriggedOn(nameof(HMonitor))]
public double ScaleFactor => this.Get(() =>
{
var factor = 100;
NativeMethods.GetScaleFactorForMonitor(HMonitor, ref factor);
return (double)factor / 100;
});

[JsonProperty]
[TriggedOn("Service.Monitors")]
public int MonitorNo
{
get
{
var i = 1;
foreach (var monitor in MonitorsService.D.Monitors.OrderBy(e => e.DeviceId.Split('\\').Last()))
foreach (var monitor in Service.Monitors.OrderBy(e => e.DeviceId.Split('\\').Last()))
{
if (ReferenceEquals(monitor, this)) return i;
if(monitor.AttachedToDesktop) i++;
Expand Down Expand Up @@ -297,7 +325,81 @@ public static string GetHKeyName(IntPtr hKey)
Marshal.FreeHGlobal(pKNI);
return result;
}
private void OpenRegKey(string keystring)
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Lastkey", true))
{
//key;
}
}

public void DisplayValues(Action<string,string, RoutedEventHandler, bool> addValue)
{
addValue("Registry", HKeyName, (sender, args) => { OpenRegKey(HKeyName); },false);


// EnumDisplaySettings
addValue("", "EnumDisplaySettings", null, true);
addValue("DisplayOrientation", AttachedDisplay.CurrentMode.DisplayOrientation.ToString(), null, false);
addValue("Position", AttachedDisplay.CurrentMode.Position.ToString(), null, false);
addValue("Pels", AttachedDisplay.CurrentMode.Pels.ToString(), null, false);
addValue("BitsPerPixel", AttachedDisplay.CurrentMode.BitsPerPixel.ToString(), null, false);
addValue("DisplayFrequency", AttachedDisplay.CurrentMode.DisplayFrequency.ToString(), null, false);
addValue("DisplayFlags", AttachedDisplay.CurrentMode.DisplayFlags.ToString(), null, false);
addValue("DisplayFixedOutput", AttachedDisplay.CurrentMode.DisplayFixedOutput.ToString(), null, false);

// GetDeviceCaps
addValue("", "GetDeviceCaps", null, true);
addValue("Size", AttachedDisplay.DeviceCaps.Size.ToString(), null, false);
addValue("Res", AttachedDisplay.DeviceCaps.Resolution.ToString(), null, false);
addValue("LogPixels", AttachedDisplay.DeviceCaps.LogPixels.ToString(), null, false);
addValue("BitsPixel", AttachedDisplay.DeviceCaps.BitsPixel.ToString(), null, false);
//AddValue("Color Planes", Monitor.Adapter.DeviceCaps.Planes.ToString());
addValue("Aspect", AttachedDisplay.DeviceCaps.Aspect.ToString(), null, false);
//AddValue("BltAlignment", Monitor.Adapter.DeviceCaps.BltAlignment.ToString());

//GetDpiForMonitor
addValue("", "GetDpiForMonitor", null, true);
addValue("EffectiveDpi", EffectiveDpi.ToString(), null, false);
addValue("AngularDpi", AngularDpi.ToString(), null, false);
addValue("RawDpi", RawDpi.ToString(), null, false);

// GetMonitorInfo
addValue("", "GetMonitorInfo", null, true);
addValue("Primary", Primary.ToString(), null, false);
addValue("MonitorArea", MonitorArea.ToString(), null, false);
addValue("WorkArea", WorkArea.ToString(), null, false);

addValue("HMonitor", HMonitor.ToString(), null, false);

// EDID
addValue("", "EDID", null, true);
addValue("ManufacturerCode", Edid.ManufacturerCode, null, false);
addValue("ProductCode", Edid.ProductCode, null, false);
addValue("Serial", Edid.Serial, null, false);
addValue("Model", Edid.Model, null, false);
addValue("SerialNo", Edid.SerialNo, null, false);
addValue("SizeInMm", Edid.PhysicalSize.ToString(), null, false);

// GetScaleFactorForMonitor
addValue("", "GetScaleFactorForMonitor", null, true);
addValue("ScaleFactor", ScaleFactor.ToString(), null, false);

// EnumDisplayDevices
addValue("", "EnumDisplayDevices", null, true);
addValue("DeviceId", AttachedDisplay.DeviceId, null, false);
addValue("DeviceKey", AttachedDisplay.DeviceKey, null, false);
addValue("DeviceString", AttachedDisplay.DeviceString, null, false);
addValue("DeviceName", AttachedDisplay.DeviceName, null, false);
addValue("StateFlags", AttachedDisplay.State.ToString(), null, false);

addValue("", "EnumDisplayDevices", null, true);
addValue("DeviceId",DeviceId, null, false);
addValue("DeviceKey", DeviceKey, null, false);
addValue("DeviceString", DeviceString, null, false);
addValue("DeviceName", AttachedDevice.DeviceName, null, false);
addValue("StateFlags", AttachedDevice.State.ToString(), null, false);

}
}
}
4 changes: 4 additions & 0 deletions HLab/Windows.Monitors/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.1-beta3" targetFramework="net47" />
</packages>
Loading

0 comments on commit a481d2b

Please sign in to comment.