Changed IDisplayDeviceDriver.RestoreResolution method to IDisplayDeviceDriver.TryRestoreResolution.
DisplayDevice now correctly reports original resolution.
This commit is contained in:
parent
989f22dc75
commit
7f1309a796
4 changed files with 34 additions and 25 deletions
|
@ -25,7 +25,7 @@ namespace OpenTK.Graphics
|
|||
// TODO: Does not detect changes to primary device.
|
||||
// TODO: Mono does not support System.Windows.Forms.Screen.BitsPerPixel -- find workaround!
|
||||
|
||||
DisplayResolution current_resolution;
|
||||
DisplayResolution current_resolution, original_resolution;
|
||||
List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
||||
bool primary;
|
||||
|
||||
|
@ -183,18 +183,21 @@ namespace OpenTK.Graphics
|
|||
/// <param name="height">The new height of the DisplayDevice.</param>
|
||||
/// <param name="bitsPerPixel">The new bits per pixel of the DisplayDevice.</param>
|
||||
/// <param name="refreshRate">The new refresh rate of the DisplayDevice.</param>
|
||||
/// <exception cref="GraphicsModeException">Thrown if the requested resolution change failed.</exception>
|
||||
/// <exception cref="GraphicsModeException">Thrown if the requested resolution could not be set.</exception>
|
||||
public void ChangeResolution(DisplayResolution resolution)
|
||||
{
|
||||
if (resolution == null)
|
||||
throw new ArgumentNullException("resulotion", "Must be a valid resolution.");
|
||||
if (resolution == current_resolution)
|
||||
return;
|
||||
|
||||
if (implementation.TryChangeResolution(this, resolution))
|
||||
{
|
||||
if (original_resolution == null)
|
||||
original_resolution = current_resolution;
|
||||
current_resolution = resolution;
|
||||
}
|
||||
else
|
||||
throw new GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
|
||||
else throw new GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
|
||||
this, resolution));
|
||||
}
|
||||
|
||||
|
@ -202,9 +205,14 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region public void RestoreResolution()
|
||||
|
||||
/// <summary>Restores the original resolution of the DisplayDevice.</summary>
|
||||
/// <exception cref="GraphicsModeException">Thrown if the original resolution could not be restored.</exception>
|
||||
public void RestoreResolution()
|
||||
{
|
||||
implementation.RestoreResolution(this);
|
||||
if (original_resolution != null)
|
||||
if (implementation.TryRestoreResolution(this))
|
||||
current_resolution = original_resolution;
|
||||
else throw new GraphicsModeException(String.Format("Device {0}: Failed to restore resolution.", this));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace OpenTK.Graphics
|
|||
internal interface IDisplayDeviceDriver
|
||||
{
|
||||
bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
|
||||
void RestoreResolution(DisplayDevice device);
|
||||
bool TryRestoreResolution(DisplayDevice device);
|
||||
//DisplayDevice[] AvailableDevices { get; }
|
||||
//DisplayResolution[]
|
||||
}
|
||||
|
|
|
@ -95,30 +95,31 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
public bool TryChangeResolution(OpenTK.Graphics.DisplayDevice device, DisplayResolution resolution)
|
||||
{
|
||||
DeviceMode mode = new DeviceMode();
|
||||
mode.PelsWidth = resolution.Width;
|
||||
mode.PelsHeight = resolution.Height;
|
||||
mode.BitsPerPel = resolution.BitsPerPixel;
|
||||
mode.DisplayFrequency = (int)resolution.RefreshRate;
|
||||
mode.Fields = Constants.DM_BITSPERPEL
|
||||
| Constants.DM_PELSWIDTH
|
||||
| Constants.DM_PELSHEIGHT
|
||||
| Constants.DM_DISPLAYFREQUENCY;
|
||||
DeviceMode mode = null;
|
||||
if (resolution != null)
|
||||
{
|
||||
mode = new DeviceMode();
|
||||
mode.PelsWidth = resolution.Width;
|
||||
mode.PelsHeight = resolution.Height;
|
||||
mode.BitsPerPel = resolution.BitsPerPixel;
|
||||
mode.DisplayFrequency = (int)resolution.RefreshRate;
|
||||
mode.Fields = Constants.DM_BITSPERPEL
|
||||
| Constants.DM_PELSWIDTH
|
||||
| Constants.DM_PELSHEIGHT
|
||||
| Constants.DM_DISPLAYFREQUENCY;
|
||||
}
|
||||
|
||||
//return Functions.ChangeDisplaySettings(settings, ChangeDisplaySettingsEnum.Fullscreen) ==
|
||||
// Constants.DISP_CHANGE_SUCCESSFUL;
|
||||
return Functions.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero, 0, IntPtr.Zero) ==
|
||||
Constants.DISP_CHANGE_SUCCESSFUL;
|
||||
return Constants.DISP_CHANGE_SUCCESSFUL ==
|
||||
Functions.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero, 0, IntPtr.Zero);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void RestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
||||
#region public TryRestoreResolution TryRestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
||||
|
||||
public void RestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
||||
public bool TryRestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
||||
{
|
||||
//Functions.ChangeDisplaySettings(null, (ChangeDisplaySettingsEnum)0);
|
||||
Functions.ChangeDisplaySettingsEx(available_device_names[device], null, IntPtr.Zero, 0, IntPtr.Zero);
|
||||
return TryChangeResolution(device, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -165,9 +165,9 @@ namespace OpenTK.Platform.X11
|
|||
current_rotation, (short)(resolution != null ? resolution.RefreshRate : 0), lastConfigUpdate[screen]);
|
||||
}
|
||||
|
||||
public void RestoreResolution(DisplayDevice device)
|
||||
public bool TryRestoreResolution(DisplayDevice device)
|
||||
{
|
||||
TryChangeResolution(device, null);
|
||||
return TryChangeResolution(device, null);
|
||||
//System.Diagnostics.Process.Start("xrandr", "-s -0").WaitForExit(); // Hack, but works ;)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue