Added IWindowInfo.cs, X11/WindowInfo.cs and Windows/WindowInfo.cs, which hold information regarding a platform specific window object.
Updated everything to not use raw window handles, but rather WindowInfo objects. Added code that (hopefully) creates an invisible input window for X11.
This commit is contained in:
parent
0172ff101c
commit
b630d84add
19 changed files with 405 additions and 155 deletions
|
@ -24,29 +24,38 @@ namespace Examples
|
|||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
using (Form exampleLauncher = new ExampleLauncher())
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.Run(exampleLauncher);
|
||||
}
|
||||
}
|
||||
StreamWriter sw = new StreamWriter(Path.Combine(System.Environment.CurrentDirectory, "keymap.log"));
|
||||
public ExampleLauncher()
|
||||
{
|
||||
InitializeComponent();
|
||||
StreamWriter sw = new StreamWriter(Path.Combine(System.Environment.CurrentDirectory, "debug.log"));
|
||||
System.Diagnostics.Debug.Listeners.Clear();
|
||||
System.Diagnostics.Debug.Listeners.Add(new TextWriterTraceListener(sw));
|
||||
System.Diagnostics.Debug.AutoFlush = true;
|
||||
Debug.AutoFlush = true;
|
||||
System.Diagnostics.Trace.Listeners.Clear();
|
||||
System.Diagnostics.Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
|
||||
System.Diagnostics.Trace.AutoFlush = true;
|
||||
Trace.AutoFlush = true;
|
||||
|
||||
try
|
||||
{
|
||||
using (Form exampleLauncher = new ExampleLauncher())
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.Run(exampleLauncher);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Debug.Flush();
|
||||
Debug.Close();
|
||||
Trace.Flush();
|
||||
Trace.Close();
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
~ExampleLauncher()
|
||||
public ExampleLauncher()
|
||||
{
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void listBox1_DoubleClick(object sender, EventArgs e)
|
||||
|
@ -100,27 +109,7 @@ namespace Examples
|
|||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e.ToString());
|
||||
//throw;
|
||||
}
|
||||
//(example as Type).InvokeMember("Launch", BindingFlags.InvokeMethod, null, example, null);
|
||||
/*
|
||||
AppDomain app = AppDomain.CreateDomain((example as Type).Name);
|
||||
|
||||
Type exType = example as Type;
|
||||
try
|
||||
{
|
||||
IExample ex = app.CreateInstanceAndUnwrap(
|
||||
exType.Assembly.GetName().Name,
|
||||
"Examples.Tests.Shim") as IExample;
|
||||
ex.Launch();
|
||||
//ex.InvokeMember("Launch", BindingFlags.InvokeMethod, null, null, null);
|
||||
//
|
||||
}
|
||||
finally
|
||||
{
|
||||
AppDomain.Unload(app);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void ExampleLauncher_Load(object sender, EventArgs e)
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Examples.WinForms
|
|||
{
|
||||
base.OnHandleCreated(e);
|
||||
|
||||
input = new OpenTK.InputDriver(this.Handle);
|
||||
input = new OpenTK.InputDriver(OpenTK.Platform.Utilities.GetWindowInfo(this));
|
||||
}
|
||||
|
||||
private void redButton_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -29,7 +29,6 @@ namespace OpenTK
|
|||
{
|
||||
#region --- Private Fields ---
|
||||
|
||||
private bool fullscreen;
|
||||
private IGLControl glControl;
|
||||
|
||||
#endregion
|
||||
|
@ -85,7 +84,7 @@ namespace OpenTK
|
|||
if (height > 0)
|
||||
this.Height = height;
|
||||
*/
|
||||
if (fullscreen)
|
||||
if (mode.Fullscreen)
|
||||
this.Fullscreen = true;
|
||||
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
|
@ -136,17 +135,11 @@ namespace OpenTK
|
|||
{
|
||||
get
|
||||
{
|
||||
return fullscreen;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!fullscreen && value)
|
||||
{
|
||||
//fullscreen = this.SetFullscreenResolution(this.Width, this.Height);
|
||||
}
|
||||
else if (fullscreen && !value)
|
||||
{
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,21 +15,15 @@ namespace OpenTK
|
|||
{
|
||||
public class GameWindow : OpenTK.Platform.IGameWindow
|
||||
{
|
||||
private INativeWindow glWindow;
|
||||
#region --- Fields ---
|
||||
|
||||
private INativeGLWindow glWindow;
|
||||
private ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
|
||||
private DisplayMode mode;
|
||||
|
||||
private InputDriver inputDevices;
|
||||
public IList<Input.Keyboard> Keyboard { get { return Input.Keyboard; } }
|
||||
public InputDriver Input
|
||||
{
|
||||
get
|
||||
{
|
||||
if (inputDevices == null)
|
||||
inputDevices = new InputDriver(this.Handle);
|
||||
return inputDevices;
|
||||
}
|
||||
}
|
||||
private InputDriver driver;
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Contructors ---
|
||||
|
||||
|
@ -41,19 +35,16 @@ namespace OpenTK
|
|||
if (Environment.OSVersion.Platform == PlatformID.Win32NT ||
|
||||
Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
||||
{
|
||||
// Create a new Windows native window. We want to be notified when it's ready,
|
||||
// in order to do some preparatory work.
|
||||
glWindow = new OpenTK.Platform.Windows.WinGLNative();
|
||||
}
|
||||
else if (Environment.OSVersion.Platform == PlatformID.Unix ||
|
||||
Environment.OSVersion.Platform == (PlatformID)128) // some older versions of Mono reported 128.
|
||||
else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
glWindow = new OpenTK.Platform.X11.X11GLNative();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException(
|
||||
"Your operating system is not currently supported. We are sorry for the inconvenience."
|
||||
"Your platform is not currently supported. Refer to http://opentk.sourceforge.net for more information."
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -64,7 +55,7 @@ namespace OpenTK
|
|||
void glWindow_Create(object sender, EventArgs e)
|
||||
{
|
||||
//glWindow.Context.MakeCurrent();
|
||||
inputDevices = new InputDriver(this.Handle);
|
||||
driver = new InputDriver(this.WindowInfo);
|
||||
|
||||
this.OnCreate(e);
|
||||
}
|
||||
|
@ -76,7 +67,51 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- INativeWindow Members ---
|
||||
#region --- Public Properties ---
|
||||
|
||||
#region public IList<Input.Keyboard> Keyboard
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of available Keyboard devices.
|
||||
/// </summary>
|
||||
public IList<Input.Keyboard> Keyboard
|
||||
{
|
||||
get
|
||||
{
|
||||
if (driver == null)
|
||||
{
|
||||
Debug.WriteLine("WARNING: Requested the list of Keyboard devices, without creating an InputDriver first. Continuing by creating an input driver, but this may indicate a prorgamming error.");
|
||||
driver = new InputDriver(this.WindowInfo);
|
||||
}
|
||||
return driver.Keyboard;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public IList<OpenTK.Input.IInputDevice> Input
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of available InputDevices.
|
||||
/// </summary>
|
||||
public IList<OpenTK.Input.IInputDevice> Input
|
||||
{
|
||||
get
|
||||
{
|
||||
if (driver == null)
|
||||
{
|
||||
Debug.WriteLine("WARNING: Requested available InputDevices, without creating an InputDriver first. Continuing by creating an input driver, but this may indicate a prorgamming error.");
|
||||
driver = new InputDriver(this.WindowInfo);
|
||||
}
|
||||
return driver.InputDevices;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- INativeGLWindow Members ---
|
||||
|
||||
#region public void CreateWindow(DisplayMode mode)
|
||||
|
||||
|
@ -99,18 +134,6 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region public IntPtr Handle
|
||||
|
||||
/// <summary>
|
||||
/// Gets the handle of the current GameWindow.
|
||||
/// </summary>
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return glWindow.Handle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Exit()
|
||||
|
||||
/// <summary>
|
||||
|
@ -197,6 +220,15 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region public IWindowInfo WindowInfo
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get { return glWindow.WindowInfo; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGameWindow Members ---
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
|
||||
using OpenTK.Input;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
|
@ -10,16 +11,17 @@ namespace OpenTK
|
|||
{
|
||||
IInputDriver inputDriver;
|
||||
|
||||
public InputDriver(IntPtr parentHandle)
|
||||
public InputDriver(IWindowInfo parent)
|
||||
{
|
||||
if (Environment.OSVersion.Version.Major > 5 ||
|
||||
(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
|
||||
{
|
||||
inputDriver = new OpenTK.Platform.Windows.WinRawInput(parentHandle);
|
||||
inputDriver = new OpenTK.Platform.Windows.WinRawInput(parent.Handle);
|
||||
}
|
||||
else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
inputDriver = new OpenTK.Platform.X11.X11Input(parentHandle);
|
||||
inputDriver =
|
||||
new OpenTK.Platform.X11.X11Input(parent as OpenTK.Platform.X11.WindowInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
interface IGameWindow : INativeWindow
|
||||
interface IGameWindow : INativeGLWindow
|
||||
{
|
||||
void Run();
|
||||
|
||||
|
|
|
@ -4,7 +4,10 @@ using System.Text;
|
|||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
interface INativeWindow : IGLControl, IResizable
|
||||
/// <summary>
|
||||
/// This interface supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
interface INativeGLWindow : IGLControl, IResizable
|
||||
{
|
||||
void CreateWindow(DisplayMode mode);
|
||||
void ProcessEvents();
|
||||
|
@ -12,6 +15,6 @@ namespace OpenTK.Platform
|
|||
|
||||
bool Created { get; }
|
||||
bool Quit { get; }
|
||||
IntPtr Handle { get; }
|
||||
IWindowInfo WindowInfo { get; }
|
||||
}
|
||||
}
|
|
@ -4,7 +4,12 @@ using System.Text;
|
|||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
public interface IWindowInfo
|
||||
{
|
||||
IntPtr Handle { get; }
|
||||
IWindowInfo Parent { get; }
|
||||
}
|
||||
}
|
||||
|
|
18
Source/OpenTK/Platform/Utilities.cs
Normal file
18
Source/OpenTK/Platform/Utilities.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides cross-platform utilities to help interact with the underlying platform.
|
||||
/// </summary>
|
||||
public static class Utilities
|
||||
{
|
||||
public static IWindowInfo GetWindowInfo(Form form)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,16 +17,22 @@ using System.Diagnostics;
|
|||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
sealed class WinGLNative : NativeWindow, OpenTK.Platform.INativeWindow, IDisposable
|
||||
/// <summary>
|
||||
/// Drives GameWindow on Windows.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
sealed class WinGLNative : NativeWindow, OpenTK.Platform.INativeGLWindow, IDisposable
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
||||
private WinGLContext glContext;
|
||||
private DisplayMode mode = new DisplayMode();
|
||||
|
||||
private bool fullscreen = false;
|
||||
private bool disposed;
|
||||
private bool quit;
|
||||
private bool created;
|
||||
private WindowInfo info;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -38,6 +44,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// </summary>
|
||||
public WinGLNative()
|
||||
{
|
||||
Debug.Print("Native window driver: {0}", this.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -79,6 +86,12 @@ namespace OpenTK.Platform.Windows
|
|||
mode.Width = Marshal.ReadInt32(m.LParam, (int)Marshal.OffsetOf(typeof(API.CreateStruct), "cx"));
|
||||
mode.Height = Marshal.ReadInt32(m.LParam, (int)Marshal.OffsetOf(typeof(API.CreateStruct), "cy"));
|
||||
|
||||
info = new WindowInfo();
|
||||
info.Handle = this.Handle;
|
||||
info.Parent = null;
|
||||
|
||||
Debug.Print("Window handle: {0}", this.Handle);
|
||||
|
||||
// Raise the Create event
|
||||
this.OnCreate(EventArgs.Empty);
|
||||
|
||||
|
@ -92,20 +105,23 @@ namespace OpenTK.Platform.Windows
|
|||
//case API.Constants.WM_KEYUP:
|
||||
// break;
|
||||
|
||||
//case API.Constants.WM_INPUT: // Raw input
|
||||
// WinRawInput.ProcessEvent(ref msg, key);
|
||||
// break;
|
||||
|
||||
case API.Constants.WM_CLOSE:
|
||||
//this.Exit();
|
||||
//return;
|
||||
break;
|
||||
|
||||
case API.Constants.WM_DESTROY:
|
||||
Debug.Print("Window handle {0} destroyed.", this.Handle);
|
||||
this.DestroyHandle();
|
||||
if (this.Handle != IntPtr.Zero)
|
||||
{
|
||||
Debug.Print("Window handle {0} destroyed.", this.Handle);
|
||||
this.DestroyHandle();
|
||||
}
|
||||
API.PostQuitMessage(0);
|
||||
return;
|
||||
|
||||
case API.Constants.WM_QUIT:
|
||||
quit = true;
|
||||
Debug.WriteLine("Window quit.");
|
||||
Debug.WriteLine("Application quit.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,12 +131,15 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- INativeWindow Members ---
|
||||
#region --- INativeGLWindow Members ---
|
||||
|
||||
#region private void CreateWindow(DisplayMode mode)
|
||||
|
||||
public void CreateWindow(DisplayMode mode)
|
||||
{
|
||||
Debug.Print("Creating native window with mode: {0}", mode.ToString());
|
||||
Debug.Indent();
|
||||
|
||||
CreateParams cp = new CreateParams();
|
||||
cp.ClassStyle =
|
||||
(int)API.WindowClassStyle.OwnDC |
|
||||
|
@ -134,7 +153,10 @@ namespace OpenTK.Platform.Windows
|
|||
cp.Width = mode.Width;
|
||||
cp.Height = mode.Height;
|
||||
cp.Caption = "OpenTK Game Window";
|
||||
base.CreateHandle(cp);
|
||||
|
||||
// Keep in mind that some construction code runs in WM_CREATE,
|
||||
// which is raised CreateHandle()
|
||||
CreateHandle(cp);
|
||||
|
||||
glContext = new WinGLContext(
|
||||
this.Handle,
|
||||
|
@ -151,6 +173,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
if (this.Handle != IntPtr.Zero && glContext != null)
|
||||
{
|
||||
Debug.WriteLine("Window creation was succesful.");
|
||||
created = true;
|
||||
}
|
||||
else
|
||||
|
@ -159,6 +182,8 @@ namespace OpenTK.Platform.Windows
|
|||
"Could not create native window and/or context. Handle: {0}, Context {1}",
|
||||
this.Handle, this.Context.ToString()));
|
||||
}
|
||||
|
||||
Debug.Unindent();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -288,7 +313,6 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region public bool Fullscreen
|
||||
|
||||
bool fullscreen;
|
||||
public bool Fullscreen
|
||||
{
|
||||
get
|
||||
|
@ -317,6 +341,15 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region public IWindowInfo WindowInfo
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get { return info; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable Members ---
|
||||
|
|
|
@ -24,17 +24,19 @@ namespace OpenTK.Platform.Windows
|
|||
/// Input event data.
|
||||
/// </summary>
|
||||
private API.RawInput data = new API.RawInput();
|
||||
|
||||
/// <summary>
|
||||
/// The list of keyboards connected to this system.
|
||||
/// The total number of input devices connected to this system.
|
||||
/// </summary>
|
||||
//internal List<WinRawKeyboard> keyboards = new List<WinRawKeyboard>();
|
||||
private static int deviceCount;
|
||||
|
||||
|
||||
private WinRawKeyboard keyboardDriver;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
internal WinRawInput(IntPtr parentHandle)
|
||||
{
|
||||
Debug.WriteLine("Initalizing raw input driver.");
|
||||
Debug.WriteLine("Initalizing windows raw input driver.");
|
||||
Debug.Indent();
|
||||
|
||||
AssignHandle(parentHandle);
|
||||
|
@ -44,7 +46,7 @@ namespace OpenTK.Platform.Windows
|
|||
Debug.Unindent();
|
||||
}
|
||||
|
||||
private static int deviceCount;
|
||||
#endregion
|
||||
|
||||
internal static int DeviceCount
|
||||
{
|
||||
|
@ -54,6 +56,7 @@ namespace OpenTK.Platform.Windows
|
|||
return deviceCount;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Device list has changed, for example
|
||||
|
|
32
Source/OpenTK/Platform/Windows/WindowInfo.cs
Normal file
32
Source/OpenTK/Platform/Windows/WindowInfo.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes a Windows window.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal class WindowInfo : IWindowInfo
|
||||
{
|
||||
private IntPtr handle;
|
||||
private WindowInfo parent;
|
||||
|
||||
#region --- IWindowInfo Members ---
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return handle; }
|
||||
internal set { handle = value; }
|
||||
}
|
||||
|
||||
public IWindowInfo Parent
|
||||
{
|
||||
get { return parent; }
|
||||
internal set { parent = value as WindowInfo; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -159,9 +159,33 @@ namespace OpenTK.Platform.X11
|
|||
ref Event event_send
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// The XSelectInput() function requests that the X server report the events associated
|
||||
/// with the specified event mask.
|
||||
/// </summary>
|
||||
/// <param name="display">Specifies the connection to the X server.</param>
|
||||
/// <param name="w">Specifies the window whose events you are interested in.</param>
|
||||
/// <param name="event_mask">Specifies the event mask.</param>
|
||||
/// <remarks>
|
||||
/// Initially, X will not report any of these events.
|
||||
/// Events are reported relative to a window.
|
||||
/// If a window is not interested in a device event,
|
||||
/// it usually propagates to the closest ancestor that is interested,
|
||||
/// unless the do_not_propagate mask prohibits it.
|
||||
/// Setting the event-mask attribute of a window overrides any previous call for the same window but not for other clients. Multiple clients can select for the same events on the same window with the following restrictions:
|
||||
/// <para>Multiple clients can select events on the same window because their event masks are disjoint. When the X server generates an event, it reports it to all interested clients. </para>
|
||||
/// <para>Only one client at a time can select CirculateRequest, ConfigureRequest, or MapRequest events, which are associated with the event mask SubstructureRedirectMask. </para>
|
||||
/// <para>Only one client at a time can select a ResizeRequest event, which is associated with the event mask ResizeRedirectMask. </para>
|
||||
/// <para>Only one client at a time can select a ButtonPress event, which is associated with the event mask ButtonPressMask. </para>
|
||||
/// <para>The server reports the event to all interested clients. </para>
|
||||
/// <para>XSelectInput() can generate a BadWindow error.</para>
|
||||
/// </remarks>
|
||||
[DllImport(_dll_name, EntryPoint = "XSelectInput")]
|
||||
internal static extern void SelectInput(Display display, Window w, EventMask event_mask);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Thing grabbin'
|
||||
#region Pointer and Keyboard grabbing
|
||||
|
||||
[DllImport(_dll_name, EntryPoint = "XGrabPointer")]
|
||||
extern internal static ErrorCodes XGrabPointer(
|
||||
|
@ -873,11 +897,11 @@ XF86VidModeGetGammaRampSize(
|
|||
}
|
||||
|
||||
[Flags]
|
||||
internal enum EventMask : ulong
|
||||
internal enum EventMask : long //: ulong
|
||||
{
|
||||
NoEventMask = 0,
|
||||
KeyPressMask = (1L<<0),
|
||||
KeyReeaseMask = (1L<<1),
|
||||
KeyReleaseMask = (1L<<1),
|
||||
Button3MotionMask = (1L<<10),
|
||||
Button4MotionMask = (1L<<11),
|
||||
Button5MotionMask = (1L<<12),
|
||||
|
|
35
Source/OpenTK/Platform/X11/WindowInfo.cs
Normal file
35
Source/OpenTK/Platform/X11/WindowInfo.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes an X11 window.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal class WindowInfo : IWindowInfo
|
||||
{
|
||||
internal WindowInfo() { }
|
||||
internal WindowInfo(WindowInfo parent)
|
||||
{
|
||||
this.TopLevelWindow = parent.TopLevelWindow;
|
||||
this.Screen = parent.Screen;
|
||||
this.Display = parent.Display;
|
||||
this.RootWindow = parent.RootWindow;
|
||||
this.Handle = parent.Handle;
|
||||
}
|
||||
|
||||
private IntPtr rootWindow, handle, topLevelWindow, display;
|
||||
private int screen;
|
||||
private WindowInfo parent;
|
||||
|
||||
internal IntPtr RootWindow { get { return rootWindow; } set { rootWindow = value; } }
|
||||
internal IntPtr TopLevelWindow { get { return topLevelWindow; } set { topLevelWindow = value; } }
|
||||
internal IntPtr Display { get { return display; } set { display = value; } }
|
||||
internal int Screen { get { return screen; } set { screen = value; } }
|
||||
|
||||
public IntPtr Handle { get { return handle; } internal set { handle = value; } }
|
||||
public IWindowInfo Parent { get { return parent; } internal set { parent = value as WindowInfo; } }
|
||||
}
|
||||
}
|
|
@ -14,14 +14,17 @@ using OpenTK.OpenGL;
|
|||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
public class X11GLContext : OpenTK.Platform.IGLContext
|
||||
/// <summary>
|
||||
/// Provides methods to create and control an opengl context on X11.
|
||||
/// </summary>
|
||||
public sealed class X11GLContext : OpenTK.Platform.IGLContext
|
||||
{
|
||||
private IntPtr x11context;
|
||||
private IntPtr display;
|
||||
private int screenNo;
|
||||
|
||||
private DisplayMode mode;// = new DisplayMode();
|
||||
internal X11WindowInfo windowInfo = new X11WindowInfo();
|
||||
internal WindowInfo windowInfo = new WindowInfo();
|
||||
private VisualInfo visualInfo;
|
||||
|
||||
//private IntPtr desktopResolution = IntPtr.Zero;
|
||||
|
@ -42,14 +45,13 @@ namespace OpenTK.Platform.X11
|
|||
this.mode = new DisplayMode();
|
||||
}
|
||||
|
||||
internal X11GLContext(IWindowInfo info, DisplayMode mode)
|
||||
internal X11GLContext(WindowInfo info, DisplayMode mode)
|
||||
{
|
||||
X11WindowInfo xInfo = info as X11WindowInfo;
|
||||
this.windowInfo.Window = xInfo.Window;
|
||||
this.windowInfo.RootWindow = xInfo.RootWindow;
|
||||
this.windowInfo.TopLevelWindow = xInfo.TopLevelWindow;
|
||||
this.windowInfo.Display = xInfo.Display;
|
||||
this.windowInfo.Screen = xInfo.Screen;
|
||||
this.windowInfo.Handle = info.Handle;
|
||||
this.windowInfo.RootWindow = info.RootWindow;
|
||||
this.windowInfo.TopLevelWindow = info.TopLevelWindow;
|
||||
this.windowInfo.Display = info.Display;
|
||||
this.windowInfo.Screen = info.Screen;
|
||||
|
||||
this.mode = mode;
|
||||
}
|
||||
|
@ -62,7 +64,7 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
public void SwapBuffers()
|
||||
{
|
||||
Glx.SwapBuffers(windowInfo.Display, windowInfo.Window);
|
||||
Glx.SwapBuffers(windowInfo.Display, windowInfo.Handle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -77,10 +79,10 @@ namespace OpenTK.Platform.X11
|
|||
x11context,
|
||||
System.Threading.Thread.CurrentThread.ManagedThreadId,
|
||||
windowInfo.Display,
|
||||
windowInfo.Window
|
||||
windowInfo.Handle
|
||||
)
|
||||
);
|
||||
bool result = Glx.MakeCurrent(windowInfo.Display, windowInfo.Window, x11context);
|
||||
bool result = Glx.MakeCurrent(windowInfo.Display, windowInfo.Handle, x11context);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
@ -246,30 +248,30 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
public IntPtr XVisual
|
||||
internal IntPtr XVisual
|
||||
{
|
||||
get { return this.visual; }
|
||||
}
|
||||
|
||||
public VisualInfo XVisualInfo
|
||||
internal VisualInfo XVisualInfo
|
||||
{
|
||||
get { return this.visualInfo; }
|
||||
}
|
||||
|
||||
public IntPtr XColormap
|
||||
internal IntPtr XColormap
|
||||
{
|
||||
get { return colormap; }
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
internal IntPtr Handle
|
||||
{
|
||||
get { return this.x11context; }
|
||||
}
|
||||
/*
|
||||
public IntPtr ContainingWindow
|
||||
{
|
||||
get { return windowInfo.Window; }
|
||||
internal set { windowInfo.Window = value; }
|
||||
get { return info.Window; }
|
||||
internal set { info.Window = value; }
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
sealed class X11GLControl : IGLControl
|
||||
{
|
||||
X11WindowInfo info = new X11WindowInfo();
|
||||
WindowInfo info = new WindowInfo();
|
||||
private Type xplatui;
|
||||
X11GLContext glContext;
|
||||
|
||||
|
@ -39,7 +39,7 @@ namespace OpenTK.Platform.X11
|
|||
throw new Exception("Attempted to bind to non-existent control.");
|
||||
}
|
||||
|
||||
info.Window = c.Handle;
|
||||
info.Handle = c.Handle;
|
||||
Trace.WriteLine(
|
||||
String.Format(
|
||||
"Binding to control: {0}",
|
||||
|
@ -70,7 +70,7 @@ namespace OpenTK.Platform.X11
|
|||
info.Screen,
|
||||
info.Display,
|
||||
info.RootWindow,
|
||||
info.Window
|
||||
info.Handle
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -14,12 +14,16 @@ using System.Diagnostics;
|
|||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
sealed class X11GLNative : OpenTK.Platform.INativeWindow, IDisposable
|
||||
/// <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
|
||||
{
|
||||
#region --- Private Fields ---
|
||||
#region --- Fields ---
|
||||
|
||||
private X11GLContext glContext;
|
||||
private X11WindowInfo windowInfo = new X11WindowInfo();
|
||||
private WindowInfo info = new WindowInfo();
|
||||
private IntPtr display;
|
||||
private int screen;
|
||||
private IntPtr rootWindow;
|
||||
|
@ -59,11 +63,12 @@ namespace OpenTK.Platform.X11
|
|||
/// </summary>
|
||||
public X11GLNative()
|
||||
{
|
||||
Debug.Print("Native window driver: {0}", this.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- INativeWindow Members ---
|
||||
#region --- INativeGLWindow Members ---
|
||||
|
||||
#region public void CreateWindow(DisplayMode mode)
|
||||
|
||||
|
@ -80,27 +85,25 @@ namespace OpenTK.Platform.X11
|
|||
/// </remarks>
|
||||
public void CreateWindow(DisplayMode mode)
|
||||
{
|
||||
Debug.WriteLine("Creating GameWindow (X11GLNative driver)");
|
||||
Debug.Print("Creating native window with mode: {0}", mode.ToString());
|
||||
Debug.Indent();
|
||||
|
||||
Debug.WriteLine(String.Format("Display mode: {0}", mode));
|
||||
|
||||
windowInfo.Display = display = API.OpenDisplay(null); // null == default display
|
||||
info.Display = display = API.OpenDisplay(null); // null == default display
|
||||
if (display == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception("Could not open connection to X");
|
||||
}
|
||||
windowInfo.Screen = screen = API.DefaultScreen(display);
|
||||
windowInfo.RootWindow = rootWindow = API.RootWindow(display, screen);
|
||||
info.Screen = screen = API.DefaultScreen(display);
|
||||
info.RootWindow = rootWindow = API.RootWindow(display, screen);
|
||||
|
||||
Debug.Print(
|
||||
"Display: {0}, Screen {1}, Root window: {2}",
|
||||
windowInfo.Display,
|
||||
windowInfo.Screen,
|
||||
windowInfo.RootWindow
|
||||
info.Display,
|
||||
info.Screen,
|
||||
info.RootWindow
|
||||
);
|
||||
|
||||
glContext = new X11GLContext(windowInfo, mode);
|
||||
glContext = new X11GLContext(info, mode);
|
||||
glContext.CreateVisual();
|
||||
|
||||
// Create a window on this display using the visual above
|
||||
|
@ -113,8 +116,7 @@ namespace OpenTK.Platform.X11
|
|||
//API.CreateColormap(display, rootWindow, glxVisualInfo.visual, 0/*AllocNone*/);
|
||||
wnd_attributes.event_mask =
|
||||
EventMask.StructureNotifyMask |
|
||||
EventMask.ExposureMask |
|
||||
EventMask.KeyPressMask;
|
||||
EventMask.ExposureMask;
|
||||
|
||||
CreateWindowMask cw_mask =
|
||||
CreateWindowMask.CWBackPixel |
|
||||
|
@ -123,8 +125,8 @@ namespace OpenTK.Platform.X11
|
|||
CreateWindowMask.CWEventMask;
|
||||
|
||||
window = API.CreateWindow(
|
||||
windowInfo.Display,
|
||||
windowInfo.RootWindow,
|
||||
info.Display,
|
||||
info.RootWindow,
|
||||
0, 0,
|
||||
640, 480,
|
||||
0,
|
||||
|
@ -165,10 +167,10 @@ namespace OpenTK.Platform.X11
|
|||
);
|
||||
*/
|
||||
|
||||
//glContext.ContainingWindow = windowInfo.Window;
|
||||
//glContext.ContainingWindow = info.Window;
|
||||
|
||||
|
||||
glContext.windowInfo.Window = window;
|
||||
glContext.windowInfo.Handle = window;
|
||||
glContext.CreateContext(null, true);
|
||||
|
||||
API.MapRaised(display, window);
|
||||
|
@ -216,7 +218,7 @@ namespace OpenTK.Platform.X11
|
|||
//API.NextEvent(display, eventPtr);
|
||||
|
||||
|
||||
Debug.WriteLine(String.Format("Event: {0} ({1} pending)", e.Type, pending));
|
||||
Debug.WriteLine(String.Format("Event: {0} ({1} pending)", e.Type, pending));
|
||||
//Debug.WriteLine(String.Format("Event: {0} ({1} pending)", eventPtr, pending));
|
||||
|
||||
// Check whether memory was corrupted by the NextEvent call.
|
||||
|
@ -363,6 +365,15 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
#region public IWindowInfo WindowInfo
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get { return info; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IResizable Members ---
|
||||
|
@ -456,7 +467,9 @@ namespace OpenTK.Platform.X11
|
|||
if (!disposed)
|
||||
{
|
||||
API.DestroyWindow(display, window);
|
||||
API.CloseDisplay(display);
|
||||
// Kills connection to the X-Server. We don't want that,
|
||||
// 'cause it kills the ExampleLauncher too.
|
||||
//API.CloseDisplay(display);
|
||||
|
||||
if (manuallyCalled)
|
||||
{
|
||||
|
|
|
@ -3,15 +3,73 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
|
||||
using OpenTK.Input;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
public class X11Input : IInputDriver
|
||||
/// <summary>
|
||||
/// Drives the InputDriver on X11.
|
||||
/// This class supports OpenTK, and is not intended for users of OpenTK.
|
||||
/// </summary>
|
||||
internal sealed class X11Input : IInputDriver
|
||||
{
|
||||
public X11Input(IntPtr windowHandle)
|
||||
private X11Keyboard keyboardDriver;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
public X11Input(WindowInfo parent)
|
||||
{
|
||||
Debug.WriteLine("Initalizing X11 input driver.");
|
||||
Debug.Indent();
|
||||
|
||||
Debug.WriteLine("Creating hidden input window.");
|
||||
|
||||
SetWindowAttributes wnd_attributes = new SetWindowAttributes();
|
||||
wnd_attributes.background_pixel = 0;
|
||||
wnd_attributes.border_pixel = 0;
|
||||
wnd_attributes.colormap = IntPtr.Zero;
|
||||
wnd_attributes.event_mask = EventMask.KeyPressMask | EventMask.KeyReleaseMask;
|
||||
|
||||
CreateWindowMask cw_mask =
|
||||
CreateWindowMask.CWEventMask;
|
||||
|
||||
WindowInfo window = new WindowInfo(parent);
|
||||
|
||||
window.Handle = API.CreateWindow(
|
||||
window.Display,
|
||||
window.RootWindow,
|
||||
0, 0,
|
||||
1, 1,
|
||||
0,
|
||||
//glxVisualInfo.depth,
|
||||
//glContext.XVisualInfo.depth,
|
||||
0,
|
||||
Constants.InputOutput,
|
||||
//glxVisualInfo.visual,
|
||||
//glContext.XVisualInfo.visual,
|
||||
IntPtr.Zero,
|
||||
cw_mask,
|
||||
wnd_attributes
|
||||
);
|
||||
|
||||
if (window.Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception("Could not create input window.");
|
||||
}
|
||||
|
||||
Debug.WriteLine("done! (id: " + window + ")");
|
||||
|
||||
// Select input events to be reported here.
|
||||
API.SelectInput(window.Display, window.Handle,
|
||||
EventMask.KeyReleaseMask | EventMask.KeyPressMask);
|
||||
|
||||
keyboardDriver = new X11Keyboard(window);
|
||||
|
||||
Debug.Unindent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IInputDriver Members ---
|
||||
|
||||
#region public IList<IInputDevice> InputDevices
|
||||
|
|
|
@ -6,8 +6,16 @@ using OpenTK.Input;
|
|||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
public class X11Keyboard : IKeyboardDriver
|
||||
/// <summary>
|
||||
/// Drives the Keyboard devices on X11.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal class X11Keyboard : IKeyboardDriver
|
||||
{
|
||||
internal X11Keyboard(WindowInfo windowHandle)
|
||||
{
|
||||
}
|
||||
|
||||
#region --- IKeyboardDriver Members ---
|
||||
|
||||
public IList<Keyboard> Keyboard
|
||||
|
|
Loading…
Reference in a new issue