2007-08-05 11:03:22 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using OpenTK.Input;
|
2007-08-05 15:42:31 +02:00
|
|
|
|
using System.Diagnostics;
|
2007-08-05 11:03:22 +02:00
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.X11
|
|
|
|
|
{
|
2007-08-05 15:42:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Drives the InputDriver on X11.
|
|
|
|
|
/// This class supports OpenTK, and is not intended for users of OpenTK.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal sealed class X11Input : IInputDriver
|
2007-08-05 11:03:22 +02:00
|
|
|
|
{
|
2007-08-05 15:42:31 +02:00
|
|
|
|
private X11Keyboard keyboardDriver;
|
2007-08-05 20:26:14 +02:00
|
|
|
|
private WindowInfo window;
|
|
|
|
|
|
|
|
|
|
Event e = new Event();
|
|
|
|
|
KeyEvent keyEvent = new KeyEvent();
|
2007-08-05 20:33:38 +02:00
|
|
|
|
int pending;
|
2007-08-05 20:26:14 +02:00
|
|
|
|
|
2007-08-05 15:42:31 +02:00
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2007-08-05 19:21:46 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new X11Input driver. Creates a hidden InputOnly window, child to
|
|
|
|
|
/// the main application window, which selects input events and routes them to
|
|
|
|
|
/// the device specific drivers (Keyboard, Mouse, Hid).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parent"></param>
|
2007-08-05 15:42:31 +02:00
|
|
|
|
public X11Input(WindowInfo parent)
|
2007-08-05 11:03:22 +02:00
|
|
|
|
{
|
2007-08-05 15:42:31 +02:00
|
|
|
|
Debug.WriteLine("Initalizing X11 input driver.");
|
|
|
|
|
Debug.Indent();
|
|
|
|
|
|
2007-08-05 19:45:59 +02:00
|
|
|
|
if (parent == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 15:42:31 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2007-08-05 20:26:14 +02:00
|
|
|
|
window = new WindowInfo(parent);
|
2007-08-05 15:42:31 +02:00
|
|
|
|
|
|
|
|
|
window.Handle = API.CreateWindow(
|
|
|
|
|
window.Display,
|
2007-08-05 19:21:46 +02:00
|
|
|
|
window.Parent.Handle,
|
2007-08-05 15:42:31 +02:00
|
|
|
|
0, 0,
|
|
|
|
|
1, 1,
|
2007-08-05 20:51:07 +02:00
|
|
|
|
0, 0,
|
2007-08-05 18:15:15 +02:00
|
|
|
|
Constants.InputOnly,
|
2007-08-05 20:51:07 +02:00
|
|
|
|
window.VisualInfo.visual,
|
2007-08-05 15:42:31 +02:00
|
|
|
|
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.
|
2007-08-05 20:38:16 +02:00
|
|
|
|
//API.SelectInput(window.Display, window.Handle,
|
|
|
|
|
// EventMask.KeyReleaseMask | EventMask.KeyPressMask);
|
2007-08-05 15:42:31 +02:00
|
|
|
|
|
|
|
|
|
keyboardDriver = new X11Keyboard(window);
|
|
|
|
|
|
|
|
|
|
Debug.Unindent();
|
2007-08-05 11:03:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 15:42:31 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-05 11:03:22 +02:00
|
|
|
|
#region --- IInputDriver Members ---
|
|
|
|
|
|
|
|
|
|
#region public IList<IInputDevice> InputDevices
|
|
|
|
|
|
|
|
|
|
public IList<IInputDevice> InputDevices
|
|
|
|
|
{
|
|
|
|
|
get { throw new Exception("The method or operation is not implemented."); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public IList<Keyboard> Keyboard
|
|
|
|
|
|
|
|
|
|
public IList<Keyboard> Keyboard
|
|
|
|
|
{
|
2007-08-05 18:30:44 +02:00
|
|
|
|
get { return keyboardDriver.Keyboard; }
|
2007-08-05 11:03:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public IList<Mouse> Mouse
|
|
|
|
|
|
|
|
|
|
public IList<Mouse> Mouse
|
|
|
|
|
{
|
|
|
|
|
get { throw new Exception("The method or operation is not implemented."); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-05 20:33:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Consumes to keyboard, mouse, etc events, routing them to their
|
|
|
|
|
/// respective drivers.
|
|
|
|
|
/// </summary>
|
2007-08-05 20:26:14 +02:00
|
|
|
|
public void ProcessEvents()
|
|
|
|
|
{
|
2007-08-05 20:33:38 +02:00
|
|
|
|
pending = API.Pending(window.Display);
|
|
|
|
|
|
|
|
|
|
if (pending == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-08-05 20:26:14 +02:00
|
|
|
|
API.PeekEvent(window.Display, e);
|
2007-08-05 20:38:16 +02:00
|
|
|
|
Debug.Write(String.Format("Input window received {0} event... ", e.Type.ToString()));
|
2007-08-05 20:33:38 +02:00
|
|
|
|
|
2007-08-05 20:26:14 +02:00
|
|
|
|
switch (e.Type)
|
|
|
|
|
{
|
|
|
|
|
case EventType.KeyPress:
|
|
|
|
|
case EventType.KeyRelease:
|
|
|
|
|
API.NextEvent(window.Display, keyEvent);
|
2007-08-05 20:38:16 +02:00
|
|
|
|
Debug.WriteLine(" consumed!");
|
2007-08-05 20:26:14 +02:00
|
|
|
|
keyboardDriver.ProcessKeyboardEvent(keyEvent);
|
|
|
|
|
break;
|
2007-08-05 20:33:38 +02:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
API.NextEvent(window.Display, e);
|
2007-08-05 20:38:16 +02:00
|
|
|
|
Debug.WriteLine(" not consumed.");
|
2007-08-05 20:33:38 +02:00
|
|
|
|
break;
|
2007-08-05 20:26:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 11:03:22 +02:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|