From 6ccbfb266e87843bcbd119706765061e0b6ae845 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 5 Aug 2007 18:26:14 +0000 Subject: [PATCH] Hooked up Keyboard event handling in X11Input Added ProcessEvents() function to IInputDriver. Does nothing on WinRawInput, but is needed by X11Input --- Source/OpenTK/GameWindow.cs | 1 + Source/OpenTK/Input/IInputDriver.cs | 2 +- Source/OpenTK/InputDriver.cs | 5 +++ Source/OpenTK/Platform/Windows/WinRawInput.cs | 33 ++++--------------- Source/OpenTK/Platform/X11/X11Input.cs | 20 ++++++++++- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 23ff4e51..dbba713b 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -280,6 +280,7 @@ namespace OpenTK public void ProcessEvents() { glWindow.ProcessEvents(); + driver.ProcessEvents(); } #endregion diff --git a/Source/OpenTK/Input/IInputDriver.cs b/Source/OpenTK/Input/IInputDriver.cs index 89c73c7b..d69dd889 100644 --- a/Source/OpenTK/Input/IInputDriver.cs +++ b/Source/OpenTK/Input/IInputDriver.cs @@ -7,7 +7,7 @@ namespace OpenTK.Input public interface IInputDriver : IKeyboardDriver, IMouseDriver { IList InputDevices { get; } - //void ProcessEvents + void ProcessEvents(); //IEnumerable Mice { get; } //IEnumerable Hids { get; } } diff --git a/Source/OpenTK/InputDriver.cs b/Source/OpenTK/InputDriver.cs index 4ffcec29..f2d51aa9 100644 --- a/Source/OpenTK/InputDriver.cs +++ b/Source/OpenTK/InputDriver.cs @@ -47,6 +47,11 @@ namespace OpenTK get { return inputDriver.Mouse; } } + public void ProcessEvents() + { + inputDriver.ProcessEvents(); + } + #endregion } } diff --git a/Source/OpenTK/Platform/Windows/WinRawInput.cs b/Source/OpenTK/Platform/Windows/WinRawInput.cs index b6f2a688..e93449e9 100644 --- a/Source/OpenTK/Platform/Windows/WinRawInput.cs +++ b/Source/OpenTK/Platform/Windows/WinRawInput.cs @@ -57,33 +57,6 @@ namespace OpenTK.Platform.Windows } } - /* - /// - /// Gets a value indicating whether the Device list has changed, for example - /// by removing or adding a device. - /// - internal static bool DeviceListChanged - { - get - { - uint count = 0; - if (API.GetRawInputDeviceList(null, ref count, API.RawInputDeviceListSize) == 0) - { - if (deviceCount == count) - return true; - - deviceCount = count; - return false; - } - else - { - throw new ApplicationException(String.Format( - "Could not retrieve the count of Keyboard devices. Windows error: {0}", - Marshal.GetLastWin32Error())); - } - } - } - */ #region protected override void WndProc(ref Message msg) int size = 0; @@ -166,6 +139,12 @@ namespace OpenTK.Platform.Windows get { throw new Exception("The method or operation is not implemented."); } } + public void ProcessEvents() + { + // Do nothing, the WndProc is automatically notified of new events. + } + + #endregion #region IMouseDriver Members diff --git a/Source/OpenTK/Platform/X11/X11Input.cs b/Source/OpenTK/Platform/X11/X11Input.cs index 2f322256..9bf7e136 100644 --- a/Source/OpenTK/Platform/X11/X11Input.cs +++ b/Source/OpenTK/Platform/X11/X11Input.cs @@ -14,6 +14,11 @@ namespace OpenTK.Platform.X11 internal sealed class X11Input : IInputDriver { private X11Keyboard keyboardDriver; + private WindowInfo window; + + Event e = new Event(); + KeyEvent keyEvent = new KeyEvent(); + #region --- Constructors --- @@ -44,7 +49,7 @@ namespace OpenTK.Platform.X11 CreateWindowMask cw_mask = CreateWindowMask.CWEventMask; - WindowInfo window = new WindowInfo(parent); + window = new WindowInfo(parent); window.Handle = API.CreateWindow( window.Display, @@ -110,6 +115,19 @@ namespace OpenTK.Platform.X11 #endregion + public void ProcessEvents() + { + API.PeekEvent(window.Display, e); + switch (e.Type) + { + case EventType.KeyPress: + case EventType.KeyRelease: + API.NextEvent(window.Display, keyEvent); + keyboardDriver.ProcessKeyboardEvent(keyEvent); + break; + } + } + #endregion } }