Skip to content

Commit

Permalink
1.7.17
Browse files Browse the repository at this point in the history
[Changes]
- More monitor information

[Bug fixes}
- Application crashing? #61
- Closing applications didn't worked properly
  • Loading branch information
Codectory committed Dec 12, 2021
1 parent a63c0b7 commit 9431366
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 131 deletions.
76 changes: 53 additions & 23 deletions Source/HDRController/HDRController/HDRController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,47 +202,77 @@ static void SetHDR(UINT32 uid, bool enabled)

static SIZE _GetResolution(UINT32 uid)
{


uint8_t set[] = { 0x0A, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x14, 0x81, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };

uint8_t request[] = { 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x7C, 0x6F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0xDB, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 };

SIZE resolution = SIZE();
bool returnValue = false;

uint32_t pathCount, modeCount;
UINT32 numPathArrayElements = 0, numModeInfoArrayElements = 0;
UINT32 filter = QDC_ALL_PATHS;

if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
{
DISPLAYCONFIG_PATH_INFO* pathsArray = nullptr;
DISPLAYCONFIG_MODE_INFO* modesArray = nullptr;

const size_t sizePathsArray = pathCount * sizeof(DISPLAYCONFIG_PATH_INFO);
const size_t sizeModesArray = modeCount * sizeof(DISPLAYCONFIG_MODE_INFO);

pathsArray = static_cast<DISPLAYCONFIG_PATH_INFO*>(std::malloc(sizePathsArray));
modesArray = static_cast<DISPLAYCONFIG_MODE_INFO*>(std::malloc(sizeModesArray));

DISPLAYCONFIG_PATH_INFO* pathsArray = new DISPLAYCONFIG_PATH_INFO[pathCount];
DISPLAYCONFIG_MODE_INFO* modesArray = new DISPLAYCONFIG_MODE_INFO[modeCount];

if (pathsArray != nullptr && modesArray != nullptr)
{
std::memset(pathsArray, 0, sizePathsArray);
std::memset(modesArray, 0, sizeModesArray);

ZeroMemory(pathsArray, sizeof(DISPLAYCONFIG_PATH_INFO) * pathCount);
ZeroMemory(modesArray, sizeof(DISPLAYCONFIG_MODE_INFO) * modeCount);
QueryDisplayConfig(filter, &pathCount, pathsArray, &modeCount, modesArray, NULL);
if (ERROR_SUCCESS == QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, pathsArray,
&modeCount, modesArray, 0))
{
DISPLAYCONFIG_DEVICE_INFO_HEADER* setPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(set);
DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(request);

//HDR is off
returnValue = false;
for (int i = 0; i < modeCount; i++)
{
try
{
if (modesArray[i].id == uid)
{
setPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
setPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
setPacket->id = modesArray[i].id;

for (short i = 0; i < pathCount; i++)
{
try
{
int ix = pathsArray[i].sourceInfo.modeInfoIdx; //assuming path[0] is primary
requestPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
requestPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
requestPacket->id = modesArray[i].id;
DISPLAYCONFIG_MODE_INFO mode = modesArray[i];
resolution.cx = mode.sourceMode.width;
resolution.cy = mode.sourceMode.height;
}
}
catch (const std::exception&)
{

if (modesArray[ix].id != uid)
}

{
resolution.cx = modesArray[ix].sourceMode.width;
resolution.cy = modesArray[ix].sourceMode.height;
SetDisplayConfig(pathCount, pathsArray, modeCount, modesArray, SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_ALLOW_CHANGES | SDC_SAVE_TO_DATABASE);
}
}
catch (const std::exception&)
{

}
std::free(pathsArray);
std::free(modesArray);
return resolution;
}
}
return resolution;

}

static bool HDRIsOn(UINT32 uid)
Expand Down
3 changes: 3 additions & 0 deletions Source/HDRProfile/AutoHDR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,14 @@
</Reference>
<Reference Include="Windows">
<HintPath>Externals\Windows.winmd</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="DispatchingObservableCollection.cs" />
<Compile Include="Displays\DisplayInformation.cs" />
<Compile Include="Profiles\Actions\CloseProgramAction.cs" />
<Compile Include="Theming\ThemeResourceDirectory.cs" />
<Compile Include="Theming\Theme.cs" />
Expand Down
Binary file modified Source/HDRProfile/Costura64/HDRController.dll
Binary file not shown.
143 changes: 143 additions & 0 deletions Source/HDRProfile/DispatchingObservableCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;

namespace AutoHDR
{
/// <summary>
/// This class is an observablecollection which invokes automatically.
/// This means that any change will be done in the right thread.
/// </summary>
/// <typeparam name="T">The type of the elements</typeparam>
public class DispatchingObservableCollection<T> : ObservableCollection<T>
{
/// <summary>
/// The default constructor of the ObservableCollection
/// </summary>
public DispatchingObservableCollection()
{
//Assign the current Dispatcher (owner of the collection)
_currentDispatcher = Dispatcher.CurrentDispatcher;
}

private readonly Dispatcher _currentDispatcher;

/// <summary>
/// Executes this action in the right thread
/// </summary>
///<param name="action">The action which should be executed</param>
private void DoDispatchedAction(Action action)
{
if (_currentDispatcher.CheckAccess())
action.Invoke();
else
_currentDispatcher.Invoke(DispatcherPriority.DataBind, action);
}

/// <summary>
/// Clears all items
/// </summary>
protected override void ClearItems()
{
DoDispatchedAction(BaseClearItems);
}

private void BaseClearItems()
{
base.ClearItems();
}

/// <summary>
/// Inserts a item at the specified index
/// </summary>
///<param name="index">The index where the item should be inserted</param>
///<param name="item">The item which should be inserted</param>
protected override void InsertItem(int index, T item)
{
DoDispatchedAction(() => BaseInsertItem(index, item));
}

private void BaseInsertItem(int index, T item)
{
base.InsertItem(index, item);
}

/// <summary>
/// Moves an item from one index to another
/// </summary>
///<param name="oldIndex">The index of the item which should be moved</param>
///<param name="newIndex">The index where the item should be moved</param>
protected override void MoveItem(int oldIndex, int newIndex)
{
DoDispatchedAction(() => BaseMoveItem(oldIndex, newIndex));
}

private void BaseMoveItem(int oldIndex, int newIndex)
{
base.MoveItem(oldIndex, newIndex);
}

/// <summary>
/// Removes the item at the specified index
/// </summary>
///<param name="index">The index of the item which should be removed</param>
protected override void RemoveItem(int index)
{
DoDispatchedAction(() => BaseRemoveItem(index));
}

private void BaseRemoveItem(int index)
{
base.RemoveItem(index);
}

/// <summary>
/// Sets the item at the specified index
/// </summary>
///<param name="index">The index which should be set</param>
///<param name="item">The new item</param>
protected override void SetItem(int index, T item)
{
DoDispatchedAction(() => BaseSetItem(index, item));
}

private void BaseSetItem(int index, T item)
{
base.SetItem(index, item);
}

/// <summary>
/// Fires the CollectionChanged Event
/// </summary>
///<param name="e">The additional arguments of the event</param>
protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
DoDispatchedAction(() => BaseOnCollectionChanged(e));
}

private void BaseOnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
base.OnCollectionChanged(e);
}

/// <summary>
/// Fires the PropertyChanged Event
/// </summary>
///<param name="e">The additional arguments of the event</param>
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
DoDispatchedAction(() => BaseOnPropertyChanged(e));
}

private void BaseOnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
}
}
}
38 changes: 29 additions & 9 deletions Source/HDRProfile/Displays/Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ namespace AutoHDR.Displays
[JsonObject(MemberSerialization.OptIn)]
public class Display : BaseViewModel
{
public static readonly Display AllDisplays = new Display(ProjectResources.Locale_Texts.AllDisplays, UInt32.MaxValue, UInt32.MaxValue, new Size(0, 0),0,0);
public static readonly Display AllDisplays = new Display(ProjectResources.Locale_Texts.AllDisplays, UInt32.MaxValue);
private bool _managed = true;

[JsonProperty]
public bool Managed { get => _managed; set { _managed = value; OnPropertyChanged(); } }


private bool _isPrimary;

[JsonProperty]
public bool IsPrimary { get => _isPrimary; set { _isPrimary = value; OnPropertyChanged(); } }

private string _name;

[JsonProperty]
public string Name { get => _name; set { _name = value; OnPropertyChanged(); } }

private string _graphicsCard;

public string GraphicsCard { get => _graphicsCard; set { _graphicsCard = value; OnPropertyChanged(); } }

private string _deviceKey;

public string DeviceKey { get => _deviceKey; set { _deviceKey = value; OnPropertyChanged(); } }

private UInt32 _uid;

Expand All @@ -35,7 +47,7 @@ public class Display : BaseViewModel
private uint _id;

[JsonProperty]
public uint ID { get => _id; private set { _id = value; OnPropertyChanged(); } }
public uint ID { get => _id; set { _id = value; OnPropertyChanged(); } }

private bool _hdrState;

Expand All @@ -61,14 +73,22 @@ private Display()

}

public Display(string name, uint uID, uint id, Size resolution, int refreshRate, int colorDepth)
public Display(DisplayInformation displayInformation, uint uid)
{
Name = displayInformation.DisplayDevice.DeviceName;
UID = uid;
ID = displayInformation.Id;
IsPrimary = displayInformation.IsPrimary;
DeviceKey = displayInformation.DisplayDevice.DeviceKey;
Resolution = new Size(displayInformation.Devmode.dmPelsWidth, displayInformation.Devmode.dmPelsHeight);
RefreshRate = displayInformation.Devmode.dmDisplayFrequency;
GraphicsCard = displayInformation.DisplayDevice.DeviceString;
}

public Display(string name, uint uid)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
UID = uID;
ID = id;
Resolution = resolution;
RefreshRate = refreshRate;
ColorDepth = colorDepth;
Name = name;
UID = uid;
}

public void UpdateHDRState()
Expand Down
27 changes: 27 additions & 0 deletions Source/HDRProfile/Displays/DisplayInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoHDR.Displays
{
public class DisplayInformation
{
public uint Id { get; private set; }
public DISPLAY_DEVICE DisplayDevice { get; private set; }
public DEVMODE Devmode { get; private set; }
public bool IsPrimary => DisplayDevice.StateFlags.HasFlag(DisplayDeviceStateFlags.PrimaryDevice);

public DisplayInformation(uint id, DISPLAY_DEVICE displayDevice, DEVMODE devmode) : this(id, displayDevice)
{
Devmode = devmode;
}

public DisplayInformation(uint id, DISPLAY_DEVICE displayDevice)
{
Id = id;
DisplayDevice = displayDevice;
}
}
}
Loading

0 comments on commit 9431366

Please sign in to comment.