From c42b53843b4afc29c1793bb2d2301bf8667d0051 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Mon, 25 Oct 2021 16:01:33 +1300 Subject: [PATCH] Updated WinLibrary to use patched current Display Settings This is needed to stop the GDI settings from overwriting the display layout. This appears to fix all display issues! --- DisplayMagicianShared/Windows/WinLibrary.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/DisplayMagicianShared/Windows/WinLibrary.cs b/DisplayMagicianShared/Windows/WinLibrary.cs index b11ffd7..74548db 100644 --- a/DisplayMagicianShared/Windows/WinLibrary.cs +++ b/DisplayMagicianShared/Windows/WinLibrary.cs @@ -1100,24 +1100,25 @@ 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 "); - for (int i = 0; i < displayConfig.GdiDisplaySettings.Count; i++) + foreach (var gdiDisplay in displayConfig.GdiDisplaySettings) { - var thisGdiSetting = displayConfig.GdiDisplaySettings.ElementAt(i); - string displayDeviceKey = thisGdiSetting.Key; + string displayDeviceKey = gdiDisplay.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 modeToUse = displayDeviceSettings.DeviceMode; + GDI_DISPLAY_SETTING currentDeviceSetting = currentGdiDisplaySettings[displayDeviceKey]; - // 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; + // Use the current device as a base, but set some of the various settings we stored as part of the profile + currentDeviceSetting.DeviceMode.BitsPerPixel = displayDeviceSettings.DeviceMode.BitsPerPixel; + currentDeviceSetting.DeviceMode.DisplayOrientation = displayDeviceSettings.DeviceMode.DisplayOrientation; + currentDeviceSetting.DeviceMode.DisplayFrequency = displayDeviceSettings.DeviceMode.DisplayFrequency; + // Sets the greyscale and interlaced settings + currentDeviceSetting.DeviceMode.DisplayFlags = displayDeviceSettings.DeviceMode.DisplayFlags; - CHANGE_DISPLAY_RESULTS result = GDIImport.ChangeDisplaySettingsEx(currentDeviceName, ref modeToUse, IntPtr.Zero, CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_UPDATEREGISTRY, IntPtr.Zero); + CHANGE_DISPLAY_RESULTS result = GDIImport.ChangeDisplaySettingsEx(currentDeviceSetting.Device.DeviceName, ref currentDeviceSetting.DeviceMode, IntPtr.Zero, CHANGE_DISPLAY_SETTINGS_FLAGS.CDS_UPDATEREGISTRY, IntPtr.Zero); if (result == CHANGE_DISPLAY_RESULTS.Successful) { SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Successfully changed display {displayDeviceKey} to use the new mode!");