2007-07-23 00:15:18 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Diagnostics;
|
2007-08-21 09:01:24 +00:00
|
|
|
|
using System.Reflection;
|
2007-09-02 23:18:50 +00:00
|
|
|
|
using OpenTK.OpenGL;
|
2007-09-26 11:58:55 +00:00
|
|
|
|
using OpenTK.Input;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
//using OpenTK.OpenGL;
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.X11
|
|
|
|
|
{
|
2007-08-05 13:42:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Drives GameWindow on X11.
|
|
|
|
|
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal sealed class X11GLNative : INativeGLWindow, IDisposable
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-05 13:42:31 +00:00
|
|
|
|
#region --- Fields ---
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-05 23:09:05 +00:00
|
|
|
|
private WindowInfo window = new WindowInfo();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
private DisplayMode mode = new DisplayMode();
|
2007-09-26 15:40:22 +00:00
|
|
|
|
private X11Input driver;
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
// Number of pending events.
|
|
|
|
|
private int pending = 0;
|
2007-08-05 10:33:23 +00:00
|
|
|
|
|
2007-08-21 12:04:01 +00:00
|
|
|
|
private int top, bottom, left, right;
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
// C# ResizeEventArgs
|
|
|
|
|
private ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
|
2007-08-05 10:33:23 +00:00
|
|
|
|
|
2007-09-26 11:58:55 +00:00
|
|
|
|
// Used for event loop.
|
2007-08-05 23:09:05 +00:00
|
|
|
|
private XEvent e = new XEvent();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
private bool disposed;
|
2007-08-06 12:13:50 +00:00
|
|
|
|
private bool exists;
|
2007-08-10 16:55:24 +00:00
|
|
|
|
private bool isExiting;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-09-26 15:40:22 +00:00
|
|
|
|
// XAtoms for window properties
|
|
|
|
|
private static IntPtr WMTitle; // The title of the GameWindow.
|
|
|
|
|
private static IntPtr UTF8String; // No idea.
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#region --- Public Constructors ---
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2007-08-05 10:33:23 +00:00
|
|
|
|
/// Constructs and initializes a new X11GLNative window.
|
|
|
|
|
/// Call CreateWindow to create the actual render window.
|
2007-07-23 00:15:18 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public X11GLNative()
|
|
|
|
|
{
|
2007-08-05 13:42:31 +00:00
|
|
|
|
Debug.Print("Native window driver: {0}", this.ToString());
|
2007-08-21 10:48:32 +00:00
|
|
|
|
|
2007-09-26 15:40:22 +00:00
|
|
|
|
//Utilities.ThrowOnX11Error = true; // Not very reliable
|
|
|
|
|
|
|
|
|
|
// Open the display to the X server, and obtain the screen and root window.
|
|
|
|
|
window.Display = API.OpenDisplay(null); // null == default display
|
|
|
|
|
if (window.Display == IntPtr.Zero)
|
|
|
|
|
throw new Exception("Could not open connection to X");
|
2007-12-09 18:15:51 +00:00
|
|
|
|
|
2007-09-26 15:40:22 +00:00
|
|
|
|
window.Screen = API.DefaultScreen(window.Display);
|
|
|
|
|
window.RootWindow = API.RootWindow(window.Display, window.Screen);
|
|
|
|
|
|
|
|
|
|
Debug.Print("Display: {0}, Screen {1}, Root window: {2}",
|
|
|
|
|
window.Display, window.Screen, window.RootWindow);
|
|
|
|
|
|
|
|
|
|
RegisterAtoms(window);
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-11-10 18:25:16 +00:00
|
|
|
|
#region private static void RegisterAtoms()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Not used yet.
|
|
|
|
|
/// Registers the necessary atoms for GameWindow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void RegisterAtoms(WindowInfo window)
|
|
|
|
|
{
|
|
|
|
|
string[] atom_names = new string[]
|
|
|
|
|
{
|
|
|
|
|
"WM_TITLE",
|
|
|
|
|
"UTF8_STRING"
|
|
|
|
|
};
|
|
|
|
|
IntPtr[] atoms = new IntPtr[atom_names.Length];
|
|
|
|
|
//Functions.XInternAtoms(window.Display, atom_names, atom_names.Length, false, atoms);
|
|
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
|
WMTitle = atoms[offset++];
|
|
|
|
|
UTF8String = atoms[offset++];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
#region --- INativeGLWindow Members ---
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#region public void ProcessEvents()
|
|
|
|
|
|
|
|
|
|
public void ProcessEvents()
|
|
|
|
|
{
|
|
|
|
|
// Process all pending events
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2007-08-06 12:13:50 +00:00
|
|
|
|
//pending = Functions.XPending(window.Display);
|
|
|
|
|
pending = API.Pending(window.Display);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
if (pending == 0)
|
|
|
|
|
return;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
2007-08-05 23:09:05 +00:00
|
|
|
|
Functions.XNextEvent(window.Display, ref e);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-09-26 11:58:55 +00:00
|
|
|
|
//Debug.Print("Event: {0} ({1} pending)", e.type, pending);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
// Respond to the event e
|
2007-08-05 23:09:05 +00:00
|
|
|
|
switch (e.type)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-21 09:01:24 +00:00
|
|
|
|
case XEventName.MapNotify:
|
|
|
|
|
Debug.WriteLine("Window mapped.");
|
|
|
|
|
return;
|
|
|
|
|
|
2007-08-05 23:09:05 +00:00
|
|
|
|
case XEventName.CreateNotify:
|
2007-08-20 10:46:37 +00:00
|
|
|
|
// A child was was created - nothing to do
|
2007-07-23 00:15:18 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-10 18:25:16 +00:00
|
|
|
|
case XEventName.ClientMessage:
|
2007-11-11 20:10:08 +00:00
|
|
|
|
this.OnDestroy(EventArgs.Empty);
|
|
|
|
|
break;
|
2007-11-10 18:25:16 +00:00
|
|
|
|
|
2007-11-11 20:10:08 +00:00
|
|
|
|
case XEventName.DestroyNotify:
|
2007-11-11 20:22:51 +00:00
|
|
|
|
exists = false;
|
2007-08-10 16:55:24 +00:00
|
|
|
|
isExiting = true;
|
2007-08-06 12:13:50 +00:00
|
|
|
|
Debug.Print("X11 window {0} destroyed.", e.DestroyWindowEvent.window);
|
|
|
|
|
return;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
2007-08-05 23:09:05 +00:00
|
|
|
|
case XEventName.ConfigureNotify:
|
2007-07-23 00:15:18 +00:00
|
|
|
|
// If the window size changed, raise the C# Resize event.
|
2007-08-05 23:09:05 +00:00
|
|
|
|
if (e.ConfigureEvent.width != mode.Width ||
|
|
|
|
|
e.ConfigureEvent.height != mode.Height)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine(
|
|
|
|
|
String.Format(
|
|
|
|
|
"New res: {0}x{1}",
|
2007-08-05 23:09:05 +00:00
|
|
|
|
e.ConfigureEvent.width,
|
|
|
|
|
e.ConfigureEvent.height
|
2007-07-23 00:15:18 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2007-08-05 23:09:05 +00:00
|
|
|
|
resizeEventArgs.Width = e.ConfigureEvent.width;
|
|
|
|
|
resizeEventArgs.Height = e.ConfigureEvent.height;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
this.OnResize(resizeEventArgs);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-08-20 13:47:14 +00:00
|
|
|
|
case XEventName.KeyPress:
|
|
|
|
|
case XEventName.KeyRelease:
|
2007-09-25 16:45:12 +00:00
|
|
|
|
case XEventName.MotionNotify:
|
|
|
|
|
case XEventName.ButtonPress:
|
|
|
|
|
case XEventName.ButtonRelease:
|
2007-09-26 11:58:55 +00:00
|
|
|
|
//Functions.XPutBackEvent(window.Display, ref e);
|
2007-11-10 18:25:16 +00:00
|
|
|
|
driver.ProcessEvent(ref e);
|
2007-09-26 11:58:55 +00:00
|
|
|
|
break;
|
2007-08-20 13:47:14 +00:00
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
default:
|
2007-08-05 23:09:05 +00:00
|
|
|
|
Debug.WriteLine(String.Format("{0} event was not handled", e.type));
|
2007-07-23 00:15:18 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-11-10 18:25:16 +00:00
|
|
|
|
#region public IInputDriver InputDriver
|
|
|
|
|
|
|
|
|
|
public IInputDriver InputDriver
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return driver;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-06 09:22:04 +00:00
|
|
|
|
#region public bool Exists
|
2007-07-27 01:20:55 +00:00
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if a render window/context exists.
|
|
|
|
|
/// </summary>
|
2007-08-06 09:22:04 +00:00
|
|
|
|
public bool Exists
|
2007-07-27 01:20:55 +00:00
|
|
|
|
{
|
2007-08-06 12:13:50 +00:00
|
|
|
|
get { return exists; }
|
2007-07-27 01:20:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#region public bool Quit
|
|
|
|
|
|
2007-08-10 16:55:24 +00:00
|
|
|
|
public bool IsExiting
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-10 16:55:24 +00:00
|
|
|
|
get { return isExiting; }
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public bool IsIdle
|
|
|
|
|
|
|
|
|
|
public bool IsIdle
|
|
|
|
|
{
|
|
|
|
|
get { throw new Exception("The method or operation is not implemented."); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public bool Fullscreen
|
|
|
|
|
|
|
|
|
|
public bool Fullscreen
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2007-08-05 13:51:07 +00:00
|
|
|
|
return false;
|
|
|
|
|
//throw new Exception("The method or operation is not implemented.");
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2007-08-05 13:51:07 +00:00
|
|
|
|
|
|
|
|
|
//throw new Exception("The method or operation is not implemented.");
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
#region public IntPtr Handle
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the current window handle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IntPtr Handle
|
|
|
|
|
{
|
2007-08-05 23:09:05 +00:00
|
|
|
|
get { return this.window.Handle; }
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-09-26 15:40:22 +00:00
|
|
|
|
#region public string Title
|
2007-09-26 11:58:55 +00:00
|
|
|
|
|
2007-09-26 15:40:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// TODO: Use atoms for this property.
|
|
|
|
|
/// Gets or sets the GameWindow title.
|
|
|
|
|
/// </summary>
|
2007-09-26 11:58:55 +00:00
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2007-09-26 15:40:22 +00:00
|
|
|
|
IntPtr name = IntPtr.Zero;
|
|
|
|
|
Functions.XFetchName(window.Display, window.Handle, ref name);
|
|
|
|
|
if (name != IntPtr.Zero)
|
|
|
|
|
return Marshal.PtrToStringAnsi(name);
|
|
|
|
|
|
2007-09-26 11:58:55 +00:00
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2007-09-26 15:40:22 +00:00
|
|
|
|
/*
|
|
|
|
|
XTextProperty name = new XTextProperty();
|
|
|
|
|
name.format = 8; //STRING
|
|
|
|
|
if (value == null)
|
|
|
|
|
name.value = String.Empty;
|
|
|
|
|
else
|
|
|
|
|
name.value = value;
|
|
|
|
|
|
|
|
|
|
Functions.XSetWMName(window.Display, window.Handle, ref name);
|
|
|
|
|
*/
|
|
|
|
|
if (value != null)
|
|
|
|
|
Functions.XStoreName(window.Display, window.Handle, value);
|
2007-09-26 11:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public bool Visible
|
|
|
|
|
|
2007-09-26 15:40:22 +00:00
|
|
|
|
bool mapped;
|
2007-09-26 11:58:55 +00:00
|
|
|
|
public bool Visible
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2007-09-26 15:40:22 +00:00
|
|
|
|
//return true;
|
|
|
|
|
return mapped;
|
2007-09-26 11:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2007-09-26 15:40:22 +00:00
|
|
|
|
if (value && !mapped)
|
|
|
|
|
{
|
|
|
|
|
Functions.XMapWindow(window.Display, window.Handle);
|
|
|
|
|
mapped = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!value && mapped)
|
|
|
|
|
{
|
|
|
|
|
Functions.XUnmapWindow(window.Display, window.Handle);
|
|
|
|
|
mapped = false;
|
|
|
|
|
}
|
2007-09-26 11:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-11-04 15:38:39 +00:00
|
|
|
|
/*
|
2007-09-26 11:58:55 +00:00
|
|
|
|
#region public IInputDriver InputDriver
|
|
|
|
|
|
|
|
|
|
public IInputDriver InputDriver
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return driver;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-11-04 15:38:39 +00:00
|
|
|
|
*/
|
2007-08-05 13:42:31 +00:00
|
|
|
|
#region public IWindowInfo WindowInfo
|
|
|
|
|
|
|
|
|
|
public IWindowInfo WindowInfo
|
|
|
|
|
{
|
2007-08-05 23:09:05 +00:00
|
|
|
|
get { return window; }
|
2007-08-05 13:42:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-15 10:31:03 +00:00
|
|
|
|
#region public void CreateWindow(DisplayMode mode, out GLContext glContext)
|
2007-08-06 12:13:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens a new render window with the given DisplayMode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mode">The DisplayMode of the render window.</param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Creates the window visual and colormap. Associates the colormap/visual
|
|
|
|
|
/// with the window and raises the window on top of the window stack.
|
|
|
|
|
/// <para>
|
|
|
|
|
/// Colormap creation is currently disabled.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// </remarks>
|
2008-01-15 10:31:03 +00:00
|
|
|
|
public void CreateWindow(DisplayMode mode, out GLContext glContext)
|
2007-08-06 11:22:18 +00:00
|
|
|
|
{
|
2007-08-06 12:13:50 +00:00
|
|
|
|
if (exists)
|
|
|
|
|
throw new ApplicationException("Render window already exists!");
|
|
|
|
|
|
2008-01-06 11:02:38 +00:00
|
|
|
|
Debug.Print("Creating GameWindow with mode: {0}", mode != null ? mode.ToString() : "default");
|
2007-12-09 18:15:51 +00:00
|
|
|
|
Debug.Indent();
|
|
|
|
|
|
2008-01-15 10:31:03 +00:00
|
|
|
|
glContext = new GLContext(mode, window);
|
|
|
|
|
(glContext as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
2008-01-11 20:23:17 +00:00
|
|
|
|
window.VisualInfo = ((glContext as IGLContextInternal).Info as X11.WindowInfo).VisualInfo;
|
2007-12-09 18:15:51 +00:00
|
|
|
|
//window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen,
|
|
|
|
|
|
|
|
|
|
// Create a window on this display using the visual above
|
|
|
|
|
Debug.Write("Opening render window... ");
|
|
|
|
|
|
|
|
|
|
XSetWindowAttributes attributes = new XSetWindowAttributes();
|
|
|
|
|
attributes.background_pixel = IntPtr.Zero;
|
|
|
|
|
attributes.border_pixel = IntPtr.Zero;
|
|
|
|
|
attributes.colormap =
|
|
|
|
|
API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/);
|
|
|
|
|
window.EventMask =
|
|
|
|
|
EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask |
|
|
|
|
|
EventMask.KeyReleaseMask | EventMask.KeyPressMask;/* |
|
2007-09-26 11:58:55 +00:00
|
|
|
|
EventMask.PointerMotionMask | /* Bad! EventMask.PointerMotionHintMask |
|
|
|
|
|
EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;*/
|
2007-12-09 18:15:51 +00:00
|
|
|
|
attributes.event_mask = (IntPtr)window.EventMask;
|
2007-08-06 12:13:50 +00:00
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
|
|
|
|
|
(uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;
|
2007-08-10 16:55:24 +00:00
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
|
|
|
|
|
0, 0, mode.Width, mode.Height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/,
|
|
|
|
|
(int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes);
|
2007-08-06 12:13:50 +00:00
|
|
|
|
|
2007-12-09 18:15:51 +00:00
|
|
|
|
if (window.Handle == IntPtr.Zero)
|
|
|
|
|
throw new ApplicationException("XCreateWindow call failed (returned 0).");
|
|
|
|
|
|
|
|
|
|
// Set the window hints
|
|
|
|
|
XSizeHints hints = new XSizeHints();
|
|
|
|
|
hints.x = 0;
|
|
|
|
|
hints.y = 0;
|
|
|
|
|
hints.width = mode.Width;
|
|
|
|
|
hints.height = mode.Height;
|
|
|
|
|
hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition);
|
|
|
|
|
Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);
|
|
|
|
|
|
|
|
|
|
// Register for window destroy notification
|
|
|
|
|
IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display,
|
|
|
|
|
"WM_DELETE_WINDOW", true);
|
|
|
|
|
XWMHints hint = new XWMHints();
|
|
|
|
|
Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1);
|
|
|
|
|
|
|
|
|
|
Top = Left = 0;
|
|
|
|
|
Right = Width;
|
|
|
|
|
Bottom = Height;
|
|
|
|
|
|
|
|
|
|
//XTextProperty text = new XTextProperty();
|
|
|
|
|
//text.value = "OpenTK Game Window";
|
|
|
|
|
//text.format = 8;
|
|
|
|
|
//Functions.XSetWMName(window.Display, window.Handle, ref text);
|
|
|
|
|
//Functions.XSetWMProperties(display, window, name, name, 0, /*None*/ null, 0, hints);
|
|
|
|
|
|
|
|
|
|
Debug.Print("done! (id: {0})", window.Handle);
|
|
|
|
|
|
2008-01-15 10:31:03 +00:00
|
|
|
|
(glContext as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
2007-12-09 18:15:51 +00:00
|
|
|
|
|
|
|
|
|
API.MapRaised(window.Display, window.Handle);
|
|
|
|
|
mapped = true;
|
|
|
|
|
|
|
|
|
|
driver = new X11Input(window);
|
|
|
|
|
|
|
|
|
|
//GL.LoadAll();
|
|
|
|
|
//Glu.LoadAll();
|
|
|
|
|
|
|
|
|
|
Debug.Unindent();
|
|
|
|
|
Debug.WriteLine("GameWindow creation completed successfully!");
|
|
|
|
|
exists = true;
|
2007-08-06 11:22:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-06 12:13:50 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-06 11:22:18 +00:00
|
|
|
|
#region OnCreate
|
|
|
|
|
|
|
|
|
|
public event CreateEvent Create;
|
|
|
|
|
|
2007-08-21 09:01:24 +00:00
|
|
|
|
private void OnCreate(EventArgs e)
|
2007-08-06 11:22:18 +00:00
|
|
|
|
{
|
|
|
|
|
if (this.Create != null)
|
|
|
|
|
{
|
|
|
|
|
Debug.Print("Create event fired from window: {0}", window.ToString());
|
|
|
|
|
this.Create(this, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-06 12:13:50 +00:00
|
|
|
|
#region public void Exit()
|
|
|
|
|
|
|
|
|
|
public void Exit()
|
|
|
|
|
{
|
|
|
|
|
this.DestroyWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public void DestroyWindow()
|
|
|
|
|
|
|
|
|
|
public void DestroyWindow()
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("X11GLNative shutdown sequence initiated.");
|
|
|
|
|
Functions.XDestroyWindow(window.Display, window.Handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnDestroy
|
|
|
|
|
|
2007-08-21 09:01:24 +00:00
|
|
|
|
public event DestroyEvent Destroy;
|
|
|
|
|
|
|
|
|
|
private void OnDestroy(EventArgs e)
|
2007-08-06 11:22:18 +00:00
|
|
|
|
{
|
2007-08-06 12:13:50 +00:00
|
|
|
|
Debug.Print("Destroy event fired from window: {0}", window.ToString());
|
|
|
|
|
if (this.Destroy != null)
|
|
|
|
|
this.Destroy(this, e);
|
2007-08-06 11:22:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-01-06 02:29:14 +00:00
|
|
|
|
#region PointToClient
|
|
|
|
|
|
|
|
|
|
public void PointToClient(ref System.Drawing.Point p)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
if (!Functions.ScreenToClient(this.Handle, p))
|
|
|
|
|
throw new InvalidOperationException(String.Format(
|
|
|
|
|
"Could not convert point {0} from client to screen coordinates. Windows error: {1}",
|
|
|
|
|
p.ToString(), Marshal.GetLastWin32Error()));
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region PointToScreen
|
|
|
|
|
|
|
|
|
|
public void PointToScreen(ref System.Drawing.Point p)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-06 12:13:50 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#region --- IResizable Members ---
|
|
|
|
|
|
|
|
|
|
#region public int Width
|
|
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return mode.Width;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{/*
|
|
|
|
|
// Clear event struct
|
|
|
|
|
//Array.Clear(xresize.pad, 0, xresize.pad.Length);
|
|
|
|
|
// Set requested parameters
|
|
|
|
|
xresize.ResizeRequest.type = EventType.ResizeRequest;
|
|
|
|
|
xresize.ResizeRequest.display = this.display;
|
|
|
|
|
xresize.ResizeRequest.width = value;
|
|
|
|
|
xresize.ResizeRequest.height = mode.Width;
|
|
|
|
|
API.SendEvent(
|
|
|
|
|
this.display,
|
|
|
|
|
this.window,
|
|
|
|
|
false,
|
|
|
|
|
EventMask.StructureNotifyMask,
|
|
|
|
|
ref xresize
|
|
|
|
|
);*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public int Height
|
|
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return mode.Height;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{/*
|
|
|
|
|
// Clear event struct
|
|
|
|
|
//Array.Clear(xresize.pad, 0, xresize.pad.Length);
|
|
|
|
|
// Set requested parameters
|
|
|
|
|
xresize.ResizeRequest.type = EventType.ResizeRequest;
|
|
|
|
|
xresize.ResizeRequest.display = this.display;
|
|
|
|
|
xresize.ResizeRequest.width = mode.Width;
|
|
|
|
|
xresize.ResizeRequest.height = value;
|
|
|
|
|
API.SendEvent(
|
|
|
|
|
this.display,
|
|
|
|
|
this.window,
|
|
|
|
|
false,
|
|
|
|
|
EventMask.StructureNotifyMask,
|
|
|
|
|
ref xresize
|
|
|
|
|
);*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public event ResizeEvent Resize
|
|
|
|
|
|
|
|
|
|
public event ResizeEvent Resize;
|
|
|
|
|
|
|
|
|
|
private void OnResize(ResizeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
mode.Width = e.Width;
|
|
|
|
|
mode.Height = e.Height;
|
|
|
|
|
if (this.Resize != null)
|
|
|
|
|
{
|
|
|
|
|
this.Resize(this, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-21 12:04:01 +00:00
|
|
|
|
public int Top
|
|
|
|
|
{
|
|
|
|
|
get { return top; }
|
|
|
|
|
private set { top = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Bottom
|
|
|
|
|
{
|
|
|
|
|
get { return bottom; }
|
|
|
|
|
private set { bottom = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Left
|
|
|
|
|
{
|
|
|
|
|
get { return left; }
|
|
|
|
|
private set { left = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Right
|
|
|
|
|
{
|
|
|
|
|
get { return right; }
|
|
|
|
|
private set { right = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IDisposable Members ---
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
this.Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dispose(bool manuallyCalled)
|
|
|
|
|
{
|
|
|
|
|
if (!disposed)
|
|
|
|
|
{
|
|
|
|
|
if (manuallyCalled)
|
|
|
|
|
{
|
2007-12-09 18:15:51 +00:00
|
|
|
|
//if (glContext != null)
|
|
|
|
|
// glContext.Dispose();
|
2007-11-11 20:10:08 +00:00
|
|
|
|
|
|
|
|
|
// Kills connection to the X-Server. We don't want that,
|
|
|
|
|
// 'cause it kills the ExampleLauncher too.
|
|
|
|
|
//Functions.XCloseDisplay(window.Display);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
2007-11-11 20:10:08 +00:00
|
|
|
|
|
|
|
|
|
Functions.XUnmapWindow(window.Display, window.Handle);
|
|
|
|
|
Functions.XDestroyWindow(window.Display, window.Handle);
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~X11GLNative()
|
|
|
|
|
{
|
|
|
|
|
this.Dispose(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|