2007-08-10 09:27:13 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-08-05 09:03:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using OpenTK.Input;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
using System.Diagnostics;
|
2007-08-05 09:03:22 +00:00
|
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.X11
|
|
|
|
|
{
|
2007-08-05 13:42:31 +00: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 09:03:22 +00:00
|
|
|
|
{
|
2007-08-05 13:42:31 +00:00
|
|
|
|
private X11Keyboard keyboardDriver;
|
2007-09-21 20:34:07 +00:00
|
|
|
|
private X11Mouse mouseDriver;
|
|
|
|
|
private X11.WindowInfo window;
|
2007-08-05 18:26:14 +00:00
|
|
|
|
|
2007-08-05 23:09:05 +00:00
|
|
|
|
XEvent e = new XEvent();
|
2007-08-05 18:26:14 +00:00
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2007-08-05 17:21:46 +00: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>
|
2007-09-21 20:34:07 +00:00
|
|
|
|
/// <param name="attach">The window which the InputDriver will attach itself on.</param>
|
|
|
|
|
public X11Input(IWindowInfo attach)
|
2007-08-05 09:03:22 +00:00
|
|
|
|
{
|
2007-08-05 13:42:31 +00:00
|
|
|
|
Debug.WriteLine("Initalizing X11 input driver.");
|
|
|
|
|
Debug.Indent();
|
|
|
|
|
|
2007-09-21 20:34:07 +00:00
|
|
|
|
if (attach == null)
|
2007-08-05 17:45:59 +00:00
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");
|
|
|
|
|
}
|
2007-08-05 23:09:05 +00:00
|
|
|
|
/*
|
2007-08-05 13:42:31 +00: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;
|
2007-08-05 23:09:05 +00:00
|
|
|
|
wnd_attributes.event_mask = EventMask.KeyPressMask | EventMask.KeyReleaseMask |
|
|
|
|
|
EventMask.FocusChangeMask;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
|
|
|
|
CreateWindowMask cw_mask =
|
|
|
|
|
CreateWindowMask.CWEventMask;
|
|
|
|
|
|
2007-08-05 18:26:14 +00:00
|
|
|
|
window = new WindowInfo(parent);
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
|
|
|
|
window.Handle = API.CreateWindow(
|
|
|
|
|
window.Display,
|
2007-08-05 17:21:46 +00:00
|
|
|
|
window.Parent.Handle,
|
2007-08-05 13:42:31 +00:00
|
|
|
|
0, 0,
|
2007-08-05 23:09:05 +00:00
|
|
|
|
1, 1,
|
2007-08-05 18:51:07 +00:00
|
|
|
|
0, 0,
|
2007-08-05 16:15:15 +00:00
|
|
|
|
Constants.InputOnly,
|
2007-08-05 23:09:05 +00:00
|
|
|
|
//window.VisualInfo.visual,
|
|
|
|
|
(IntPtr)0,
|
2007-08-05 13:42:31 +00:00
|
|
|
|
cw_mask,
|
|
|
|
|
wnd_attributes
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (window.Handle == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Could not create input window.");
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 19:04:06 +00:00
|
|
|
|
API.MapWindow(window.Display, window.Handle);
|
2007-08-05 23:09:05 +00:00
|
|
|
|
API.GrabKeyboard(window.Display, window.Handle, false, GrabMode.GrabModeAsync, GrabMode.GrabModeAsync, 0);
|
2007-08-05 19:04:06 +00:00
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
Debug.WriteLine("done! (id: " + window + ")");
|
2007-08-06 12:13:50 +00:00
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
keyboardDriver = new X11Keyboard(window);
|
2007-08-05 23:09:05 +00:00
|
|
|
|
*/
|
2007-08-06 12:13:50 +00:00
|
|
|
|
|
2007-09-21 20:34:07 +00:00
|
|
|
|
window = attach as Platform.WindowInfo ?? attach as X11.WindowInfo;
|
|
|
|
|
|
|
|
|
|
keyboardDriver = new X11Keyboard(window);
|
|
|
|
|
// Todo: mask is now specified by hand, hard to keep in sync.
|
|
|
|
|
API.SelectInput(window.Display, window.Handle, EventMask.StructureNotifyMask |
|
2007-08-06 12:13:50 +00:00
|
|
|
|
EventMask.SubstructureNotifyMask | EventMask.ExposureMask |
|
2007-08-05 23:09:05 +00:00
|
|
|
|
EventMask.KeyReleaseMask | EventMask.KeyPressMask);
|
2007-08-05 13:42:31 +00:00
|
|
|
|
|
|
|
|
|
Debug.Unindent();
|
2007-08-05 09:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 13:42:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-05 09:03:22 +00: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 16:30:44 +00:00
|
|
|
|
get { return keyboardDriver.Keyboard; }
|
2007-08-05 09:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public IList<Mouse> Mouse
|
|
|
|
|
|
|
|
|
|
public IList<Mouse> Mouse
|
|
|
|
|
{
|
2007-09-24 21:10:52 +00:00
|
|
|
|
get { return mouseDriver.Mouse; }
|
2007-08-05 09:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-09-24 21:10:52 +00:00
|
|
|
|
#region public void Poll()
|
|
|
|
|
|
2007-08-05 18:33:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Consumes to keyboard, mouse, etc events, routing them to their
|
|
|
|
|
/// respective drivers.
|
|
|
|
|
/// </summary>
|
2007-09-22 13:13:17 +00:00
|
|
|
|
public void Poll()
|
2007-08-05 18:26:14 +00:00
|
|
|
|
{
|
2007-08-05 23:38:59 +00:00
|
|
|
|
while (API.CheckMaskEvent(window.Display, EventMask.KeyReleaseMask | EventMask.KeyPressMask, ref e))
|
|
|
|
|
{
|
|
|
|
|
keyboardDriver.ProcessKeyboardEvent(e.KeyEvent);
|
|
|
|
|
}
|
2007-09-24 20:56:50 +00:00
|
|
|
|
while (API.CheckMaskEvent(window.Display, EventMask.ButtonPressMask | EventMask.ButtonPressMask, ref e))
|
|
|
|
|
{
|
|
|
|
|
mouseDriver.ProcessButton(e.ButtonEvent);
|
|
|
|
|
}
|
|
|
|
|
while (API.CheckMaskEvent(window.Display, EventMask.PointerMotionMask | EventMask.PointerMotionHintMask, ref e))
|
|
|
|
|
{
|
|
|
|
|
mouseDriver.ProcessMotion(e.MotionEvent);
|
|
|
|
|
}
|
2007-08-20 13:45:04 +00:00
|
|
|
|
/*
|
|
|
|
|
if (API.Pending(window.Display) > 0)
|
|
|
|
|
{
|
|
|
|
|
Functions.XPeekEvent(window.Display, ref e);
|
|
|
|
|
if (e.type == XEventName.KeyRelease || e.type == XEventName.KeyPress)
|
|
|
|
|
{
|
|
|
|
|
keyboardDriver.ProcessKeyboardEvent(e.KeyEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
2007-08-05 18:26:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 09:03:22 +00:00
|
|
|
|
#endregion
|
2007-08-22 00:30:16 +00:00
|
|
|
|
|
2007-09-24 21:10:52 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-08-22 00:30:16 +00:00
|
|
|
|
#region --- IDisposable Members ---
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-05 09:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|