From 1faa8ecc5b1cd69da5262bbdc4e9aaf32cd6403f Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Mon, 25 Oct 2021 15:19:02 +1300 Subject: [PATCH] Updated AMDLibrary and WinLibrary to latest versions AMDLibrary had an error that caused issues due to a missing call to get a valid default config. WinLibrary had an issue where it wasn't applying the GDIDisplaySettings correctly after a reboot. This has now been fixed. --- DisplayMagician/Program.cs | 2 +- DisplayMagician/Properties/AssemblyInfo.cs | 4 +-- DisplayMagicianShared/AMD/AMDLibrary.cs | 2 +- DisplayMagicianShared/Windows/WinLibrary.cs | 34 ++++++++++++++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index 7c00fe4..ad57fae 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -280,7 +280,7 @@ namespace DisplayMagician { // Warn the user about the fact we need a new DisplayProfiles_2.0.json StartMessageForm myMessageWindow = new StartMessageForm(); myMessageWindow.MessageMode = "rtf"; - myMessageWindow.URL = "https://displaymagician.littlebitbig.com/messages/DisplayMagician2.0to2.1.rtf"; + myMessageWindow.URL = "https://displaymagician.littlebitbig.com/messages/DisplayMagician20to21.rtf"; myMessageWindow.HeadingText = "DisplayMagician v2.1.0 Upgrade Warning"; myMessageWindow.ButtonText = "&Close"; myMessageWindow.ShowDialog(); diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index b13bd9f..85b4bce 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.1.0.11")] -[assembly: AssemblyFileVersion("2.1.0.11")] +[assembly: AssemblyVersion("2.1.0.14")] +[assembly: AssemblyFileVersion("2.1.0.14")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagicianShared/AMD/AMDLibrary.cs b/DisplayMagicianShared/AMD/AMDLibrary.cs index b9586bc..fdfcdc2 100644 --- a/DisplayMagicianShared/AMD/AMDLibrary.cs +++ b/DisplayMagicianShared/AMD/AMDLibrary.cs @@ -170,7 +170,7 @@ namespace DisplayMagicianShared.AMD static AMDLibrary() { } public AMDLibrary() { - + _activeDisplayConfig = CreateDefaultConfig(); try { SharedLogger.logger.Trace($"AMDLibrary/AMDLibrary: Attempting to load the AMD ADL DLL {ADLImport.ATI_ADL_DLL}"); diff --git a/DisplayMagicianShared/Windows/WinLibrary.cs b/DisplayMagicianShared/Windows/WinLibrary.cs index 652c12d..b11ffd7 100644 --- a/DisplayMagicianShared/Windows/WinLibrary.cs +++ b/DisplayMagicianShared/Windows/WinLibrary.cs @@ -515,6 +515,16 @@ namespace DisplayMagicianShared.Windows } } + // And then we need to go through the list of modes again and patch the 'cloned' displays with a real display ID so the display layout is right in cloned displays + for (int i = 0; i < modes.Length; i++) + { + // We only change the ids that match in InfoType for target displays + if (modes[i].InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET && targetIdsToChange.Contains(modes[i].Id)) + { + // Patch the cloned ids with a real working one! + modes[i].Id = targetIdMap[modes[i].Id]; + } + } // Store the active paths and modes in our display config object windowsDisplayConfig.DisplayConfigPaths = paths; @@ -522,7 +532,6 @@ namespace DisplayMagicianShared.Windows windowsDisplayConfig.DisplayHDRStates = hdrInfos; windowsDisplayConfig.GdiDisplaySettings = GetGdiDisplaySettings(); - return windowsDisplayConfig; } @@ -1018,8 +1027,9 @@ namespace DisplayMagicianShared.Windows SharedLogger.logger.Error($"WinLibrary/SetActiveConfig: ERROR - SetDisplayConfig couldn't validate the display configuration supplied. This display configuration won't work if applied."); return false; } - SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Yay! The display configuration is valid! Attempting to set the Display Config now"); + + // Now set the specified display configuration for this computer err = CCDImport.SetDisplayConfig(myPathsCount, displayConfig.DisplayConfigPaths, myModesCount, displayConfig.DisplayConfigModes, SDC.DISPLAYMAGICIAN_SET | SDC.SDC_FORCE_MODE_ENUMERATION); if (err == WIN32STATUS.ERROR_SUCCESS) @@ -1090,18 +1100,23 @@ namespace DisplayMagicianShared.Windows // Apply the previously saved display settings to the new displays (match them up) // NOTE: This may be the only mode needed once it's completed. SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Attempting to change Display Device settings through GDI API using "); - foreach (var myGdiDisplaySettings in displayConfig.GdiDisplaySettings) + for (int i = 0; i < displayConfig.GdiDisplaySettings.Count; i++) { - string displayDeviceKey = myGdiDisplaySettings.Key; - GDI_DISPLAY_SETTING displayDeviceSettings = myGdiDisplaySettings.Value; - SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Trying to change Device Mode for Display {displayDeviceKey}."); + + var thisGdiSetting = displayConfig.GdiDisplaySettings.ElementAt(i); + string displayDeviceKey = thisGdiSetting.Key; + GDI_DISPLAY_SETTING displayDeviceSettings = displayConfig.GdiDisplaySettings[displayDeviceKey]; if (currentGdiDisplaySettings.ContainsKey(displayDeviceKey)) { + SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Trying to change Device Mode for Display {displayDeviceKey}."); string currentDeviceName = currentGdiDisplaySettings[displayDeviceKey].Device.DeviceName; - DEVICE_MODE currentModeToUse = currentGdiDisplaySettings[displayDeviceKey].DeviceMode; + //DEVICE_MODE currentModeToUse = currentGdiDisplaySettings[displayDeviceKey].DeviceMode; DEVICE_MODE modeToUse = displayDeviceSettings.DeviceMode; + // Update the Device name to match what the OS currently thinks that is (Ensures the device settings are provided to the correct screens) + displayDeviceSettings.Device.DeviceName = currentGdiDisplaySettings[displayDeviceKey].Device.DeviceName; + CHANGE_DISPLAY_RESULTS result = GDIImport.ChangeDisplaySettingsEx(currentDeviceName, ref modeToUse, IntPtr.Zero, CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_UPDATEREGISTRY, IntPtr.Zero); if (result == CHANGE_DISPLAY_RESULTS.Successful) { @@ -1147,7 +1162,10 @@ namespace DisplayMagicianShared.Windows SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Display {displayDeviceKey} not updated to use the new mode."); } } - + else + { + SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Display {displayDeviceKey} is not currently in use, so cannot set it!"); + } } return true;