diff --git a/AMDInfo/Program.cs b/AMDInfo/Program.cs index 72f11fc..0db31ca 100644 --- a/AMDInfo/Program.cs +++ b/AMDInfo/Program.cs @@ -52,10 +52,10 @@ static void Main(string[] args) NLog.LogManager.Configuration = config; // Start the Log file - SharedLogger.logger.Info($"AMDInfo/Main: Starting AMDInfo v1.7.9"); + SharedLogger.logger.Info($"AMDInfo/Main: Starting AMDInfo v1.8.0"); - Console.WriteLine($"\nAMDInfo v1.7.9"); + Console.WriteLine($"\nAMDInfo v1.8.0"); Console.WriteLine($"=============="); Console.WriteLine($"By Terry MacDonald 2022\n"); diff --git a/AMDInfo/Properties/AssemblyInfo.cs b/AMDInfo/Properties/AssemblyInfo.cs index c988042..b917240 100644 --- a/AMDInfo/Properties/AssemblyInfo.cs +++ b/AMDInfo/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.9.0")] -[assembly: AssemblyFileVersion("1.7.9.0")] +[assembly: AssemblyVersion("1.8.0.0")] +[assembly: AssemblyFileVersion("1.8.0.0")] diff --git a/AMDInfo/TaskBarLayout.cs b/AMDInfo/TaskBarLayout.cs index b08d9b6..2278715 100644 --- a/AMDInfo/TaskBarLayout.cs +++ b/AMDInfo/TaskBarLayout.cs @@ -123,7 +123,7 @@ public bool ReadFromRegistry(string regKeyValue) } catch (Exception ex) { - SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: Exception while trying to open RegKey {address}. Unable to get the TaskBarStuckRectangle binary settings. Screen details may not be available yet in registry."); + SharedLogger.logger.Trace(ex, $"TaskBarLayout/ReadFromRegistry: Exception while trying to open RegKey {address}. Unable to get the TaskBarStuckRectangle binary settings. Screen details may not be available yet in registry."); } } else @@ -196,7 +196,7 @@ public bool ReadFromRegistry(string regKeyValue) } catch (Exception ex) { - SharedLogger.logger.Trace($"TaskBarLayout/ReadFromRegistry: Exception2 while trying to open RegKey {address}. Unable to get the TaskBarStuckRectangle binary settings. Screen details may not be available yet in registry."); + SharedLogger.logger.Trace(ex, $"TaskBarLayout/ReadFromRegistry: Exception2 while trying to open RegKey {address}. Unable to get the TaskBarStuckRectangle binary settings. Screen details may not be available yet in registry."); return false; } @@ -615,6 +615,7 @@ public static Dictionary GetAllCurrentTaskBarLayouts(Dict // Then go through the secondary windows and get the position of them // Tell Windows to refresh the Other Windows Taskbars if needed + int clonedCount = 0; try { IntPtr lastTaskBarWindowHwnd = (IntPtr)Utils.NULL; @@ -677,6 +678,11 @@ public static Dictionary GetAllCurrentTaskBarLayouts(Dict { // Invalid state SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar position was not on a horizontal edge of a monitor!"); + SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Forcing Taskbar position to be at the bottom"); + tbWidth = monWidth; + tbHeight = monHeight - wrkHeight; + tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcWork.bottom, tbWidth, tbHeight); + tbsr.Edge = TaskBarEdge.Bottom; } } @@ -703,12 +709,22 @@ public static Dictionary GetAllCurrentTaskBarLayouts(Dict { // Invalid state SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar position was not on a vertical edge of a monitor!"); + SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Forcing Taskbar position to be at the bottom"); + tbWidth = monWidth; + tbHeight = monHeight - wrkHeight; + tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcWork.bottom, tbWidth, tbHeight); + tbsr.Edge = TaskBarEdge.Bottom; } } else { // Invalid state SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar position was not fully along one of the monitor edges!"); + SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Forcing Taskbar position to be at the bottom"); + tbWidth = monWidth; + tbHeight = monHeight - wrkHeight; + tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcWork.bottom, tbWidth, tbHeight); + tbsr.Edge = TaskBarEdge.Bottom; } tbsr.MonitorLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monWidth, monHeight); @@ -718,7 +734,8 @@ public static Dictionary GetAllCurrentTaskBarLayouts(Dict SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Secondary taskbar coordinates are {tbsr.TaskBarLocation.X},{tbsr.TaskBarLocation.Y} and it is {tbsr.TaskBarLocation.Width}x{tbsr.TaskBarLocation.Height}"); SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Secondary taskbar is {tbsr.Edge.ToString("G")}"); - // Now as a LAST step we update the Binary field just before we apply it to make sure that the correct binary settings are stored + // Now as a LAST step we update the Binary field to make sure that the correct binary settings are stored + // This means the correct location should be returned even if the registry isn't updated as we're patching the registry object before we store it. tbsr.PopulateBinaryFromFields(); if (!taskBarStuckRectangles.ContainsKey(monitorInfo.szDevice)) @@ -728,6 +745,7 @@ public static Dictionary GetAllCurrentTaskBarLayouts(Dict else { SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Skipping grabbing Taskbar position from a cloned display {monitorInfo.szDevice}"); + clonedCount++; } // Prep the next taskbar window so we continue through them @@ -739,6 +757,29 @@ public static Dictionary GetAllCurrentTaskBarLayouts(Dict SharedLogger.logger.Error(ex, $"TaskBarLayout/GetAllCurrentTaskBarPositions: Exception while trying to get a secondary taskbar position"); } + // Check if the display reg keys shown match the display sources + foreach (var tbrKey in taskBarStuckRectangles.Keys) + { + if (tbrKey.Equals("Settings")) + { + continue; + } + // If there isn't a match then we have a problem. + if (!displaySources.ContainsKey(tbrKey)) + { + SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: We have an error because Display Sources array doesn't include the {tbrKey} taskbar data. This means we have a mismatch somewhere."); + retryNeeded = true; + } + } + + // Check if the length of the display sources equals the taskbar locations we're tracking + // Note: taskBarStuckRectangles includes the 'Settings' main screen which is one extra screen that windows stores for the primary screen. We need to remove this from the count as it is extra. + if (displaySources.Count != taskBarStuckRectangles.Keys.Count - 1) + { + SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: We have an error because Display Sources array length doesn't match the taskBarStuckRectangles array length. This means we have a mismatch somewhere."); + retryNeeded = true; + } + retryNeeded = false; return taskBarStuckRectangles; } diff --git a/AMDInfo/WinLibrary.cs b/AMDInfo/WinLibrary.cs index 3d7ec0b..e19959c 100644 --- a/AMDInfo/WinLibrary.cs +++ b/AMDInfo/WinLibrary.cs @@ -1611,8 +1611,18 @@ public bool SetActiveConfig(WINDOWS_DISPLAY_CONFIG displayConfig) if (result == CHANGE_DISPLAY_RESULTS.Successful) { SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Success. The GDI Device Mode will work for display {displayDeviceKey}."); - SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Actually going to try to set the GDI Device Mode for display {displayDeviceKey} now."); - result = GDIImport.ChangeDisplaySettingsEx(currentDeviceSetting.Device.DeviceName, ref currentDeviceSetting.DeviceMode, IntPtr.Zero, (CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_UPDATEREGISTRY | CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_NORESET), IntPtr.Zero); + // Set the + if (currentDeviceSetting.IsPrimary) + { + SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Actually going to try to set the GDI Device Mode for display {displayDeviceKey} now (primary display)."); + result = GDIImport.ChangeDisplaySettingsEx(currentDeviceSetting.Device.DeviceName, ref currentDeviceSetting.DeviceMode, IntPtr.Zero, (CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_SET_PRIMARY | CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_UPDATEREGISTRY | CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_NORESET), IntPtr.Zero); + } + else + { + SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Actually going to try to set the GDI Device Mode for display {displayDeviceKey} now (secondary display)."); + result = GDIImport.ChangeDisplaySettingsEx(currentDeviceSetting.Device.DeviceName, ref currentDeviceSetting.DeviceMode, IntPtr.Zero, (CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_UPDATEREGISTRY | CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_NORESET), IntPtr.Zero); + + } if (result == CHANGE_DISPLAY_RESULTS.Successful) { SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: Successfully changed display {displayDeviceKey} to use the new mode!");