mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Fix screen bounds determining in some cases in X11DisplayDevice
This commit is contained in:
parent
63530be40a
commit
e6ec7037aa
@ -92,8 +92,7 @@ namespace OpenTK
|
||||
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
|
||||
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
|
||||
public GameWindow(int width, int height, GraphicsMode mode, string title, bool nullContext,
|
||||
GameWindowFlags options, DisplayDevice device)
|
||||
: base(width, height, title, options, mode, device) {
|
||||
GameWindowFlags options, DisplayDevice device) : base(width, height, title, mode, device) {
|
||||
try {
|
||||
glContext = nullContext ? new NullContext() :
|
||||
Factory.Default.CreateGLContext(mode, WindowInfo);
|
||||
|
@ -37,15 +37,10 @@ namespace OpenTK {
|
||||
/// <summary> Instances of this class implement the <see cref="OpenTK.INativeWindow"/> interface on the current platform. </summary>
|
||||
public class NativeWindow : INativeWindow {
|
||||
|
||||
private readonly GameWindowFlags options;
|
||||
private readonly DisplayDevice device;
|
||||
private readonly INativeWindow implementation;
|
||||
private bool disposed, events;
|
||||
|
||||
/// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary>
|
||||
public NativeWindow()
|
||||
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { }
|
||||
|
||||
/// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the NativeWindow in pixels.</param>
|
||||
/// <param name="height">The height of the NativeWindow in pixels.</param>
|
||||
@ -55,10 +50,10 @@ namespace OpenTK {
|
||||
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
|
||||
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
|
||||
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
|
||||
public NativeWindow(int width, int height, string title, GraphicsMode mode, DisplayDevice device)
|
||||
: this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
|
||||
device.Bounds.Top + (device.Bounds.Height - height) / 2,
|
||||
width, height, title, options, mode, device) { }
|
||||
width, height, title, mode, device) { }
|
||||
|
||||
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
|
||||
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
|
||||
@ -71,7 +66,7 @@ namespace OpenTK {
|
||||
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
|
||||
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
|
||||
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device) {
|
||||
public NativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
|
||||
// TODO: Should a constraint be added for the position?
|
||||
if (width < 1)
|
||||
throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
|
||||
@ -82,10 +77,9 @@ namespace OpenTK {
|
||||
if (device == null)
|
||||
throw new ArgumentNullException("device");
|
||||
|
||||
this.options = options;
|
||||
this.device = device;
|
||||
|
||||
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
|
||||
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, this.device);
|
||||
}
|
||||
|
||||
/// <summary> Closes the NativeWindow. </summary>
|
||||
|
@ -31,7 +31,7 @@ using OpenTK.Graphics;
|
||||
namespace OpenTK.Platform {
|
||||
|
||||
interface IPlatformFactory {
|
||||
INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
|
||||
INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device);
|
||||
|
||||
void InitDisplayDeviceDriver();
|
||||
|
||||
@ -53,8 +53,8 @@ namespace OpenTK.Platform {
|
||||
namespace OpenTK.Platform.MacOS {
|
||||
class MacOSFactory : IPlatformFactory {
|
||||
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new CarbonGLNative(x, y, width, height, title, options, device);
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
|
||||
return new CarbonGLNative(x, y, width, height, title, device);
|
||||
}
|
||||
|
||||
public void InitDisplayDeviceDriver() {
|
||||
@ -70,8 +70,8 @@ namespace OpenTK.Platform.MacOS {
|
||||
namespace OpenTK.Platform.Windows {
|
||||
class WinFactory : IPlatformFactory {
|
||||
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new WinGLNative(x, y, width, height, title, options, device);
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
|
||||
return new WinGLNative(x, y, width, height, title, device);
|
||||
}
|
||||
|
||||
public void InitDisplayDeviceDriver() {
|
||||
@ -87,8 +87,8 @@ namespace OpenTK.Platform.Windows {
|
||||
namespace OpenTK.Platform.X11 {
|
||||
class X11Factory : IPlatformFactory {
|
||||
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new X11GLNative(x, y, width, height, title, mode, options, device);
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
|
||||
return new X11GLNative(x, y, width, height, title, mode, device);
|
||||
}
|
||||
|
||||
public void InitDisplayDeviceDriver() {
|
||||
|
@ -66,7 +66,7 @@ namespace OpenTK.Platform.MacOS
|
||||
Application.Initialize();
|
||||
}
|
||||
|
||||
public CarbonGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device)
|
||||
public CarbonGLNative(int x, int y, int width, int height, string title, DisplayDevice device)
|
||||
{
|
||||
this.title = title;
|
||||
CreateNativeWindow(WindowClass.Document,
|
||||
|
@ -64,15 +64,12 @@ namespace OpenTK.Platform.Windows
|
||||
const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys.
|
||||
KeyPressEventArgs key_press = new KeyPressEventArgs();
|
||||
|
||||
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) {
|
||||
public WinGLNative(int x, int y, int width, int height, string title, DisplayDevice device) {
|
||||
WindowProcedureDelegate = WindowProcedure;
|
||||
// To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be
|
||||
// bound to the top-level window, but rather to a child window docked in the parent.
|
||||
window = new WinWindowInfo(
|
||||
CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null);
|
||||
child_window = new WinWindowInfo(
|
||||
CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window);
|
||||
|
||||
window = new WinWindowInfo(CreateWindow(x, y, width, height, title, device, IntPtr.Zero), null);
|
||||
child_window = new WinWindowInfo(CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, device, window.WindowHandle), window);
|
||||
exists = true;
|
||||
}
|
||||
|
||||
@ -376,7 +373,7 @@ namespace OpenTK.Platform.Windows
|
||||
Marshal.GetLastWin32Error());
|
||||
}
|
||||
|
||||
IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle) {
|
||||
IntPtr CreateWindow(int x, int y, int width, int height, string title, DisplayDevice device, IntPtr parentHandle) {
|
||||
// Use win32 to create the native window.
|
||||
// Keep in mind that some construction code runs in the WM_CREATE message handler.
|
||||
|
||||
|
@ -79,39 +79,17 @@ namespace OpenTK.Platform.X11 {
|
||||
// Get available resolutions. Then, for each resolution get all available rates.
|
||||
foreach (DisplayDevice dev in devices) {
|
||||
int screen = (int)dev.Metadata;
|
||||
List<DisplayResolution> available_res = new List<DisplayResolution>();
|
||||
int[] depths = API.XListDepths(API.DefaultDisplay, screen);
|
||||
|
||||
int resolution_count = 0;
|
||||
foreach (XRRScreenSize size in FindAvailableResolutions(screen)) {
|
||||
if (size.Width == 0 || size.Height == 0) {
|
||||
Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
|
||||
continue;
|
||||
}
|
||||
short[] rates = API.XRRRates(API.DefaultDisplay, screen, resolution_count);
|
||||
|
||||
// It seems that XRRRates returns 0 for modes that are larger than the screen
|
||||
// can support, as well as for all supported modes. On Ubuntu 7.10 the tool
|
||||
// "Screens and Graphics" does report these modes, though.
|
||||
foreach (short rate in rates) {
|
||||
// Note: some X servers (like Xming on Windows) do not report any rates other than 0.
|
||||
// If we only have 1 rate, add it even if it is 0.
|
||||
if (rate != 0 || rates.Length == 1)
|
||||
foreach (int depth in depths)
|
||||
available_res.Add(new DisplayResolution(size.Width, size.Height, depth, rate));
|
||||
}
|
||||
++resolution_count;
|
||||
}
|
||||
|
||||
XRRScreenSize[] sizes = FindAvailableResolutions(screen);
|
||||
IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
|
||||
|
||||
ushort curRotation;
|
||||
int curResolutionIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
|
||||
int curSizesIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
|
||||
float curRefreshRate = API.XRRConfigCurrentRate(screenConfig);
|
||||
int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen);
|
||||
API.XRRFreeScreenConfigInfo(screenConfig);
|
||||
|
||||
if (dev.Bounds == Rectangle.Empty)
|
||||
dev.Bounds = new Rectangle(0, 0, available_res[curResolutionIndex].Width, available_res[curResolutionIndex].Height);
|
||||
dev.Bounds = new Rectangle(0, 0, sizes[curSizesIndex].Width, sizes[curSizesIndex].Height);
|
||||
dev.BitsPerPixel = curDepth;
|
||||
dev.RefreshRate = curRefreshRate;
|
||||
}
|
||||
|
@ -85,8 +85,7 @@ namespace OpenTK.Platform.X11 {
|
||||
int keysyms_per_keycode; // The number of KeySyms for each KeyCode.
|
||||
IntPtr[] keysyms;
|
||||
|
||||
public X11GLNative(int x, int y, int width, int height, string title,
|
||||
GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
|
||||
if (width <= 0)
|
||||
throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
|
||||
if (height <= 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user