From c375a716038fe1121848726178bf775cdfad3dc5 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sat, 10 Nov 2007 18:24:56 +0000 Subject: [PATCH] Reverted to 0.3.12 way of handling input events. --- Source/OpenTK/Platform/X11/X11Input.cs | 79 ++++++++++++----------- Source/OpenTK/Platform/X11/X11Keyboard.cs | 8 ++- Source/OpenTK/Platform/X11/X11Mouse.cs | 3 +- 3 files changed, 51 insertions(+), 39 deletions(-) diff --git a/Source/OpenTK/Platform/X11/X11Input.cs b/Source/OpenTK/Platform/X11/X11Input.cs index d8eafecb..1c3a80fb 100644 --- a/Source/OpenTK/Platform/X11/X11Input.cs +++ b/Source/OpenTK/Platform/X11/X11Input.cs @@ -29,7 +29,6 @@ namespace OpenTK.Platform.X11 Thread pollingThread = null; bool disposed; - bool disposing = false; #region --- Constructors --- @@ -45,13 +44,13 @@ namespace OpenTK.Platform.X11 Debug.Indent(); if (attach == null) - { throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver."); - } window = new X11.WindowInfo(attach); - window.Parent = attach; /* + window = new WindowInfo(); + window.Parent = attach; + Debug.Print("Creating hidden input window."); XSetWindowAttributes wnd_attr = new XSetWindowAttributes(); @@ -80,7 +79,7 @@ namespace OpenTK.Platform.X11 keyboardDriver = new X11Keyboard(window); mouseDriver = new X11Mouse(window); - //Thread pollingThread = new Thread(InternalPoll); + //pollingThread = new Thread(InternalPoll); //pollingThread.Priority = ThreadPriority.BelowNormal; //pollingThread.IsBackground = true; //pollingThread.Start(); @@ -90,44 +89,46 @@ namespace OpenTK.Platform.X11 #endregion + #region private void InternalPoll() +#if false private void InternalPoll() { - /* + X11.XEvent e = new XEvent(); try { - //while (!disposed) - //{ - // Functions.XMaskEvent(window.Display, - // EventMask.PointerMotionMask | EventMask.PointerMotionHintMask | - // EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | - // EventMask.KeyPressMask | EventMask.KeyReleaseMask | - // EventMask.StructureNotifyMask, ref e); + while (!disposed) + { + Functions.XMaskEvent(window.Display, + EventMask.PointerMotionMask | EventMask.PointerMotionHintMask | + EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | + EventMask.KeyPressMask | EventMask.KeyReleaseMask | + EventMask.StructureNotifyMask, ref e); - // if (disposed || disposing) - // return; + if (disposed) + return; - // switch (e.type) - // { - // case XEventName.KeyPress: - // case XEventName.KeyRelease: - // keyboardDriver.ProcessKeyboardEvent(ref e.KeyEvent); - // break; + switch (e.type) + { + case XEventName.KeyPress: + case XEventName.KeyRelease: + keyboardDriver.ProcessKeyboardEvent(ref e.KeyEvent); + break; - // case XEventName.ButtonPress: - // case XEventName.ButtonRelease: - // mouseDriver.ProcessButton(ref e.ButtonEvent); - // break; + case XEventName.ButtonPress: + case XEventName.ButtonRelease: + mouseDriver.ProcessButton(ref e.ButtonEvent); + break; - // case XEventName.MotionNotify: - // mouseDriver.ProcessMotion(ref e.MotionEvent); - // break; + case XEventName.MotionNotify: + mouseDriver.ProcessMotion(ref e.MotionEvent); + break; - // case XEventName.DestroyNotify: - // Functions.XPutBackEvent(window.Display, ref e); - // //pollingThread.Abort(); - // return; - // } - //} + case XEventName.DestroyNotify: + Functions.XPutBackEvent(window.Display, ref e); + //pollingThread.Abort(); + return; + } + } } catch (ThreadAbortException expt) { @@ -135,8 +136,11 @@ namespace OpenTK.Platform.X11 Functions.XDestroyWindow(window.Display, window.Handle); return; } - */ } +#endif + #endregion + + #region internal void ProcessEvent(ref XEvent e) internal void ProcessEvent(ref XEvent e) { @@ -162,6 +166,8 @@ namespace OpenTK.Platform.X11 } } + #endregion + #region --- IInputDriver Members --- #region public IList InputDevices @@ -199,6 +205,7 @@ namespace OpenTK.Platform.X11 public void Poll() { mouseDriver.Poll(); + } #endregion @@ -217,7 +224,7 @@ namespace OpenTK.Platform.X11 { if (!disposed) { - disposing = true; + //disposing = true; if (pollingThread != null && pollingThread.IsAlive) pollingThread.Abort(); diff --git a/Source/OpenTK/Platform/X11/X11Keyboard.cs b/Source/OpenTK/Platform/X11/X11Keyboard.cs index 1af72ac4..faf13c14 100644 --- a/Source/OpenTK/Platform/X11/X11Keyboard.cs +++ b/Source/OpenTK/Platform/X11/X11Keyboard.cs @@ -161,12 +161,12 @@ namespace OpenTK.Platform.X11 #endregion - #region Constructor + #region --- Constructor --- internal X11Keyboard(WindowInfo window) { if (window == null) - throw new ArgumentException("Window cannot be null."); + throw new ArgumentNullException("window"); this.window = window; Initialize(); @@ -250,6 +250,8 @@ namespace OpenTK.Platform.X11 #endregion + #region public void Poll() + public void Poll() { //Keymap map = new Keymap(); @@ -273,5 +275,7 @@ namespace OpenTK.Platform.X11 } */ } + + #endregion } } diff --git a/Source/OpenTK/Platform/X11/X11Mouse.cs b/Source/OpenTK/Platform/X11/X11Mouse.cs index 69749840..a2581f6c 100644 --- a/Source/OpenTK/Platform/X11/X11Mouse.cs +++ b/Source/OpenTK/Platform/X11/X11Mouse.cs @@ -20,7 +20,7 @@ namespace OpenTK.Platform.X11 WindowInfo window; List mice = new List(); - #region Constructor + #region --- Constructor --- public X11Mouse(WindowInfo window) { @@ -28,6 +28,7 @@ namespace OpenTK.Platform.X11 // Just create one mouse now. // TODO: support for multiple devices through evdev. + // TODO: Should call XSelectInput for mouse pointer events. MouseDevice m = new MouseDevice(); m.Description = "Default X11 mouse"; m.DeviceID = IntPtr.Zero;