diff --git a/Source/Examples/ExampleLauncher.cs b/Source/Examples/ExampleLauncher.cs index 1179e463..765239cf 100644 --- a/Source/Examples/ExampleLauncher.cs +++ b/Source/Examples/ExampleLauncher.cs @@ -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) diff --git a/Source/Examples/WinForms/W01_First_Window.cs b/Source/Examples/WinForms/W01_First_Window.cs index 5222c6c6..2fefc900 100644 --- a/Source/Examples/WinForms/W01_First_Window.cs +++ b/Source/Examples/WinForms/W01_First_Window.cs @@ -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) diff --git a/Source/OpenTK/GLControl.cs b/Source/OpenTK/GLControl.cs index 75388948..af215f59 100644 --- a/Source/OpenTK/GLControl.cs +++ b/Source/OpenTK/GLControl.cs @@ -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(); } } diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 4d298862..1bf8d886 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -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 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 Keyboard + + /// + /// Gets the list of available Keyboard devices. + /// + public IList 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 Input + + /// + /// Gets the list of available InputDevices. + /// + public IList 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 - - /// - /// Gets the handle of the current GameWindow. - /// - public IntPtr Handle - { - get { return glWindow.Handle; } - } - - #endregion - #region public void Exit() /// @@ -197,6 +220,15 @@ namespace OpenTK #endregion + #region public IWindowInfo WindowInfo + + public IWindowInfo WindowInfo + { + get { return glWindow.WindowInfo; } + } + + #endregion + #endregion #region --- IGameWindow Members --- diff --git a/Source/OpenTK/InputDriver.cs b/Source/OpenTK/InputDriver.cs index 1e1eee1d..4ffcec29 100644 --- a/Source/OpenTK/InputDriver.cs +++ b/Source/OpenTK/InputDriver.cs @@ -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 { diff --git a/Source/OpenTK/Platform/IGameWindow.cs b/Source/OpenTK/Platform/IGameWindow.cs index 106be817..b3c8a6dd 100644 --- a/Source/OpenTK/Platform/IGameWindow.cs +++ b/Source/OpenTK/Platform/IGameWindow.cs @@ -5,7 +5,7 @@ using System.Text; namespace OpenTK.Platform { - interface IGameWindow : INativeWindow + interface IGameWindow : INativeGLWindow { void Run(); diff --git a/Source/OpenTK/Platform/INativeWindow.cs b/Source/OpenTK/Platform/INativeGLWindow.cs similarity index 52% rename from Source/OpenTK/Platform/INativeWindow.cs rename to Source/OpenTK/Platform/INativeGLWindow.cs index f219d288..a4d07a00 100644 --- a/Source/OpenTK/Platform/INativeWindow.cs +++ b/Source/OpenTK/Platform/INativeGLWindow.cs @@ -4,7 +4,10 @@ using System.Text; namespace OpenTK.Platform { - interface INativeWindow : IGLControl, IResizable + /// + /// This interface supports OpenTK, and is not intended for use by OpenTK programs. + /// + 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; } } } diff --git a/Source/OpenTK/Platform/IWindowInfo.cs b/Source/OpenTK/Platform/IWindowInfo.cs index bdb2e12e..28bb10f0 100644 --- a/Source/OpenTK/Platform/IWindowInfo.cs +++ b/Source/OpenTK/Platform/IWindowInfo.cs @@ -4,7 +4,12 @@ using System.Text; namespace OpenTK.Platform { + /// + /// This interface supports OpenTK, and is not intended for use by OpenTK programs. + /// public interface IWindowInfo { + IntPtr Handle { get; } + IWindowInfo Parent { get; } } } diff --git a/Source/OpenTK/Platform/Utilities.cs b/Source/OpenTK/Platform/Utilities.cs new file mode 100644 index 00000000..e939fe72 --- /dev/null +++ b/Source/OpenTK/Platform/Utilities.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace OpenTK.Platform +{ + /// + /// Provides cross-platform utilities to help interact with the underlying platform. + /// + public static class Utilities + { + public static IWindowInfo GetWindowInfo(Form form) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 5a01f83e..c65a0d27 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -17,16 +17,22 @@ using System.Diagnostics; namespace OpenTK.Platform.Windows { - sealed class WinGLNative : NativeWindow, OpenTK.Platform.INativeWindow, IDisposable + /// + /// Drives GameWindow on Windows. + /// This class supports OpenTK, and is not intended for use by OpenTK programs. + /// + 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 /// public WinGLNative() { + Debug.Print("Native window driver: {0}", this.ToString()); } #endregion @@ -78,7 +85,13 @@ namespace OpenTK.Platform.Windows // Set the window width and height: 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 --- diff --git a/Source/OpenTK/Platform/Windows/WinRawInput.cs b/Source/OpenTK/Platform/Windows/WinRawInput.cs index 7e0fe386..b6f2a688 100644 --- a/Source/OpenTK/Platform/Windows/WinRawInput.cs +++ b/Source/OpenTK/Platform/Windows/WinRawInput.cs @@ -24,17 +24,19 @@ namespace OpenTK.Platform.Windows /// Input event data. /// private API.RawInput data = new API.RawInput(); - /// - /// The list of keyboards connected to this system. + /// The total number of input devices connected to this system. /// - //internal List keyboards = new List(); + 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; } } + /* /// /// Gets a value indicating whether the Device list has changed, for example diff --git a/Source/OpenTK/Platform/Windows/WindowInfo.cs b/Source/OpenTK/Platform/Windows/WindowInfo.cs new file mode 100644 index 00000000..c2d2a463 --- /dev/null +++ b/Source/OpenTK/Platform/Windows/WindowInfo.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenTK.Platform.Windows +{ + /// + /// Describes a Windows window. + /// This class supports OpenTK, and is not intended for use by OpenTK programs. + /// + 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 + } +} diff --git a/Source/OpenTK/Platform/X11/API.cs b/Source/OpenTK/Platform/X11/API.cs index ba100edf..a8683031 100644 --- a/Source/OpenTK/Platform/X11/API.cs +++ b/Source/OpenTK/Platform/X11/API.cs @@ -159,9 +159,33 @@ namespace OpenTK.Platform.X11 ref Event event_send ); + /// + /// The XSelectInput() function requests that the X server report the events associated + /// with the specified event mask. + /// + /// Specifies the connection to the X server. + /// Specifies the window whose events you are interested in. + /// Specifies the event mask. + /// + /// 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: + /// 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. + /// Only one client at a time can select CirculateRequest, ConfigureRequest, or MapRequest events, which are associated with the event mask SubstructureRedirectMask. + /// Only one client at a time can select a ResizeRequest event, which is associated with the event mask ResizeRedirectMask. + /// Only one client at a time can select a ButtonPress event, which is associated with the event mask ButtonPressMask. + /// The server reports the event to all interested clients. + /// XSelectInput() can generate a BadWindow error. + /// + [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), diff --git a/Source/OpenTK/Platform/X11/WindowInfo.cs b/Source/OpenTK/Platform/X11/WindowInfo.cs new file mode 100644 index 00000000..c2427102 --- /dev/null +++ b/Source/OpenTK/Platform/X11/WindowInfo.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenTK.Platform.X11 +{ + /// + /// Describes an X11 window. + /// This class supports OpenTK, and is not intended for use by OpenTK programs. + /// + 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; } } + } +} diff --git a/Source/OpenTK/Platform/X11/X11GLContext.cs b/Source/OpenTK/Platform/X11/X11GLContext.cs index 8be60566..fc0e40c1 100644 --- a/Source/OpenTK/Platform/X11/X11GLContext.cs +++ b/Source/OpenTK/Platform/X11/X11GLContext.cs @@ -14,14 +14,17 @@ using OpenTK.OpenGL; namespace OpenTK.Platform.X11 { - public class X11GLContext : OpenTK.Platform.IGLContext + /// + /// Provides methods to create and control an opengl context on X11. + /// + 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; } } */ } diff --git a/Source/OpenTK/Platform/X11/X11GLControl.cs b/Source/OpenTK/Platform/X11/X11GLControl.cs index 7d7b1c5d..2361f464 100644 --- a/Source/OpenTK/Platform/X11/X11GLControl.cs +++ b/Source/OpenTK/Platform/X11/X11GLControl.cs @@ -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 ) ); diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index e24ca300..ef480aaf 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -14,12 +14,16 @@ using System.Diagnostics; namespace OpenTK.Platform.X11 { - sealed class X11GLNative : OpenTK.Platform.INativeWindow, IDisposable + /// + /// Drives GameWindow on X11. + /// This class supports OpenTK, and is not intended for use by OpenTK programs. + /// + 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 /// 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 /// 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); @@ -210,13 +212,13 @@ namespace OpenTK.Platform.X11 if (pending == 0) return; - + //API.NextEvent(display, e); API.PeekEvent(display, e); //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. @@ -233,7 +235,7 @@ namespace OpenTK.Platform.X11 case EventType.CreateNotify: API.NextEvent(display, createWindow); - + // Set window width/height mode.Width = createWindow.width; mode.Height = createWindow.height; @@ -248,11 +250,11 @@ namespace OpenTK.Platform.X11 quit = true; Debug.WriteLine("Window destroyed, shutting down."); break; - - + + case EventType.ConfigureNotify: API.NextEvent(display, configure); - + // If the window size changed, raise the C# Resize event. if (configure.width != mode.Width || configure.height != mode.Height) @@ -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) { diff --git a/Source/OpenTK/Platform/X11/X11Input.cs b/Source/OpenTK/Platform/X11/X11Input.cs index 0a77d098..17dd2e36 100644 --- a/Source/OpenTK/Platform/X11/X11Input.cs +++ b/Source/OpenTK/Platform/X11/X11Input.cs @@ -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 + /// + /// Drives the InputDriver on X11. + /// This class supports OpenTK, and is not intended for users of OpenTK. + /// + 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 InputDevices diff --git a/Source/OpenTK/Platform/X11/X11Keyboard.cs b/Source/OpenTK/Platform/X11/X11Keyboard.cs index cbafc248..32f34be6 100644 --- a/Source/OpenTK/Platform/X11/X11Keyboard.cs +++ b/Source/OpenTK/Platform/X11/X11Keyboard.cs @@ -6,8 +6,16 @@ using OpenTK.Input; namespace OpenTK.Platform.X11 { - public class X11Keyboard : IKeyboardDriver + /// + /// Drives the Keyboard devices on X11. + /// This class supports OpenTK, and is not intended for use by OpenTK programs. + /// + internal class X11Keyboard : IKeyboardDriver { + internal X11Keyboard(WindowInfo windowHandle) + { + } + #region --- IKeyboardDriver Members --- public IList Keyboard