diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index e88ca59..ad16e06 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.0.1.129")] -[assembly: AssemblyFileVersion("2.0.1.129")] +[assembly: AssemblyVersion("2.0.1.149")] +[assembly: AssemblyFileVersion("2.0.1.149")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 25e4642..8b37148 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -2399,7 +2399,7 @@ namespace DisplayMagician.UIForms _gameLauncher = game.GameLibrary.ToString("G"); lbl_game_library.Text = $"Game Library: {_gameLauncher}"; _gameId = game.Id; - + break; } } } diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index 87ab42b..27936b7 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -973,7 +973,7 @@ namespace DisplayMagicianShared { uint displayId = _nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].Displays[0].DisplayId; string windowsDisplayName = _nvidiaDisplayConfig.DisplayNames[displayId]; - uint sourceIndex = _windowsDisplayConfig.DisplaySources[windowsDisplayName]; + List sourceIndexes = _windowsDisplayConfig.DisplaySources[windowsDisplayName]; for (int x = 0; x < _windowsDisplayConfig.DisplayConfigModes.Length; x++) { // Skip this if its not a source info config type @@ -982,8 +982,8 @@ namespace DisplayMagicianShared continue; } - // If the source index matches the index of the source info object we're looking at, then process it! - if (_windowsDisplayConfig.DisplayConfigModes[x].Id == sourceIndex) + // If the source index matches the index of the source info object we're looking at, then process it! + if (sourceIndexes.Contains(_windowsDisplayConfig.DisplayConfigModes[x].Id)) { screen.Name = displayId.ToString(); diff --git a/DisplayMagicianShared/ProfileRepository.cs b/DisplayMagicianShared/ProfileRepository.cs index e036981..12f10f3 100644 --- a/DisplayMagicianShared/ProfileRepository.cs +++ b/DisplayMagicianShared/ProfileRepository.cs @@ -797,12 +797,11 @@ namespace DisplayMagicianShared SharedLogger.logger.Error($"ProfileRepository/MigrateJsonToLatestVersion: Exception while trying to process the Profiles json data to migrate any older feature to the latest version."); } - - // Now we try and add a default NVIDIA Color Settings if there isn't one + // We do the change we wre trying to do try { + // Now we try and add a default NVIDIA Color Settings if there isn't one SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Looking for missing NVIDIA Color Config."); - // Create a default object NVIDIA_DISPLAY_CONFIG myDefaultConfig = new NVIDIA_DISPLAY_CONFIG(); myDefaultConfig.ColorConfig.ColorData = new Dictionary(); @@ -820,22 +819,10 @@ namespace DisplayMagicianShared changedJson = true; SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Patched missing NVIDIA Color Config in profile {profile.SelectToken("Name")} (index {i})."); } - } - } - catch (JsonReaderException ex) - { - SharedLogger.logger.Error($"ProfileRepository/MigrateJsonToLatestVersion: JSONReaderException while trying to process the Profiles json data to migrate any older feature to the latest version."); - } - catch (Exception ex) - { - SharedLogger.logger.Error($"ProfileRepository/MigrateJsonToLatestVersion: Exception while trying to process the Profiles json data to migrate any older feature to the latest version."); - } + } - // Now we try and add a default Windows GDI Device Context if there isn't one - try - { + // Now we try to patch in a Windows GDI device context into the json if there isnt one SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Looking for missing Windows GDI Device Context."); - // Create a default object Dictionary GdiDisplaySettings = new Dictionary(); JObject defaultGdiDisplaySettings = (JObject)JToken.FromObject(GdiDisplaySettings); @@ -852,6 +839,41 @@ namespace DisplayMagicianShared SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Patched missing Windows GDI Device Context in profile {profile.SelectToken("Name")} (index {i})."); } } + + // Now we try to convert the individual sourceids into a list of source ids to cope with cloned devices + SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Looking for missing Windows GDI Device Context."); + // Create a default object + List WinDisplaySourcesList = new List(); + //JObject WinDisplaySources = (JObject)JToken.FromObject(WinDisplaySourcesList); + for (int i = 0; i < root.Count; i++) + { + JObject profile = (JObject)root[i]; + try + { + JObject WindowsDisplaySources = (JObject)profile.SelectToken("WindowsDisplayConfig.DisplaySources"); + Dictionary> existingDisplaySources = WindowsDisplaySources.ToObject>>(); + } + catch (Exception ex) + { + JObject WindowsDisplaySources = (JObject)profile.SelectToken("WindowsDisplayConfig.DisplaySources"); + //foreach (var displaySource in WindowsDisplaySources.ToObject>()) + Dictionary existingDisplaySources = WindowsDisplaySources.ToObject>(); + Dictionary> newDisplaySources = new Dictionary>(); + foreach (var sourceName in existingDisplaySources.Keys) + { + List newList = new List(); + newList.Add((uint)existingDisplaySources[sourceName]); + newDisplaySources[sourceName] = newList; + } + JObject newSourcesDict = JObject.FromObject(newDisplaySources); + JToken WindowsDisplayConfig = (JToken)profile.SelectToken("WindowsDisplayConfig.DisplaySources"); + WindowsDisplayConfig.Replace(newSourcesDict); + changedJson = true; + SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Patched missing Windows GDI Device Context in profile {profile.SelectToken("Name")} (index {i})."); + } + + } + } catch (JsonReaderException ex) { diff --git a/DisplayMagicianShared/Windows/WinLibrary.cs b/DisplayMagicianShared/Windows/WinLibrary.cs index c97b337..409eef5 100644 --- a/DisplayMagicianShared/Windows/WinLibrary.cs +++ b/DisplayMagicianShared/Windows/WinLibrary.cs @@ -46,7 +46,7 @@ namespace DisplayMagicianShared.Windows // Note: We purposely have left out the DisplaySources from the Equals as it's order keeps changing after each reboot and after each profile swap // and it is informational only and doesn't contribute to the configuration (it's used for generating the Screens structure, and therefore for // generating the profile icon. - public Dictionary DisplaySources; + public Dictionary> DisplaySources; public List DisplayIdentifiers; public override bool Equals(object obj) => obj is WINDOWS_DISPLAY_CONFIG other && this.Equals(other); @@ -143,7 +143,7 @@ namespace DisplayMagicianShared.Windows myDefaultConfig.DisplayConfigPaths = new DISPLAYCONFIG_PATH_INFO[0]; myDefaultConfig.DisplayHDRStates = new ADVANCED_HDR_INFO_PER_PATH[0]; myDefaultConfig.DisplayIdentifiers = new List(); - myDefaultConfig.DisplaySources = new Dictionary(); + myDefaultConfig.DisplaySources = new Dictionary>(); myDefaultConfig.GdiDisplaySettings = new Dictionary(); return myDefaultConfig; @@ -304,7 +304,7 @@ namespace DisplayMagicianShared.Windows WINDOWS_DISPLAY_CONFIG windowsDisplayConfig = new WINDOWS_DISPLAY_CONFIG(); windowsDisplayConfig.DisplayAdapters = new Dictionary(); windowsDisplayConfig.DisplayHDRStates = new ADVANCED_HDR_INFO_PER_PATH[pathCount]; - windowsDisplayConfig.DisplaySources = new Dictionary(); + windowsDisplayConfig.DisplaySources = new Dictionary>(); // Now cycle through the paths and grab the HDR state information // and map the adapter name to adapter id @@ -322,7 +322,21 @@ namespace DisplayMagicianShared.Windows if (err == WIN32STATUS.ERROR_SUCCESS) { // Store it for later - windowsDisplayConfig.DisplaySources.Add(sourceInfo.ViewGdiDeviceName, path.SourceInfo.Id); + if (windowsDisplayConfig.DisplaySources.ContainsKey(sourceInfo.ViewGdiDeviceName)) + { + // We already have at least one display using this source, so we need to add the other cloned display to the existing list + List sourceIds = windowsDisplayConfig.DisplaySources[sourceInfo.ViewGdiDeviceName]; + sourceIds.Add(path.SourceInfo.Id); + windowsDisplayConfig.DisplaySources.Add(sourceInfo.ViewGdiDeviceName, sourceIds); + } + else + { + // This is the first display to use this source + List sourceIds = new List(); + sourceIds.Add(path.SourceInfo.Id); + windowsDisplayConfig.DisplaySources.Add(sourceInfo.ViewGdiDeviceName, sourceIds); + } + SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Found Display Source {sourceInfo.ViewGdiDeviceName} for source {path.SourceInfo.Id}."); } else