From 5f6c8e654c583b377dd67f8d61f4e157f835f1d4 Mon Sep 17 00:00:00 2001 From: cwassall Date: Sun, 19 Jan 2014 19:44:12 +0000 Subject: [PATCH] Remember DisplayDevice original resolutions When refreshing the AvailableDevices list, it is important to set the original resolution on any DisplayDevices that were previously available to allow the RestoreResolution() method to work correctly. --- Source/OpenTK/DisplayDevice.cs | 3 ++- Source/OpenTK/Platform/Windows/WinDisplayDevice.cs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/DisplayDevice.cs b/Source/OpenTK/DisplayDevice.cs index b90a3273..d6bf0837 100644 --- a/Source/OpenTK/DisplayDevice.cs +++ b/Source/OpenTK/DisplayDevice.cs @@ -47,7 +47,8 @@ namespace OpenTK bool primary; Rectangle bounds; - DisplayResolution current_resolution = new DisplayResolution(), original_resolution; + DisplayResolution current_resolution = new DisplayResolution(); + internal DisplayResolution original_resolution; List available_resolutions = new List(); IList available_resolutions_readonly; diff --git a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs index 2ff578f7..56da3668 100644 --- a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -96,6 +96,10 @@ namespace OpenTK.Platform.Windows { lock (display_lock) { + // Store an array of the current available DisplayDevice objects. + // This is needed to preserve the original_resolution. + DisplayDevice[] previousDevices = AvailableDevices.ToArray(); + AvailableDevices.Clear(); // We save all necessary parameters in temporary variables @@ -159,6 +163,11 @@ namespace OpenTK.Platform.Windows opentk_dev_current_res.Bounds, dev1.DeviceName); + // Set the original_resolution if the DisplayDevice was previously available. + foreach (DisplayDevice existingDevice in previousDevices) + if ((string)existingDevice.Id == (string)opentk_dev.Id) + opentk_dev.original_resolution = existingDevice.original_resolution; + AvailableDevices.Add(opentk_dev); if (opentk_dev_primary)