mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-22 20:50:57 +00:00
Refactored and simplified DisplayDevice detection (devices are now stored in the platform-specific drivers instead of the frontend).
Made XRR resolution changes more robust. Resolution changes now refresh the DisplayDevices on Windows.
This commit is contained in:
parent
8be8190ee8
commit
6c0da79687
|
@ -1,16 +1,33 @@
|
||||||
#region --- License ---
|
#region License
|
||||||
/* Licensed under the MIT/X11 license.
|
//
|
||||||
* Copyright (c) 2006-2008 the OpenTK team.
|
// The Open Toolkit Library License
|
||||||
* This notice may not be removed.
|
//
|
||||||
* See license.txt for licensing detailed licensing details.
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
*/
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenTK
|
namespace OpenTK
|
||||||
|
@ -21,23 +38,19 @@ namespace OpenTK
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DisplayDevice
|
public class DisplayDevice
|
||||||
{
|
{
|
||||||
// TODO: Add support for refresh rate queries and switches.
|
|
||||||
// TODO: Check whether bits_per_pixel works correctly under Mono/X11.
|
|
||||||
// TODO: Add properties that describe the 'usable' size of the Display, i.e. the maximized size without the taskbar etc.
|
// TODO: Add properties that describe the 'usable' size of the Display, i.e. the maximized size without the taskbar etc.
|
||||||
// TODO: Does not detect changes to primary device.
|
// TODO: Does not detect changes to primary device.
|
||||||
// TODO: Mono does not support System.Windows.Forms.Screen.BitsPerPixel -- find workaround!
|
|
||||||
|
|
||||||
#region --- Fields ---
|
#region Fields
|
||||||
|
|
||||||
|
bool primary;
|
||||||
|
Rectangle bounds;
|
||||||
DisplayResolution current_resolution = new DisplayResolution(), original_resolution;
|
DisplayResolution current_resolution = new DisplayResolution(), original_resolution;
|
||||||
List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
||||||
IList<DisplayResolution> available_resolutions_readonly;
|
IList<DisplayResolution> available_resolutions_readonly;
|
||||||
bool primary;
|
|
||||||
|
internal object Id; // A platform-specific id for this monitor
|
||||||
|
|
||||||
Rectangle bounds;
|
|
||||||
|
|
||||||
static readonly List<DisplayDevice> available_displays = new List<DisplayDevice>();
|
|
||||||
static readonly IList<DisplayDevice> available_displays_readonly;
|
|
||||||
static readonly object display_lock = new object();
|
static readonly object display_lock = new object();
|
||||||
static DisplayDevice primary_display;
|
static DisplayDevice primary_display;
|
||||||
|
|
||||||
|
@ -45,26 +58,21 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region Constructors
|
||||||
|
|
||||||
static DisplayDevice()
|
static DisplayDevice()
|
||||||
{
|
{
|
||||||
implementation = Platform.Factory.Default.CreateDisplayDeviceDriver();
|
implementation = Platform.Factory.Default.CreateDisplayDeviceDriver();
|
||||||
available_displays_readonly = available_displays.AsReadOnly();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal DisplayDevice()
|
internal DisplayDevice()
|
||||||
{
|
{
|
||||||
lock (display_lock)
|
|
||||||
{
|
|
||||||
available_displays.Add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
available_resolutions_readonly = available_resolutions.AsReadOnly();
|
available_resolutions_readonly = available_resolutions.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal DisplayDevice(DisplayResolution currentResolution, bool primary,
|
internal DisplayDevice(DisplayResolution currentResolution, bool primary,
|
||||||
IEnumerable<DisplayResolution> availableResolutions, Rectangle bounds)
|
IEnumerable<DisplayResolution> availableResolutions, Rectangle bounds,
|
||||||
|
object id)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
#warning "Consolidate current resolution with bounds? Can they fall out of sync right now?"
|
#warning "Consolidate current resolution with bounds? Can they fall out of sync right now?"
|
||||||
|
@ -72,9 +80,7 @@ namespace OpenTK
|
||||||
IsPrimary = primary;
|
IsPrimary = primary;
|
||||||
this.available_resolutions.AddRange(availableResolutions);
|
this.available_resolutions.AddRange(availableResolutions);
|
||||||
this.bounds = bounds == Rectangle.Empty ? currentResolution.Bounds : bounds;
|
this.bounds = bounds == Rectangle.Empty ? currentResolution.Bounds : bounds;
|
||||||
|
this.Id = id;
|
||||||
Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
|
|
||||||
available_displays.Count, primary ? "primary" : "secondary", available_resolutions.Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -280,10 +286,23 @@ namespace OpenTK
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of available <see cref="DisplayDevice"/> objects.
|
/// Gets the list of available <see cref="DisplayDevice"/> objects.
|
||||||
|
/// This function allocates memory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("Use GetDisplay(DisplayIndex) instead.")]
|
||||||
public static IList<DisplayDevice> AvailableDisplays
|
public static IList<DisplayDevice> AvailableDisplays
|
||||||
{
|
{
|
||||||
get { return available_displays_readonly; }
|
get
|
||||||
|
{
|
||||||
|
List<DisplayDevice> displays = new List<DisplayDevice>();
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
DisplayDevice dev = GetDisplay(DisplayIndex.First + i);
|
||||||
|
if (dev != null)
|
||||||
|
displays.Add(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return displays.AsReadOnly();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -291,7 +310,24 @@ namespace OpenTK
|
||||||
#region public static DisplayDevice Default
|
#region public static DisplayDevice Default
|
||||||
|
|
||||||
/// <summary>Gets the default (primary) display of this system.</summary>
|
/// <summary>Gets the default (primary) display of this system.</summary>
|
||||||
public static DisplayDevice Default { get { return primary_display; } }
|
public static DisplayDevice Default
|
||||||
|
{
|
||||||
|
get { return implementation.GetDisplay(DisplayIndex.Primary); }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetDisplay
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="DisplayDevice"/> for the specified <see cref="DeviceIndex"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">The <see cref="DeviceIndex"/> that defines the desired display.</param>
|
||||||
|
/// <returns>A <see cref="DisplayDevice"/> or null, if no device corresponds to the specified index.</returns>
|
||||||
|
public static DisplayDevice GetDisplay(DisplayIndex index)
|
||||||
|
{
|
||||||
|
return implementation.GetDisplay(index);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
72
Source/OpenTK/DisplayIndex.cs
Normal file
72
Source/OpenTK/DisplayIndex.cs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#region License
|
||||||
|
//
|
||||||
|
// The Open Toolkit Library License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenTK
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines <see cref="DisplayDevice"/> indices.
|
||||||
|
/// </summary>
|
||||||
|
public enum DisplayIndex
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The first DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
First = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// The second DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Second,
|
||||||
|
/// <summary>
|
||||||
|
/// The third DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Third,
|
||||||
|
/// <summary>
|
||||||
|
/// The fourth DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Fourth,
|
||||||
|
/// <summary>
|
||||||
|
/// The fifth DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Fifth,
|
||||||
|
/// <summary>
|
||||||
|
/// The sixth DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Sixth,
|
||||||
|
/// <summary>
|
||||||
|
/// The default (primary) DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Primary = -1,
|
||||||
|
/// <summary>
|
||||||
|
/// The default (primary) DisplayDevice.
|
||||||
|
/// </summary>
|
||||||
|
Default = Primary,
|
||||||
|
}
|
||||||
|
}
|
|
@ -321,8 +321,8 @@ namespace OpenTK.Graphics
|
||||||
{
|
{
|
||||||
if (defaultMode == null)
|
if (defaultMode == null)
|
||||||
{
|
{
|
||||||
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel,
|
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).",
|
||||||
16, 0, 0, 0, 2, false);
|
DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
|
||||||
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
|
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
|
||||||
}
|
}
|
||||||
return defaultMode;
|
return defaultMode;
|
||||||
|
|
|
@ -128,11 +128,13 @@
|
||||||
<Compile Include="DisplayDevice.cs">
|
<Compile Include="DisplayDevice.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="DisplayIndex.cs" />
|
||||||
<Compile Include="Graphics\GraphicsModeComparer.cs" />
|
<Compile Include="Graphics\GraphicsModeComparer.cs" />
|
||||||
<Compile Include="Input\IGamePadDriver.cs" />
|
<Compile Include="Input\IGamePadDriver.cs" />
|
||||||
<Compile Include="Input\IInputDriver2.cs" />
|
<Compile Include="Input\IInputDriver2.cs" />
|
||||||
<Compile Include="Input\IKeyboardDriver2.cs" />
|
<Compile Include="Input\IKeyboardDriver2.cs" />
|
||||||
<Compile Include="Input\IMouseDriver2.cs" />
|
<Compile Include="Input\IMouseDriver2.cs" />
|
||||||
|
<Compile Include="Platform\DisplayDeviceBase.cs" />
|
||||||
<Compile Include="Platform\Windows\WinInputBase.cs" />
|
<Compile Include="Platform\Windows\WinInputBase.cs" />
|
||||||
<Compile Include="WindowBorder.cs">
|
<Compile Include="WindowBorder.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
|
|
53
Source/OpenTK/Platform/DisplayDeviceBase.cs
Normal file
53
Source/OpenTK/Platform/DisplayDeviceBase.cs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#region License
|
||||||
|
//
|
||||||
|
// The Open Toolkit Library License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenTK.Platform
|
||||||
|
{
|
||||||
|
abstract class DisplayDeviceBase : IDisplayDeviceDriver
|
||||||
|
{
|
||||||
|
protected readonly List<DisplayDevice> AvailableDevices = new List<DisplayDevice>();
|
||||||
|
protected DisplayDevice Primary;
|
||||||
|
|
||||||
|
public abstract bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
|
||||||
|
public abstract bool TryRestoreResolution(DisplayDevice device);
|
||||||
|
|
||||||
|
// Gets the DisplayDevice that corresponds to the specified index.
|
||||||
|
public virtual DisplayDevice GetDisplay(DisplayIndex index)
|
||||||
|
{
|
||||||
|
if (index == DisplayIndex.Primary)
|
||||||
|
return Primary;
|
||||||
|
else if ((int)index >= 0 && (int)index < AvailableDevices.Count)
|
||||||
|
return AvailableDevices[(int)index];
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,28 @@
|
||||||
#region --- License ---
|
#region License
|
||||||
/* Licensed under the MIT/X11 license.
|
//
|
||||||
* Copyright (c) 2006-2008 the OpenTK team.
|
// The Open Toolkit Library License
|
||||||
* This notice may not be removed.
|
//
|
||||||
* See license.txt for licensing detailed licensing details.
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
*/
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
@ -16,5 +35,6 @@ namespace OpenTK.Platform
|
||||||
{
|
{
|
||||||
bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
|
bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
|
||||||
bool TryRestoreResolution(DisplayDevice device);
|
bool TryRestoreResolution(DisplayDevice device);
|
||||||
|
DisplayDevice GetDisplay(DisplayIndex displayIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
IntPtr cgdevice = GetQuartzDevice(carbonWindow);
|
IntPtr cgdevice = GetQuartzDevice(carbonWindow);
|
||||||
|
|
||||||
if (cgdevice == IntPtr.Zero)
|
if (cgdevice == IntPtr.Zero)
|
||||||
cgdevice = QuartzDisplayDeviceDriver.MainDisplay;
|
cgdevice = (IntPtr)DisplayDevice.Default.Id;
|
||||||
|
|
||||||
OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
|
OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,43 @@
|
||||||
|
#region License
|
||||||
|
//
|
||||||
|
// The Open Toolkit Library License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenTK.Platform.MacOS.Carbon;
|
||||||
|
|
||||||
namespace OpenTK.Platform.MacOS
|
namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
using System.Drawing;
|
sealed class QuartzDisplayDeviceDriver : DisplayDeviceBase
|
||||||
using Carbon;
|
|
||||||
|
|
||||||
class QuartzDisplayDeviceDriver : IDisplayDeviceDriver
|
|
||||||
{
|
{
|
||||||
static object display_lock = new object();
|
static object display_lock = new object();
|
||||||
|
|
||||||
static Dictionary<DisplayDevice, IntPtr> displayMap = new Dictionary<DisplayDevice, IntPtr>();
|
public QuartzDisplayDeviceDriver()
|
||||||
|
|
||||||
static IntPtr mainDisplay;
|
|
||||||
static internal IntPtr MainDisplay
|
|
||||||
{
|
|
||||||
get { return mainDisplay; }
|
|
||||||
}
|
|
||||||
|
|
||||||
static QuartzDisplayDeviceDriver()
|
|
||||||
{
|
{
|
||||||
lock (display_lock)
|
lock (display_lock)
|
||||||
{
|
{
|
||||||
|
@ -52,9 +70,6 @@ namespace OpenTK.Platform.MacOS
|
||||||
// main display.
|
// main display.
|
||||||
bool primary = (i == 0);
|
bool primary = (i == 0);
|
||||||
|
|
||||||
if (primary)
|
|
||||||
mainDisplay = currentDisplay;
|
|
||||||
|
|
||||||
// gets current settings
|
// gets current settings
|
||||||
int currentWidth = CG.DisplayPixelsWide(currentDisplay);
|
int currentWidth = CG.DisplayPixelsWide(currentDisplay);
|
||||||
int currentHeight = CG.DisplayPixelsHigh(currentDisplay);
|
int currentHeight = CG.DisplayPixelsHigh(currentDisplay);
|
||||||
|
@ -97,22 +112,22 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
Debug.Print("Display {0} bounds: {1}", i, newRect);
|
Debug.Print("Display {0} bounds: {1}", i, newRect);
|
||||||
|
|
||||||
DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect);
|
DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res,
|
||||||
|
primary, opentk_dev_available_res, newRect, currentDisplay);
|
||||||
displayMap.Add(opentk_dev, currentDisplay);
|
|
||||||
|
AvailableDevices.Add(opentk_dev);
|
||||||
|
|
||||||
|
if (primary)
|
||||||
|
Primary = opentk_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Unindent();
|
Debug.Unindent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static internal IntPtr HandleTo(DisplayDevice displayDevice)
|
static internal IntPtr HandleTo(DisplayDevice displayDevice)
|
||||||
{
|
{
|
||||||
if (displayMap.ContainsKey(displayDevice))
|
return (IntPtr)displayDevice.Id;
|
||||||
return displayMap[displayDevice];
|
|
||||||
else
|
|
||||||
return IntPtr.Zero;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IDisplayDeviceDriver Members
|
#region IDisplayDeviceDriver Members
|
||||||
|
@ -120,9 +135,9 @@ namespace OpenTK.Platform.MacOS
|
||||||
Dictionary<IntPtr, IntPtr> storedModes = new Dictionary<IntPtr, IntPtr>();
|
Dictionary<IntPtr, IntPtr> storedModes = new Dictionary<IntPtr, IntPtr>();
|
||||||
List<IntPtr> displaysCaptured = new List<IntPtr>();
|
List<IntPtr> displaysCaptured = new List<IntPtr>();
|
||||||
|
|
||||||
public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
||||||
{
|
{
|
||||||
IntPtr display = displayMap[device];
|
IntPtr display = HandleTo(device);
|
||||||
IntPtr currentModePtr = CG.DisplayCurrentMode(display);
|
IntPtr currentModePtr = CG.DisplayCurrentMode(display);
|
||||||
|
|
||||||
if (storedModes.ContainsKey(display) == false)
|
if (storedModes.ContainsKey(display) == false)
|
||||||
|
@ -160,9 +175,9 @@ namespace OpenTK.Platform.MacOS
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryRestoreResolution(DisplayDevice device)
|
public sealed override bool TryRestoreResolution(DisplayDevice device)
|
||||||
{
|
{
|
||||||
IntPtr display = displayMap[device];
|
IntPtr display = HandleTo(device);
|
||||||
|
|
||||||
if (storedModes.ContainsKey(display))
|
if (storedModes.ContainsKey(display))
|
||||||
{
|
{
|
||||||
|
@ -177,8 +192,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,101 @@
|
||||||
#region --- License ---
|
#region License
|
||||||
/* Licensed under the MIT/X11 license.
|
//
|
||||||
* Copyright (c) 2006-2008 the OpenTK team.
|
// The Open Toolkit Library License
|
||||||
* This notice may not be removed.
|
//
|
||||||
* See license.txt for licensing detailed licensing details.
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
*/
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using OpenTK.Graphics;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace OpenTK.Platform.Windows
|
namespace OpenTK.Platform.Windows
|
||||||
{
|
{
|
||||||
internal class WinDisplayDeviceDriver : IDisplayDeviceDriver
|
sealed class WinDisplayDeviceDriver : DisplayDeviceBase
|
||||||
{
|
{
|
||||||
static object display_lock = new object();
|
readonly object display_lock = new object();
|
||||||
static Dictionary<DisplayDevice, string> available_device_names =
|
|
||||||
new Dictionary<DisplayDevice, string>(); // Needed for ChangeDisplaySettingsEx
|
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>Queries available display devices and display resolutions.</summary>
|
public WinDisplayDeviceDriver()
|
||||||
static WinDisplayDeviceDriver()
|
{
|
||||||
|
RefreshDisplayDevices();
|
||||||
|
Microsoft.Win32.SystemEvents.DisplaySettingsChanged +=
|
||||||
|
HandleDisplaySettingsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisplayDeviceDriver Members
|
||||||
|
|
||||||
|
#region TryChangeResolution
|
||||||
|
|
||||||
|
public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
||||||
|
{
|
||||||
|
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 Constants.DISP_CHANGE_SUCCESSFUL ==
|
||||||
|
Functions.ChangeDisplaySettingsEx((string)device.Id, mode, IntPtr.Zero,
|
||||||
|
ChangeDisplaySettingsEnum.Fullscreen, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region TryRestoreResolution
|
||||||
|
|
||||||
|
public sealed override bool TryRestoreResolution(DisplayDevice device)
|
||||||
|
{
|
||||||
|
return TryChangeResolution(device, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
#region RefreshDisplayDevices
|
||||||
|
|
||||||
|
public void RefreshDisplayDevices()
|
||||||
{
|
{
|
||||||
lock (display_lock)
|
lock (display_lock)
|
||||||
{
|
{
|
||||||
// To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
|
AvailableDevices.Clear();
|
||||||
// we only allow settings to be set through its constructor.
|
|
||||||
// Thus, we save all necessary parameters in temporary variables
|
// We save all necessary parameters in temporary variables
|
||||||
// and construct the device when every needed detail is available.
|
// and construct the device when every needed detail is available.
|
||||||
// The main DisplayDevice constructor adds the newly constructed device
|
// The main DisplayDevice constructor adds the newly constructed device
|
||||||
// to the list of available devices.
|
// to the list of available devices.
|
||||||
|
@ -82,56 +146,37 @@ namespace OpenTK.Platform.Windows
|
||||||
opentk_dev_current_res,
|
opentk_dev_current_res,
|
||||||
opentk_dev_primary,
|
opentk_dev_primary,
|
||||||
opentk_dev_available_res,
|
opentk_dev_available_res,
|
||||||
opentk_dev_current_res.Bounds);
|
opentk_dev_current_res.Bounds,
|
||||||
|
dev1.DeviceName);
|
||||||
|
|
||||||
available_device_names.Add(opentk_dev, dev1.DeviceName);
|
AvailableDevices.Add(opentk_dev);
|
||||||
|
|
||||||
|
if (opentk_dev_primary)
|
||||||
|
Primary = opentk_dev;
|
||||||
|
|
||||||
|
Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
|
||||||
|
device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WinDisplayDeviceDriver()
|
#endregion
|
||||||
|
|
||||||
|
#region HandleDisplaySettingsChanged
|
||||||
|
|
||||||
|
void HandleDisplaySettingsChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
RefreshDisplayDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- IDisplayDeviceDriver Members ---
|
~WinDisplayDeviceDriver()
|
||||||
|
|
||||||
#region public bool TryChangeResolution(OpenTK.Graphics.DisplayDevice device, DisplayResolution resolution)
|
|
||||||
|
|
||||||
public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
|
||||||
{
|
{
|
||||||
DeviceMode mode = null;
|
Microsoft.Win32.SystemEvents.DisplaySettingsChanged -=
|
||||||
|
HandleDisplaySettingsChanged;
|
||||||
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 Constants.DISP_CHANGE_SUCCESSFUL ==
|
|
||||||
Functions.ChangeDisplaySettingsEx(available_device_names[device], mode, IntPtr.Zero,
|
|
||||||
ChangeDisplaySettingsEnum.Fullscreen, IntPtr.Zero);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public TryRestoreResolution TryRestoreResolution(OpenTK.Graphics.DisplayDevice device)
|
|
||||||
|
|
||||||
public bool TryRestoreResolution(DisplayDevice device)
|
|
||||||
{
|
|
||||||
return TryChangeResolution(device, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region Constructors
|
||||||
|
|
||||||
public WinGraphicsMode()
|
public WinGraphicsMode()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1501,7 +1501,7 @@ XF86VidModeGetGammaRampSize(
|
||||||
|
|
||||||
[DllImport(XrandrLibrary)]
|
[DllImport(XrandrLibrary)]
|
||||||
public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config,
|
public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config,
|
||||||
Drawable draw, int size_index, ref Rotation rotation, Time timestamp);
|
Drawable draw, int size_index, Rotation rotation, Time timestamp);
|
||||||
|
|
||||||
[DllImport(XrandrLibrary)]
|
[DllImport(XrandrLibrary)]
|
||||||
public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config,
|
public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config,
|
||||||
|
|
|
@ -1,9 +1,28 @@
|
||||||
#region --- License ---
|
#region License
|
||||||
/* Licensed under the MIT/X11 license.
|
//
|
||||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
// The Open Toolkit Library License
|
||||||
* This notice may not be removed from any source distribution.
|
//
|
||||||
* See license.txt for licensing detailed licensing details.
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
||||||
*/
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights to
|
||||||
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
// the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
// so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
//
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
@ -14,27 +33,35 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenTK.Platform.X11
|
namespace OpenTK.Platform.X11
|
||||||
{
|
{
|
||||||
internal class X11DisplayDevice : IDisplayDeviceDriver
|
sealed class X11DisplayDevice : DisplayDeviceBase
|
||||||
{
|
{
|
||||||
static object display_lock = new object();
|
|
||||||
// Store a mapping between resolutions and their respective
|
// Store a mapping between resolutions and their respective
|
||||||
// size_index (needed for XRRSetScreenConfig). The size_index
|
// size_index (needed for XRRSetScreenConfig). The size_index
|
||||||
// is simply the sequence number of the resolution as returned by
|
// is simply the sequence number of the resolution as returned by
|
||||||
// XRRSizes. This is done per available screen.
|
// XRRSizes. This is done per available screen.
|
||||||
static List<Dictionary<DisplayResolution, int>> screenResolutionToIndex =
|
readonly List<Dictionary<DisplayResolution, int>> screenResolutionToIndex =
|
||||||
new List<Dictionary<DisplayResolution, int>>();
|
new List<Dictionary<DisplayResolution, int>>();
|
||||||
// Store a mapping between DisplayDevices and their default resolutions.
|
// Store a mapping between DisplayDevices and their default resolutions.
|
||||||
static Dictionary<DisplayDevice, int> deviceToDefaultResolution = new Dictionary<DisplayDevice, int>();
|
readonly Dictionary<DisplayDevice, int> deviceToDefaultResolution = new Dictionary<DisplayDevice, int>();
|
||||||
// Store a mapping between DisplayDevices and X11 screens.
|
// Store a mapping between DisplayDevices and X11 screens.
|
||||||
static Dictionary<DisplayDevice, int> deviceToScreen = new Dictionary<DisplayDevice, int>();
|
readonly Dictionary<DisplayDevice, int> deviceToScreen = new Dictionary<DisplayDevice, int>();
|
||||||
// Keep the time when the config of each screen was last updated.
|
// Keep the time when the config of each screen was last updated.
|
||||||
static List<IntPtr> lastConfigUpdate = new List<IntPtr>();
|
readonly List<IntPtr> lastConfigUpdate = new List<IntPtr>();
|
||||||
|
|
||||||
static bool xinerama_supported, xrandr_supported, xf86_supported;
|
bool xinerama_supported, xrandr_supported, xf86_supported;
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region Constructors
|
||||||
|
|
||||||
static X11DisplayDevice()
|
public X11DisplayDevice()
|
||||||
|
{
|
||||||
|
RefreshDisplayDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
void RefreshDisplayDevices()
|
||||||
{
|
{
|
||||||
using (new XLock(API.DefaultDisplay))
|
using (new XLock(API.DefaultDisplay))
|
||||||
{
|
{
|
||||||
|
@ -82,16 +109,23 @@ namespace OpenTK.Platform.X11
|
||||||
Debug.Print("XF86 query failed, no DisplayDevice support available.");
|
Debug.Print("XF86 query failed, no DisplayDevice support available.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AvailableDevices.Clear();
|
||||||
|
AvailableDevices.AddRange(devices);
|
||||||
|
Primary = FindDefaultDevice(devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal X11DisplayDevice() { }
|
static DisplayDevice FindDefaultDevice(IEnumerable<DisplayDevice> devices)
|
||||||
|
{
|
||||||
|
foreach (DisplayDevice dev in devices)
|
||||||
|
if (dev.IsPrimary)
|
||||||
|
return dev;
|
||||||
|
|
||||||
#endregion
|
throw new InvalidOperationException("No primary display found. Please file a bug at http://www.opentk.com");
|
||||||
|
}
|
||||||
|
|
||||||
#region --- Private Methods ---
|
bool QueryXinerama(List<DisplayDevice> devices)
|
||||||
|
|
||||||
static bool QueryXinerama(List<DisplayDevice> devices)
|
|
||||||
{
|
{
|
||||||
// Try to use Xinerama to obtain the geometry of all output devices.
|
// Try to use Xinerama to obtain the geometry of all output devices.
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
|
@ -119,7 +153,7 @@ namespace OpenTK.Platform.X11
|
||||||
return (devices.Count>0);
|
return (devices.Count>0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool QueryXRandR(List<DisplayDevice> devices)
|
bool QueryXRandR(List<DisplayDevice> devices)
|
||||||
{
|
{
|
||||||
// Get available resolutions. Then, for each resolution get all available rates.
|
// Get available resolutions. Then, for each resolution get all available rates.
|
||||||
foreach (DisplayDevice dev in devices)
|
foreach (DisplayDevice dev in devices)
|
||||||
|
@ -196,7 +230,7 @@ namespace OpenTK.Platform.X11
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool QueryXF86(List<DisplayDevice> devices)
|
bool QueryXF86(List<DisplayDevice> devices)
|
||||||
{
|
{
|
||||||
int major;
|
int major;
|
||||||
int minor;
|
int minor;
|
||||||
|
@ -286,14 +320,14 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#region private static int FindCurrentDepth(int screen)
|
#region private static int FindCurrentDepth(int screen)
|
||||||
|
|
||||||
private static int FindCurrentDepth(int screen)
|
static int FindCurrentDepth(int screen)
|
||||||
{
|
{
|
||||||
return (int)Functions.XDefaultDepth(API.DefaultDisplay, screen);
|
return (int)Functions.XDefaultDepth(API.DefaultDisplay, screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
static bool ChangeResolutionXRandR(DisplayDevice device, DisplayResolution resolution)
|
bool ChangeResolutionXRandR(DisplayDevice device, DisplayResolution resolution)
|
||||||
{
|
{
|
||||||
using (new XLock(API.DefaultDisplay))
|
using (new XLock(API.DefaultDisplay))
|
||||||
{
|
{
|
||||||
|
@ -313,8 +347,28 @@ namespace OpenTK.Platform.X11
|
||||||
Debug.Print("Changing size of screen {0} from {1} to {2}",
|
Debug.Print("Changing size of screen {0} from {1} to {2}",
|
||||||
screen, current_resolution_index, new_resolution_index);
|
screen, current_resolution_index, new_resolution_index);
|
||||||
|
|
||||||
return 0 == Functions.XRRSetScreenConfigAndRate(API.DefaultDisplay, screen_config, root, new_resolution_index,
|
int ret = 0;
|
||||||
current_rotation, (short)(resolution != null ? resolution.RefreshRate : 0), lastConfigUpdate[screen]);
|
short refresh_rate =(short)(resolution != null ? resolution.RefreshRate : 0);
|
||||||
|
if (refresh_rate > 0)
|
||||||
|
{
|
||||||
|
ret = Functions.XRRSetScreenConfigAndRate(API.DefaultDisplay,
|
||||||
|
screen_config, root, new_resolution_index, current_rotation,
|
||||||
|
refresh_rate, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = Functions.XRRSetScreenConfig(API.DefaultDisplay,
|
||||||
|
screen_config, root, new_resolution_index, current_rotation,
|
||||||
|
IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
Debug.Print("[Error] Change to resolution {0} failed with error {1}.",
|
||||||
|
resolution, (ErrorCode)ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,9 +379,9 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- IDisplayDeviceDriver Members ---
|
#region IDisplayDeviceDriver Members
|
||||||
|
|
||||||
public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
|
||||||
{
|
{
|
||||||
// If resolution is null, restore the default resolution (new_resolution_index = 0).
|
// If resolution is null, restore the default resolution (new_resolution_index = 0).
|
||||||
|
|
||||||
|
@ -345,8 +399,7 @@ namespace OpenTK.Platform.X11
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed override bool TryRestoreResolution(DisplayDevice device)
|
||||||
public bool TryRestoreResolution(DisplayDevice device)
|
|
||||||
{
|
{
|
||||||
return TryChangeResolution(device, null);
|
return TryChangeResolution(device, null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue