mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Updated branch with latest develop hotfixes
This commit is contained in:
commit
8cc59583e1
@ -2727,8 +2727,18 @@ namespace DisplayMagicianShared.NVIDIA
|
||||
}
|
||||
else if (NVStatus == NVAPI_STATUS.NVAPI_INVALID_ARGUMENT)
|
||||
{
|
||||
SharedLogger.logger.Error($"NVIDIALibrary/SetActiveConfig: One or more arguments passed in are invalid. NvAPI_DISP_SetDisplayConfig() returned error code {NVStatus}");
|
||||
return false;
|
||||
// We sometimes get an invalid argument here if NVIDIA has just disolved a mosaic surround screen into indivudal screens
|
||||
// THis is because if there are any additional screens from other adapters, nvidia tells windows to disable them
|
||||
// We need to wait until the Windows library applies the screen before the DisplayConfig will be applied.
|
||||
if (!displayConfig.MosaicConfig.IsMosaicEnabled && ActiveDisplayConfig.MosaicConfig.IsMosaicEnabled)
|
||||
{
|
||||
SharedLogger.logger.Error($"NVIDIALibrary/SetActiveConfig: NvAPI_DISP_SetDisplayConfig() returned error code {NVStatus}, but this is expected as we are changing from a Surround screen layout to a non-surround layout. Ignoring this error.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"NVIDIALibrary/SetActiveConfig: One or more arguments passed in are invalid. NvAPI_DISP_SetDisplayConfig() returned error code {NVStatus}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (NVStatus == NVAPI_STATUS.NVAPI_API_NOT_INITIALIZED)
|
||||
{
|
||||
@ -2780,10 +2790,11 @@ namespace DisplayMagicianShared.NVIDIA
|
||||
|
||||
NVAPI_STATUS NVStatus = NVAPI_STATUS.NVAPI_ERROR;
|
||||
|
||||
|
||||
// Go through the physical adapters
|
||||
foreach (var physicalGPU in displayConfig.PhysicalAdapters)
|
||||
{
|
||||
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Processing settings for Physical GPU #{physicalGPU.Key}");
|
||||
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfigOverride: Processing settings for Physical GPU #{physicalGPU.Key}");
|
||||
NVIDIA_PER_ADAPTER_CONFIG myAdapter = physicalGPU.Value;
|
||||
UInt32 myAdapterIndex = physicalGPU.Key;
|
||||
|
||||
@ -2797,7 +2808,7 @@ namespace DisplayMagicianShared.NVIDIA
|
||||
|
||||
if (!ActiveDisplayConfig.PhysicalAdapters[myAdapterIndex].Displays.ContainsKey(displayId))
|
||||
{
|
||||
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Display {displayId} doesn't exist in this setup, so skipping overriding any NVIDIA display Settings.");
|
||||
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfigOverride: Display {displayId} doesn't exist in this setup, so skipping overriding any NVIDIA display Settings.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -724,6 +724,10 @@ namespace DisplayMagicianShared
|
||||
|
||||
if (itWorkedforNVIDIAColor)
|
||||
{
|
||||
// Lets update the screen config again for the final time.
|
||||
nvidiaLibrary.UpdateActiveConfig();
|
||||
winLibrary.UpdateActiveConfig();
|
||||
|
||||
SharedLogger.logger.Trace($"ProfileItem/SetActive: The NVIDIA display settings that override windows within the profile {Name} were successfully applied.");
|
||||
return true;
|
||||
}
|
||||
@ -789,6 +793,10 @@ namespace DisplayMagicianShared
|
||||
|
||||
if (itWorkedforAMDColor)
|
||||
{
|
||||
// Lets update the screen config again for the final time.
|
||||
amdLibrary.UpdateActiveConfig();
|
||||
winLibrary.UpdateActiveConfig();
|
||||
|
||||
SharedLogger.logger.Trace($"ProfileItem/SetActive: The AMD display settings that override windows within the profile {Name} were successfully applied.");
|
||||
return true;
|
||||
}
|
||||
@ -829,6 +837,9 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
if (winLibrary.SetActiveConfig(_windowsDisplayConfig))
|
||||
{
|
||||
// Lets update the screen config again for the final time.
|
||||
winLibrary.UpdateActiveConfig();
|
||||
|
||||
SharedLogger.logger.Trace($"ProfileItem/SetActive: The Windows CCD display settings within profile {Name} were successfully applied.");
|
||||
return true;
|
||||
}
|
||||
@ -1490,7 +1501,8 @@ namespace DisplayMagicianShared
|
||||
// IMPORTANT: This lookup WILL DEFINITELY CAUSE AN EXCEPTION right after windows changes back from
|
||||
// NVIDIA Surround to a non-surround profile. This is expected, as it is caused bythe way Windows is SOOOO slow to update
|
||||
// the taskbar locations in memory (it takes up to 15 seconds!). Nothing I can do, except put this protection in place :( .
|
||||
screen.TaskBarEdge = _windowsDisplayConfig.TaskBarLayout.First(tbr => tbr.Value.RegKeyValue.Contains($"UID{targetId}")).Value.Edge;
|
||||
|
||||
screen.TaskBarEdge = _windowsDisplayConfig.TaskBarLayout.First(tbr => tbr.Value.RegKeyValue != null && tbr.Value.RegKeyValue.Contains($"UID{targetId}")).Value.Edge;
|
||||
SharedLogger.logger.Trace($"ProfileItem/GetWindowsScreenPositions: Position of the taskbar on display {targetId} is on the {screen.TaskBarEdge } of the screen.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -1575,10 +1587,10 @@ namespace DisplayMagicianShared
|
||||
// rather than the MMStuckRect reg keys
|
||||
try
|
||||
{
|
||||
if (_windowsDisplayConfig.TaskBarLayout.Count(tbr => tbr.Value.RegKeyValue.Contains("Settings")) > 0)
|
||||
if (_windowsDisplayConfig.TaskBarLayout.Count(tbr => tbr.Value.RegKeyValue != null && tbr.Value.RegKeyValue.Contains("Settings")) > 0)
|
||||
{
|
||||
screen.TaskBarEdge = _windowsDisplayConfig.TaskBarLayout.First(tbr => tbr.Value.RegKeyValue.Contains("Settings")).Value.Edge;
|
||||
SharedLogger.logger.Trace($"ProfileItem/GetWindowsScreenPositions: Position of the taskbar on the primary display {targetId} is on the {screen.TaskBarEdge } of the screen.");
|
||||
SharedLogger.logger.Trace($"ProfileItem/GetWindowsScreenPositions: Position of the taskbar on the primary display {targetId} is on the {screen.TaskBarEdge} of the screen.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1598,7 +1610,7 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
try
|
||||
{
|
||||
int numMatches = _windowsDisplayConfig.TaskBarLayout.Count(tbr => tbr.Value.RegKeyValue.Contains($"UID{targetId}"));
|
||||
int numMatches = _windowsDisplayConfig.TaskBarLayout.Count(tbr => tbr.Value.RegKeyValue != null && tbr.Value.RegKeyValue.Contains($"UID{targetId}"));
|
||||
if (numMatches > 1)
|
||||
{
|
||||
var matchingTbls = (from tbl in _windowsDisplayConfig.TaskBarLayout where tbl.Value.RegKeyValue.Contains($"UID{targetId}") select tbl.Value).ToList();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@ -58,8 +59,9 @@ namespace DisplayMagicianShared.Windows
|
||||
{3, new byte[] {0x30, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF}}
|
||||
};
|
||||
*/
|
||||
public bool ReadFromRegistry(string regKeyValue)
|
||||
public bool ReadFromRegistry(string regKeyValue, out bool retryNeeded)
|
||||
{
|
||||
retryNeeded = false;
|
||||
bool MMStuckRectVerFound = false;
|
||||
// Check if key exists
|
||||
int version = 3;
|
||||
@ -99,25 +101,33 @@ namespace DisplayMagicianShared.Windows
|
||||
address,
|
||||
RegistryKeyPermissionCheck.ReadSubTree))
|
||||
{
|
||||
var binary = key?.GetValue(regKeyValue) as byte[];
|
||||
if (binary?.Length > 0)
|
||||
if (key.GetValueNames().Contains(regKeyValue))
|
||||
{
|
||||
MainScreen = false;
|
||||
RegKeyValue = regKeyValue;
|
||||
Binary = binary;
|
||||
Version = version;
|
||||
var binary = key?.GetValue(regKeyValue) as byte[];
|
||||
if (binary?.Length > 0)
|
||||
{
|
||||
MainScreen = false;
|
||||
RegKeyValue = regKeyValue;
|
||||
Binary = binary;
|
||||
Version = version;
|
||||
|
||||
// Extract the values from the binary byte field
|
||||
PopulateFieldsFromBinary();
|
||||
// Extract the values from the binary byte field
|
||||
PopulateFieldsFromBinary();
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
|
||||
// If we get here then we're done and don't need to continue with the rest of the code.
|
||||
return true;
|
||||
// If we get here then we're done and don't need to continue with the rest of the code.
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen. Screen details may not be available yet in registry.");
|
||||
retryNeeded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen. Screen details may not be available yet in registry.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: Unable to find {regKeyValue} key in {address}. Screen details may not be available yet in registry.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -173,23 +183,32 @@ namespace DisplayMagicianShared.Windows
|
||||
address,
|
||||
RegistryKeyPermissionCheck.ReadSubTree))
|
||||
{
|
||||
var binary = key?.GetValue(regKeyValue) as byte[];
|
||||
if (binary?.Length > 0)
|
||||
if (key.GetValueNames().Contains(regKeyValue))
|
||||
{
|
||||
MainScreen = true;
|
||||
RegKeyValue = regKeyValue;
|
||||
Binary = binary;
|
||||
Version = version;
|
||||
var binary = key?.GetValue(regKeyValue) as byte[];
|
||||
if (binary?.Length > 0)
|
||||
{
|
||||
MainScreen = true;
|
||||
RegKeyValue = regKeyValue;
|
||||
Binary = binary;
|
||||
Version = version;
|
||||
|
||||
// Extract the values from the binary byte field
|
||||
PopulateFieldsFromBinary();
|
||||
// Extract the values from the binary byte field
|
||||
PopulateFieldsFromBinary();
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
return true;
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarLayout/ReadFromRegistry: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen.");
|
||||
retryNeeded = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarLayout/ReadFromRegistry: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: Unable to find {regKeyValue} key in {address}. Screen details may not be available yet in registry.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -285,6 +304,11 @@ namespace DisplayMagicianShared.Windows
|
||||
|
||||
private bool PopulateFieldsFromBinary()
|
||||
{
|
||||
if (Binary == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now we decipher the binary properties features to populate the stuckrectangle
|
||||
// DPI
|
||||
if (Binary.Length < 44)
|
||||
@ -356,6 +380,11 @@ namespace DisplayMagicianShared.Windows
|
||||
|
||||
public bool PopulateBinaryFromFields()
|
||||
{
|
||||
if (Binary == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the DPI
|
||||
if (Binary.Length < 44)
|
||||
{
|
||||
@ -550,8 +579,8 @@ namespace DisplayMagicianShared.Windows
|
||||
|
||||
TaskBarLayout tbsr = new TaskBarLayout();
|
||||
// Now we're at the point that we should be able to update the binary that we grabbed earlier when the object was created
|
||||
tbsrReadWorked = tbsr.ReadFromRegistry(GetRegKeyValueFromDevicePath(displaySources[monitorInfo.szDevice][0].DevicePath));
|
||||
if (!tbsrReadWorked)
|
||||
tbsrReadWorked = tbsr.ReadFromRegistry(GetRegKeyValueFromDevicePath(displaySources[monitorInfo.szDevice][0].DevicePath),out retryNeeded);
|
||||
if (retryNeeded)
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar read #1 from registry didn't work.");
|
||||
retryNeeded = true;
|
||||
@ -587,8 +616,8 @@ namespace DisplayMagicianShared.Windows
|
||||
|
||||
// If it's a main screen, also add a duplicate so we track the main StuckRects settings separately too
|
||||
TaskBarLayout tbsrMain = new TaskBarLayout();
|
||||
tbsrReadWorked = tbsrMain.ReadFromRegistry("Settings");
|
||||
if (!tbsrReadWorked)
|
||||
tbsrReadWorked = tbsrMain.ReadFromRegistry("Settings",out retryNeeded) ;
|
||||
if (!retryNeeded)
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar read #1 from registry didn't work.");
|
||||
retryNeeded = true;
|
||||
@ -647,7 +676,7 @@ namespace DisplayMagicianShared.Windows
|
||||
|
||||
TaskBarLayout tbsr = new TaskBarLayout();
|
||||
// Now we're at the point that we should be able to update the binary that we grabbed earlier when the object was created
|
||||
tbsrReadWorked = tbsr.ReadFromRegistry(GetRegKeyValueFromDevicePath(displaySources[monitorInfo.szDevice][0].DevicePath));
|
||||
tbsrReadWorked = tbsr.ReadFromRegistry(GetRegKeyValueFromDevicePath(displaySources[monitorInfo.szDevice][0].DevicePath), out retryNeeded);
|
||||
if (!tbsrReadWorked)
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar read #3 from registry didn't work.");
|
||||
|
Loading…
Reference in New Issue
Block a user