diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs
index dbba713b..d08839fb 100644
--- a/Source/OpenTK/GameWindow.cs
+++ b/Source/OpenTK/GameWindow.cs
@@ -56,7 +56,8 @@ namespace OpenTK
{
//glWindow.Context.MakeCurrent();
- driver = new InputDriver(this.WindowInfo);
+ if (driver == null)
+ driver = new InputDriver(this.WindowInfo);
glWindow.Create -= glWindow_CreateInputDriver;
this.OnCreate(e);
@@ -80,12 +81,7 @@ namespace OpenTK
{
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;
+ return InputDriver.Keyboard;
}
}
@@ -100,17 +96,25 @@ namespace OpenTK
{
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;
+ return InputDriver.InputDevices;
}
}
#endregion
+ internal InputDriver InputDriver
+ {
+ get
+ {
+ if (driver == null)
+ {
+ Debug.WriteLine("WARNING: Accessed null InputDriver - creating new. This may indicate a prorgamming error.");
+ driver = new InputDriver(this.WindowInfo);
+ }
+ return driver;
+ }
+ }
+
#endregion
#region --- INativeGLWindow Members ---
@@ -279,8 +283,9 @@ namespace OpenTK
///
public void ProcessEvents()
{
+ if (driver != null)
+ driver.ProcessEvents();
glWindow.ProcessEvents();
- driver.ProcessEvents();
}
#endregion
diff --git a/Source/OpenTK/Platform/X11/API.cs b/Source/OpenTK/Platform/X11/API.cs
index fc3c5d67..d2eed721 100644
--- a/Source/OpenTK/Platform/X11/API.cs
+++ b/Source/OpenTK/Platform/X11/API.cs
@@ -30,6 +30,7 @@ namespace OpenTK.Platform.X11
using KeyCode = System.Byte; // Or maybe ushort?
using Display = System.IntPtr;
+ using XPointer = System.IntPtr;
#endregion
@@ -145,7 +146,7 @@ namespace OpenTK.Platform.X11
[DllImport(_dll_name, EntryPoint = "XPeekEvent")]
extern internal static void PeekEvent(
Display display,
- [In, Out]Event event_return
+ [In, Out]XEvent event_return
);
[DllImport(_dll_name, EntryPoint = "XSendEvent")]
@@ -156,7 +157,7 @@ namespace OpenTK.Platform.X11
bool propagate,
[MarshalAs(UnmanagedType.SysInt)]
EventMask event_mask,
- ref Event event_send
+ ref XEvent event_send
);
///
@@ -183,6 +184,22 @@ namespace OpenTK.Platform.X11
[DllImport(_dll_name, EntryPoint = "XSelectInput")]
internal static extern void SelectInput(Display display, Window w, EventMask event_mask);
+ ///
+ /// When the predicate procedure finds a match, XCheckIfEvent() copies the matched event into the client-supplied XEvent structure and returns True. (This event is removed from the queue.) If the predicate procedure finds no match, XCheckIfEvent() returns False, and the output buffer will have been flushed. All earlier events stored in the queue are not discarded.
+ ///
+ /// Specifies the connection to the X server.
+ /// Returns a copy of the matched event's associated structure.
+ /// Specifies the procedure that is to be called to determine if the next event in the queue matches what you want
+ /// Specifies the user-supplied argument that will be passed to the predicate procedure.
+ /// true if the predicate returns true for some event, false otherwise
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static extern bool CheckIfEvent(Display display, ref XEvent event_return,
+ /*[MarshalAs(UnmanagedType.FunctionPtr)] */ CheckEventPredicate predicate, /*XPointer*/ IntPtr arg);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal delegate bool CheckEventPredicate(Display display, ref XEvent @event, IntPtr arg);
+
#endregion
#region Pointer and Keyboard functions
@@ -626,220 +643,6 @@ XF86VidModeGetGammaRampSize(
#endregion
- #region Event structures
-
- #region XEvent
-
- [StructLayout(LayoutKind.Sequential)]
- //[StructLayout(LayoutKind.Explicit)]
- internal class Event
- {
- internal EventType Type;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- /*[FieldOffset(0)]internal EventType Type;*/
- /*[FieldOffset(0)]
- IntPtr
- pad1 , pad2 , pad3 , pad4 , pad5 , pad6 ,
- pad7 , pad8 , pad9 , pad10, pad11, pad12,
- pad13, pad14, pad15, pad16, pad17, pad18,
- pad19, pad20, pad21, pad22, pad23, pad24;*/
-
- /*private ConfigureNotifyEvent cne = new ConfigureNotifyEvent();
- internal ConfigureNotifyEvent ConfigureEvent
- {
- get
- {
- cne.type = this.Type;
- cne.serial = this.pad1;
- }
- }*/
-
- //[FieldOffset(0)]internal AnyEvent Any;
- //[FieldOffset(0)]internal KeyEvent Key;
- //[FieldOffset(0)]internal DestroyWindowEvent DestroyWindow;
- //[FieldOffset(0)]internal CreateWindowEvent CreateWindow;
- //[FieldOffset(0)]internal ResizeRequestEvent ResizeRequest;
- //[FieldOffset(0)]internal ConfigureNotifyEvent ConfigureNotify;
- //[FieldOffset(0)]internal ReparentNotifyEvent ReparentNotify;
- //[FieldOffset(0)]internal ExposeEvent Expose;
- }
-
- #endregion
-
- #region XAnyEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class AnyEvent
- {
- internal EventType type;
- //[MarshalAs(UnmanagedType.SysUInt)]
- internal IntPtr serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window window;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
-
- }
-
- #endregion
-
- #region XKeyEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class KeyEvent
- {
- internal EventType type; /* KeyPress or KeyRelease */
- [MarshalAs(UnmanagedType.SysUInt)]
- internal ulong serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window window; /* ``event'' window it is reported relative to */
- internal Window root; /* root window that the event occurred on */
- internal Window subwindow; /* child window */
- [MarshalAs(UnmanagedType.SysUInt)]
- internal Time time; /* milliseconds */
- internal int x, y; /* pointer x, y coordinates in event window */
- internal int x_root, y_root; /* coordinates relative to root */
- internal uint state; /* key or button mask */
- internal uint keycode; /* detail */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool same_screen; /* same screen flag */
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- }
-
- #endregion
-
- #region XDestroyWindowEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class DestroyWindowEvent
- {
- internal EventType type; /* DestroyNotify */
- internal ulong serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window @event;
- internal Window window;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- }
-
- #endregion
-
- #region XCreateWindowEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class CreateWindowEvent
- {
- internal EventType type; /* CreateNotify */
- internal ulong serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window parent; /* parent of the window */
- internal Window window; /* window id of window created */
- internal int x, y; /* window location */
- internal int width, height; /* size of window */
- internal int border_width; /* border width */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool override_redirect; /* creation should be overridden */
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- }
-
- #endregion
-
- #region XResizeRequestEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class ResizeRequestEvent
- {
- internal EventType type; /* ResizeRequest */
- internal ulong serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window window;
- internal int width, height;
- }
-
- #endregion
-
- #region XConfigureNotifyEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class ConfigureNotifyEvent
- {
- internal EventType type; /* ConfigureNotify */
- internal ulong serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window @event;
- internal Window window;
- internal int x, y;
- internal int width, height;
- internal int border_width;
- internal Window above;
- [MarshalAs(UnmanagedType.Bool)]
- internal bool override_redirect;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- }
-
- #endregion
-
- #region XReparentNotifyEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class ReparentNotifyEvent
- {
- internal EventType type; /* ReparentNotify */
- //[MarshalAs(UnmanagedType.SysUInt)]
- internal IntPtr serial; /* # of last request processed by server */
- //[MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window @event;
- internal Window window;
- internal Window parent;
- internal int x, y;
- //[MarshalAs(UnmanagedType.Bool)]
- internal bool override_redirect;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- }
-
- #endregion
-
- #region XExposeEvent
-
- [StructLayout(LayoutKind.Sequential)]
- internal class ExposeEvent
- {
- internal EventType type; /* Expose */
- internal ulong serial; /* # of last request processed by server */
- [MarshalAs(UnmanagedType.Bool)]
- internal bool send_event; /* true if this came from a SendEvent request */
- internal Display display; /* Display the event was read from */
- internal Window window;
- internal int x, y;
- internal int width, height;
- internal int count; /* if nonzero, at least this many more */
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=192)]
- byte[] pad = new byte[192];
- }
-
- #endregion
-
- #endregion
-
#endregion
#region X11 Constants and Enums
@@ -856,45 +659,6 @@ XF86VidModeGetGammaRampSize(
internal const int InputOnly = 2;
}
- internal enum EventType : int
- {
- NoEventMask = 0,
- FocusOut = 10,
- KeymapNotify = 11,
- Expose = 12,
- GraphicsExpose = 13,
- NoExpose = 14,
- VisibilityNotify = 15,
- CreateNotify = 16,
- DestroyNotify = 17,
- UnmapNotify = 18,
- MapNotify = 19,
- KeyPress = 2,
- MapRequest = 20,
- ReparentNotify = 21,
- ConfigureNotify = 22,
- ConfigureRequest = 23,
- GravityNotify = 24,
- ResizeRequest = 25,
- CirculateNotify = 26,
- CirculateRequest = 27,
- PropertyNotify = 28,
- SelectionClear = 29,
- KeyRelease = 3,
- SelectionRequest = 30,
- SelectionNotify = 31,
- ColormapNotify = 32,
- ClientMessage = 33,
- MappingNotify = 34,
- LASTEvent = 35,
- ButtonPress = 4,
- ButtonRelease = 5,
- MotionNotify = 6,
- EnterNotify = 7,
- LeaveNotify = 8,
- FocusIn = 9,
- }
-
internal enum ErrorCodes : int
{
Success = 0,
@@ -917,42 +681,6 @@ XF86VidModeGetGammaRampSize(
BadImplementation = 17,
}
- internal enum GrabMode : int
- {
- Sync = 0,
- Async = 1,
- }
-
- [Flags]
- internal enum EventMask : long //: ulong
- {
- NoEventMask = 0,
- KeyPressMask = (1L<<0),
- KeyReleaseMask = (1L<<1),
- Button3MotionMask = (1L<<10),
- Button4MotionMask = (1L<<11),
- Button5MotionMask = (1L<<12),
- ButtonMotionMask = (1L<<13),
- KeymapStateMask = (1L<<14),
- ExposureMask = (1L<<15),
- VisibilityChangeMask = (1L<<16),
- StructureNotifyMask = (1L<<17),
- ResizeRedirectMask = (1L<<18),
- SubstructureNotifyMask = (1L<<19),
- ButtonPressMask = (1L<<2),
- SubstructureRedirectMask = (1L<<20),
- FocusChangeMask = (1L<<21),
- PropertyChangeMask = (1L<<22),
- CoormapChangeMask = (1L<<23),
- ButtonReleaseMask = (1L<<3),
- EnterWindowMask = (1L<<4),
- LeaveWindowMask = (1L<<5),
- PointerMotionMask = (1L<<6),
- PointerMotionHintMask = (1L<<7),
- Button1MotionMask = (1L<<8),
- Button2MotionMask = (1L<<9),
- }
-
[Flags]
internal enum CreateWindowMask : long//: ulong
{
diff --git a/Source/OpenTK/Platform/X11/Functions.cs b/Source/OpenTK/Platform/X11/Functions.cs
new file mode 100644
index 00000000..4fee743e
--- /dev/null
+++ b/Source/OpenTK/Platform/X11/Functions.cs
@@ -0,0 +1,317 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+
+namespace OpenTK.Platform.X11
+{
+ class Functions
+ {
+ [DllImport("libX11", EntryPoint = "XOpenDisplay")]
+ internal extern static IntPtr XOpenDisplay(IntPtr display);
+ [DllImport("libX11", EntryPoint = "XCloseDisplay")]
+ internal extern static int XCloseDisplay(IntPtr display);
+ [DllImport("libX11", EntryPoint = "XSynchronize")]
+ internal extern static IntPtr XSynchronize(IntPtr display, bool onoff);
+
+ [DllImport("libX11", EntryPoint = "XCreateWindow")]
+ internal extern static IntPtr XCreateWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int depth, int xclass, IntPtr visual, UIntPtr valuemask, ref XSetWindowAttributes attributes);
+ [DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]
+ internal extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, UIntPtr border, UIntPtr background);
+ [DllImport("libX11", EntryPoint = "XMapWindow")]
+ internal extern static int XMapWindow(IntPtr display, IntPtr window);
+ [DllImport("libX11", EntryPoint = "XUnmapWindow")]
+ internal extern static int XUnmapWindow(IntPtr display, IntPtr window);
+ [DllImport("libX11", EntryPoint = "XMapSubwindows")]
+ internal extern static int XMapSubindows(IntPtr display, IntPtr window);
+ [DllImport("libX11", EntryPoint = "XUnmapSubwindows")]
+ internal extern static int XUnmapSubwindows(IntPtr display, IntPtr window);
+ [DllImport("libX11", EntryPoint = "XRootWindow")]
+ internal extern static IntPtr XRootWindow(IntPtr display, int screen_number);
+ [DllImport("libX11", EntryPoint = "XNextEvent")]
+ internal extern static IntPtr XNextEvent(IntPtr display, ref XEvent xevent);
+ [DllImport("libX11")]
+ internal extern static int XConnectionNumber(IntPtr diplay);
+ [DllImport("libX11")]
+ internal extern static int XPending(IntPtr diplay);
+ [DllImport("libX11", EntryPoint = "XSelectInput")]
+ internal extern static IntPtr XSelectInput(IntPtr display, IntPtr window, IntPtr mask);
+
+ [DllImport("libX11", EntryPoint = "XDestroyWindow")]
+ internal extern static int XDestroyWindow(IntPtr display, IntPtr window);
+
+ [DllImport("libX11", EntryPoint = "XReparentWindow")]
+ internal extern static int XReparentWindow(IntPtr display, IntPtr window, IntPtr parent, int x, int y);
+ [DllImport("libX11", EntryPoint = "XMoveResizeWindow")]
+ internal extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height);
+
+ [DllImport("libX11", EntryPoint = "XResizeWindow")]
+ internal extern static int XResizeWindow(IntPtr display, IntPtr window, int width, int height);
+
+ [DllImport("libX11", EntryPoint = "XGetWindowAttributes")]
+ internal extern static int XGetWindowAttributes(IntPtr display, IntPtr window, ref XWindowAttributes attributes);
+
+ [DllImport("libX11", EntryPoint = "XFlush")]
+ internal extern static int XFlush(IntPtr display);
+
+ [DllImport("libX11", EntryPoint = "XSetWMName")]
+ internal extern static int XSetWMName(IntPtr display, IntPtr window, ref XTextProperty text_prop);
+
+ [DllImport("libX11", EntryPoint = "XStoreName")]
+ internal extern static int XStoreName(IntPtr display, IntPtr window, string window_name);
+
+ [DllImport("libX11", EntryPoint = "XFetchName")]
+ internal extern static int XFetchName(IntPtr display, IntPtr window, ref IntPtr window_name);
+
+ [DllImport("libX11", EntryPoint = "XSendEvent")]
+ internal extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XEvent send_event);
+
+ [DllImport("libX11", EntryPoint = "XQueryTree")]
+ internal extern static int XQueryTree(IntPtr display, IntPtr window, out IntPtr root_return, out IntPtr parent_return, out IntPtr children_return, out int nchildren_return);
+
+ [DllImport("libX11", EntryPoint = "XFree")]
+ internal extern static int XFree(IntPtr data);
+
+ [DllImport("libX11", EntryPoint = "XRaiseWindow")]
+ internal extern static int XRaiseWindow(IntPtr display, IntPtr window);
+
+ [DllImport("libX11", EntryPoint = "XLowerWindow")]
+ internal extern static uint XLowerWindow(IntPtr display, IntPtr window);
+
+ [DllImport("libX11", EntryPoint = "XConfigureWindow")]
+ internal extern static uint XConfigureWindow(IntPtr display, IntPtr window, ChangeWindowFlags value_mask, ref XWindowChanges values);
+
+ [DllImport("libX11", EntryPoint = "XInternAtom")]
+ internal extern static IntPtr XInternAtom(IntPtr display, string atom_name, bool only_if_exists);
+
+ [DllImport("libX11", EntryPoint = "XInternAtoms")]
+ internal extern static int XInternAtoms(IntPtr display, string[] atom_names, int atom_count, bool only_if_exists, IntPtr[] atoms);
+
+ [DllImport("libX11", EntryPoint = "XSetWMProtocols")]
+ internal extern static int XSetWMProtocols(IntPtr display, IntPtr window, IntPtr[] protocols, int count);
+
+ [DllImport("libX11", EntryPoint = "XGrabPointer")]
+ internal extern static int XGrabPointer(IntPtr display, IntPtr window, bool owner_events, EventMask event_mask, GrabMode pointer_mode, GrabMode keyboard_mode, IntPtr confine_to, IntPtr cursor, IntPtr timestamp);
+
+ [DllImport("libX11", EntryPoint = "XUngrabPointer")]
+ internal extern static int XUngrabPointer(IntPtr display, IntPtr timestamp);
+
+ [DllImport("libX11", EntryPoint = "XQueryPointer")]
+ internal extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons);
+
+ [DllImport("libX11", EntryPoint = "XTranslateCoordinates")]
+ internal extern static bool XTranslateCoordinates(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, out int intdest_x_return, out int dest_y_return, out IntPtr child_return);
+
+ [DllImport("libX11", EntryPoint = "XGetGeometry")]
+ internal extern static bool XGetGeometry(IntPtr display, IntPtr window, out IntPtr root, out int x, out int y, out int width, out int height, out int border_width, out int depth);
+
+ [DllImport("libX11", EntryPoint = "XGetGeometry")]
+ internal extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, out int x, out int y, out int width, out int height, IntPtr border_width, IntPtr depth);
+
+ [DllImport("libX11", EntryPoint = "XGetGeometry")]
+ internal extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, out int x, out int y, IntPtr width, IntPtr height, IntPtr border_width, IntPtr depth);
+
+ [DllImport("libX11", EntryPoint = "XGetGeometry")]
+ internal extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, IntPtr x, IntPtr y, out int width, out int height, IntPtr border_width, IntPtr depth);
+
+ [DllImport("libX11", EntryPoint = "XWarpPointer")]
+ internal extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y);
+
+ [DllImport("libX11", EntryPoint = "XClearWindow")]
+ internal extern static int XClearWindow(IntPtr display, IntPtr window);
+
+ [DllImport("libX11", EntryPoint = "XClearArea")]
+ internal extern static int XClearArea(IntPtr display, IntPtr window, int x, int y, int width, int height, bool exposures);
+
+ // Colormaps
+ [DllImport("libX11", EntryPoint = "XDefaultScreenOfDisplay")]
+ internal extern static IntPtr XDefaultScreenOfDisplay(IntPtr display);
+
+ [DllImport("libX11", EntryPoint = "XScreenNumberOfScreen")]
+ internal extern static int XScreenNumberOfScreen(IntPtr display, IntPtr Screen);
+
+ [DllImport("libX11", EntryPoint = "XDefaultVisual")]
+ internal extern static IntPtr XDefaultVisual(IntPtr display, int screen_number);
+
+ [DllImport("libX11", EntryPoint = "XDefaultDepth")]
+ internal extern static uint XDefaultDepth(IntPtr display, int screen_number);
+
+ [DllImport("libX11", EntryPoint = "XDefaultScreen")]
+ internal extern static int XDefaultScreen(IntPtr display);
+
+ [DllImport("libX11", EntryPoint = "XDefaultColormap")]
+ internal extern static IntPtr XDefaultColormap(IntPtr display, int screen_number);
+
+ [DllImport("libX11", EntryPoint = "XLookupColor")]
+ internal extern static int XLookupColor(IntPtr display, IntPtr Colormap, string Coloranem, ref XColor exact_def_color, ref XColor screen_def_color);
+
+ [DllImport("libX11", EntryPoint = "XAllocColor")]
+ internal extern static int XAllocColor(IntPtr display, IntPtr Colormap, ref XColor colorcell_def);
+
+ [DllImport("libX11", EntryPoint = "XSetTransientForHint")]
+ internal extern static int XSetTransientForHint(IntPtr display, IntPtr window, IntPtr prop_window);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref MotifWmHints data, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref uint value, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref IntPtr value, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, uint[] data, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, int[] data, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr[] data, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty")]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr atoms, int nelements);
+
+ [DllImport("libX11", EntryPoint = "XChangeProperty", CharSet = CharSet.Ansi)]
+ internal extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, string text, int text_length);
+
+ [DllImport("libX11", EntryPoint = "XDeleteProperty")]
+ internal extern static int XDeleteProperty(IntPtr display, IntPtr window, IntPtr property);
+
+ // Drawing
+ [DllImport("libX11", EntryPoint = "XCreateGC")]
+ internal extern static IntPtr XCreateGC(IntPtr display, IntPtr window, IntPtr valuemask, ref XGCValues values);
+
+ [DllImport("libX11", EntryPoint = "XFreeGC")]
+ internal extern static int XFreeGC(IntPtr display, IntPtr gc);
+
+ [DllImport("libX11", EntryPoint = "XSetFunction")]
+ internal extern static int XSetFunction(IntPtr display, IntPtr gc, GXFunction function);
+
+ [DllImport("libX11", EntryPoint = "XSetLineAttributes")]
+ internal extern static int XSetLineAttributes(IntPtr display, IntPtr gc, int line_width, GCLineStyle line_style, GCCapStyle cap_style, GCJoinStyle join_style);
+
+ [DllImport("libX11", EntryPoint = "XDrawLine")]
+ internal extern static int XDrawLine(IntPtr display, IntPtr drawable, IntPtr gc, int x1, int y1, int x2, int y2);
+
+ [DllImport("libX11", EntryPoint = "XDrawRectangle")]
+ internal extern static int XDrawRectangle(IntPtr display, IntPtr drawable, IntPtr gc, int x1, int y1, int width, int height);
+
+ [DllImport("libX11", EntryPoint = "XFillRectangle")]
+ internal extern static int XFillRectangle(IntPtr display, IntPtr drawable, IntPtr gc, int x1, int y1, int width, int height);
+
+ [DllImport("libX11", EntryPoint = "XSetWindowBackground")]
+ internal extern static int XSetWindowBackground(IntPtr display, IntPtr window, IntPtr background);
+
+ [DllImport("libX11", EntryPoint = "XCopyArea")]
+ internal extern static int XCopyArea(IntPtr display, IntPtr src, IntPtr dest, IntPtr gc, int src_x, int src_y, int width, int height, int dest_x, int dest_y);
+
+ [DllImport("libX11", EntryPoint = "XGetWindowProperty")]
+ internal extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop);
+
+ [DllImport("libX11", EntryPoint = "XSetInputFocus")]
+ internal extern static int XSetInputFocus(IntPtr display, IntPtr window, RevertTo revert_to, IntPtr time);
+
+ [DllImport("libX11", EntryPoint = "XIconifyWindow")]
+ internal extern static int XIconifyWindow(IntPtr display, IntPtr window, int screen_number);
+
+ [DllImport("libX11", EntryPoint = "XDefineCursor")]
+ internal extern static int XDefineCursor(IntPtr display, IntPtr window, IntPtr cursor);
+
+ [DllImport("libX11", EntryPoint = "XUndefineCursor")]
+ internal extern static int XUndefineCursor(IntPtr display, IntPtr window);
+
+ [DllImport("libX11", EntryPoint = "XFreeCursor")]
+ internal extern static int XFreeCursor(IntPtr display, IntPtr cursor);
+
+ [DllImport("libX11", EntryPoint = "XCreateFontCursor")]
+ internal extern static IntPtr XCreateFontCursor(IntPtr display, CursorFontShape shape);
+
+ [DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]
+ internal extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foreground_color, ref XColor background_color, int x_hot, int y_hot);
+
+ [DllImport("libX11", EntryPoint = "XCreatePixmapFromBitmapData")]
+ internal extern static IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width, int height, IntPtr fg, IntPtr bg, int depth);
+
+ [DllImport("libX11", EntryPoint = "XCreatePixmap")]
+ internal extern static IntPtr XCreatePixmap(IntPtr display, IntPtr d, int width, int height, int depth);
+
+ [DllImport("libX11", EntryPoint = "XFreePixmap")]
+ internal extern static IntPtr XFreePixmap(IntPtr display, IntPtr pixmap);
+
+ [DllImport("libX11", EntryPoint = "XQueryBestCursor")]
+ internal extern static int XQueryBestCursor(IntPtr display, IntPtr drawable, int width, int height, out int best_width, out int best_height);
+
+ [DllImport("libX11", EntryPoint = "XQueryExtension")]
+ internal extern static int XQueryExtension(IntPtr display, string extension_name, ref int major, ref int first_event, ref int first_error);
+
+ [DllImport("libX11", EntryPoint = "XWhitePixel")]
+ internal extern static IntPtr XWhitePixel(IntPtr display, int screen_no);
+
+ [DllImport("libX11", EntryPoint = "XBlackPixel")]
+ internal extern static IntPtr XBlackPixel(IntPtr display, int screen_no);
+
+ [DllImport("libX11", EntryPoint = "XGrabServer")]
+ internal extern static void XGrabServer(IntPtr display);
+
+ [DllImport("libX11", EntryPoint = "XUngrabServer")]
+ internal extern static void XUngrabServer(IntPtr display);
+
+ [DllImport("libX11", EntryPoint = "XGetWMNormalHints")]
+ internal extern static void XGetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints, out IntPtr supplied_return);
+
+ [DllImport("libX11", EntryPoint = "XSetWMNormalHints")]
+ internal extern static void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints);
+
+ [DllImport("libX11", EntryPoint = "XSetZoomHints")]
+ internal extern static void XSetZoomHints(IntPtr display, IntPtr window, ref XSizeHints hints);
+
+ [DllImport("libX11", EntryPoint = "XSetWMHints")]
+ internal extern static void XSetWMHints(IntPtr display, IntPtr window, ref XWMHints wmhints);
+
+ [DllImport("libX11", EntryPoint = "XGetIconSizes")]
+ internal extern static int XGetIconSizes(IntPtr display, IntPtr window, out IntPtr size_list, out int count);
+
+ [DllImport("libX11", EntryPoint = "XSetErrorHandler")]
+ internal extern static IntPtr XSetErrorHandler(XErrorHandler error_handler);
+
+ [DllImport("libX11", EntryPoint = "XGetErrorText")]
+ internal extern static IntPtr XGetErrorText(IntPtr display, byte code, StringBuilder buffer, int length);
+
+ [DllImport("libX11", EntryPoint = "XInitThreads")]
+ internal extern static int XInitThreads();
+
+ [DllImport("libX11", EntryPoint = "XConvertSelection")]
+ internal extern static int XConvertSelection(IntPtr display, IntPtr selection, IntPtr target, IntPtr property, IntPtr requestor, IntPtr time);
+
+ [DllImport("libX11", EntryPoint = "XGetSelectionOwner")]
+ internal extern static IntPtr XGetSelectionOwner(IntPtr display, IntPtr selection);
+
+ [DllImport("libX11", EntryPoint = "XSetSelectionOwner")]
+ internal extern static int XSetSelectionOwner(IntPtr display, IntPtr selection, IntPtr owner, IntPtr time);
+
+ [DllImport("libX11", EntryPoint = "XSetPlaneMask")]
+ internal extern static int XSetPlaneMask(IntPtr display, IntPtr gc, IntPtr mask);
+
+ [DllImport("libX11", EntryPoint = "XSetForeground")]
+ internal extern static int XSetForeground(IntPtr display, IntPtr gc, UIntPtr foreground);
+
+ [DllImport("libX11", EntryPoint = "XSetBackground")]
+ internal extern static int XSetBackground(IntPtr display, IntPtr gc, UIntPtr background);
+
+ [DllImport("libX11", EntryPoint = "XBell")]
+ internal extern static int XBell(IntPtr display, int percent);
+
+ [DllImport("libX11", EntryPoint = "XChangeActivePointerGrab")]
+ internal extern static int XChangeActivePointerGrab(IntPtr display, EventMask event_mask, IntPtr cursor, IntPtr time);
+
+ [DllImport("libX11", EntryPoint = "XFilterEvent")]
+ internal extern static bool XFilterEvent(ref XEvent xevent, IntPtr window);
+
+ [DllImport("libX11")]
+ internal extern static void XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, IntPtr supported);
+
+ [DllImport("libX11")]
+ internal extern static void XPeekEvent(IntPtr display, ref XEvent xevent);
+ }
+}
diff --git a/Source/OpenTK/Platform/X11/Structs.cs b/Source/OpenTK/Platform/X11/Structs.cs
new file mode 100644
index 00000000..6ed282af
--- /dev/null
+++ b/Source/OpenTK/Platform/X11/Structs.cs
@@ -0,0 +1,1657 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software",, to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2004 Novell, Inc.
+//
+// Authors:
+// Peter Bartok pbartok@novell.com
+//
+
+
+// NOT COMPLETE
+
+using System;
+using System.ComponentModel;
+using System.Collections;
+using System.Drawing;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+/// X11 Version
+namespace OpenTK.Platform.X11
+{
+ //
+ // In the structures below, fields of type long are mapped to IntPtr.
+ // This will work on all platforms where sizeof(long)==sizeof(void*), which
+ // is almost all platforms except WIN64.
+ //
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XAnyEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XKeyEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr root;
+ internal IntPtr subwindow;
+ internal IntPtr time;
+ internal int x;
+ internal int y;
+ internal int x_root;
+ internal int y_root;
+ internal int state;
+ internal int keycode;
+ internal bool same_screen;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XButtonEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr root;
+ internal IntPtr subwindow;
+ internal IntPtr time;
+ internal int x;
+ internal int y;
+ internal int x_root;
+ internal int y_root;
+ internal int state;
+ internal int button;
+ internal bool same_screen;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XMotionEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr root;
+ internal IntPtr subwindow;
+ internal IntPtr time;
+ internal int x;
+ internal int y;
+ internal int x_root;
+ internal int y_root;
+ internal int state;
+ internal byte is_hint;
+ internal bool same_screen;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XCrossingEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr root;
+ internal IntPtr subwindow;
+ internal IntPtr time;
+ internal int x;
+ internal int y;
+ internal int x_root;
+ internal int y_root;
+ internal NotifyMode mode;
+ internal NotifyDetail detail;
+ internal bool same_screen;
+ internal bool focus;
+ internal int state;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XFocusChangeEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal int mode;
+ internal NotifyDetail detail;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XKeymapEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal byte key_vector0;
+ internal byte key_vector1;
+ internal byte key_vector2;
+ internal byte key_vector3;
+ internal byte key_vector4;
+ internal byte key_vector5;
+ internal byte key_vector6;
+ internal byte key_vector7;
+ internal byte key_vector8;
+ internal byte key_vector9;
+ internal byte key_vector10;
+ internal byte key_vector11;
+ internal byte key_vector12;
+ internal byte key_vector13;
+ internal byte key_vector14;
+ internal byte key_vector15;
+ internal byte key_vector16;
+ internal byte key_vector17;
+ internal byte key_vector18;
+ internal byte key_vector19;
+ internal byte key_vector20;
+ internal byte key_vector21;
+ internal byte key_vector22;
+ internal byte key_vector23;
+ internal byte key_vector24;
+ internal byte key_vector25;
+ internal byte key_vector26;
+ internal byte key_vector27;
+ internal byte key_vector28;
+ internal byte key_vector29;
+ internal byte key_vector30;
+ internal byte key_vector31;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XExposeEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int count;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XGraphicsExposeEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr drawable;
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int count;
+ internal int major_code;
+ internal int minor_code;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XNoExposeEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr drawable;
+ internal int major_code;
+ internal int minor_code;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XVisibilityEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal int state;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XCreateWindowEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr parent;
+ internal IntPtr window;
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int border_width;
+ internal bool override_redirect;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XDestroyWindowEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XUnmapEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ internal bool from_configure;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XMapEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ internal bool override_redirect;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XMapRequestEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr parent;
+ internal IntPtr window;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XReparentEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ internal IntPtr parent;
+ internal int x;
+ internal int y;
+ internal bool override_redirect;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XConfigureEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int border_width;
+ internal IntPtr above;
+ internal bool override_redirect;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XGravityEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ internal int x;
+ internal int y;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XResizeRequestEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal int width;
+ internal int height;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XConfigureRequestEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr parent;
+ internal IntPtr window;
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int border_width;
+ internal IntPtr above;
+ internal int detail;
+ internal IntPtr value_mask;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XCirculateEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr xevent;
+ internal IntPtr window;
+ internal int place;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XCirculateRequestEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr parent;
+ internal IntPtr window;
+ internal int place;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XPropertyEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr atom;
+ internal IntPtr time;
+ internal int state;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XSelectionClearEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr selection;
+ internal IntPtr time;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XSelectionRequestEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr owner;
+ internal IntPtr requestor;
+ internal IntPtr selection;
+ internal IntPtr target;
+ internal IntPtr property;
+ internal IntPtr time;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XSelectionEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr requestor;
+ internal IntPtr selection;
+ internal IntPtr target;
+ internal IntPtr property;
+ internal IntPtr time;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XColormapEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr colormap;
+ internal bool c_new;
+ internal int state;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XClientMessageEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal IntPtr message_type;
+ internal int format;
+ internal IntPtr ptr1;
+ internal IntPtr ptr2;
+ internal IntPtr ptr3;
+ internal IntPtr ptr4;
+ internal IntPtr ptr5;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XMappingEvent
+ {
+ internal XEventName type;
+ internal IntPtr serial;
+ internal bool send_event;
+ internal IntPtr display;
+ internal IntPtr window;
+ internal int request;
+ internal int first_keycode;
+ internal int count;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XErrorEvent
+ {
+ internal XEventName type;
+ internal IntPtr display;
+ internal IntPtr resourceid;
+ internal IntPtr serial;
+ internal byte error_code;
+ internal XRequest request_code;
+ internal byte minor_code;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XEventPad
+ {
+ internal IntPtr pad0;
+ internal IntPtr pad1;
+ internal IntPtr pad2;
+ internal IntPtr pad3;
+ internal IntPtr pad4;
+ internal IntPtr pad5;
+ internal IntPtr pad6;
+ internal IntPtr pad7;
+ internal IntPtr pad8;
+ internal IntPtr pad9;
+ internal IntPtr pad10;
+ internal IntPtr pad11;
+ internal IntPtr pad12;
+ internal IntPtr pad13;
+ internal IntPtr pad14;
+ internal IntPtr pad15;
+ internal IntPtr pad16;
+ internal IntPtr pad17;
+ internal IntPtr pad18;
+ internal IntPtr pad19;
+ internal IntPtr pad20;
+ internal IntPtr pad21;
+ internal IntPtr pad22;
+ internal IntPtr pad23;
+ }
+
+ [StructLayout(LayoutKind.Explicit)]
+ internal struct XEvent
+ {
+ [FieldOffset(0)]
+ internal XEventName type;
+ [FieldOffset(0)]
+ internal XAnyEvent AnyEvent;
+ [FieldOffset(0)]
+ internal XKeyEvent KeyEvent;
+ [FieldOffset(0)]
+ internal XButtonEvent ButtonEvent;
+ [FieldOffset(0)]
+ internal XMotionEvent MotionEvent;
+ [FieldOffset(0)]
+ internal XCrossingEvent CrossingEvent;
+ [FieldOffset(0)]
+ internal XFocusChangeEvent FocusChangeEvent;
+ [FieldOffset(0)]
+ internal XExposeEvent ExposeEvent;
+ [FieldOffset(0)]
+ internal XGraphicsExposeEvent GraphicsExposeEvent;
+ [FieldOffset(0)]
+ internal XNoExposeEvent NoExposeEvent;
+ [FieldOffset(0)]
+ internal XVisibilityEvent VisibilityEvent;
+ [FieldOffset(0)]
+ internal XCreateWindowEvent CreateWindowEvent;
+ [FieldOffset(0)]
+ internal XDestroyWindowEvent DestroyWindowEvent;
+ [FieldOffset(0)]
+ internal XUnmapEvent UnmapEvent;
+ [FieldOffset(0)]
+ internal XMapEvent MapEvent;
+ [FieldOffset(0)]
+ internal XMapRequestEvent MapRequestEvent;
+ [FieldOffset(0)]
+ internal XReparentEvent ReparentEvent;
+ [FieldOffset(0)]
+ internal XConfigureEvent ConfigureEvent;
+ [FieldOffset(0)]
+ internal XGravityEvent GravityEvent;
+ [FieldOffset(0)]
+ internal XResizeRequestEvent ResizeRequestEvent;
+ [FieldOffset(0)]
+ internal XConfigureRequestEvent ConfigureRequestEvent;
+ [FieldOffset(0)]
+ internal XCirculateEvent CirculateEvent;
+ [FieldOffset(0)]
+ internal XCirculateRequestEvent CirculateRequestEvent;
+ [FieldOffset(0)]
+ internal XPropertyEvent PropertyEvent;
+ [FieldOffset(0)]
+ internal XSelectionClearEvent SelectionClearEvent;
+ [FieldOffset(0)]
+ internal XSelectionRequestEvent SelectionRequestEvent;
+ [FieldOffset(0)]
+ internal XSelectionEvent SelectionEvent;
+ [FieldOffset(0)]
+ internal XColormapEvent ColormapEvent;
+ [FieldOffset(0)]
+ internal XClientMessageEvent ClientMessageEvent;
+ [FieldOffset(0)]
+ internal XMappingEvent MappingEvent;
+ [FieldOffset(0)]
+ internal XErrorEvent ErrorEvent;
+ [FieldOffset(0)]
+ internal XKeymapEvent KeymapEvent;
+
+ //[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=24)]
+ //[ FieldOffset(0) ] internal int[] pad;
+ [FieldOffset(0)]
+ internal XEventPad Pad;
+ public override string ToString()
+ {
+ switch (type)
+ {
+ case XEventName.PropertyNotify:
+ return ToString(PropertyEvent);
+ case XEventName.ResizeRequest:
+ return ToString(ResizeRequestEvent);
+ case XEventName.ConfigureNotify:
+ return ToString(ConfigureEvent);
+ default:
+ return type.ToString();
+ }
+ }
+
+ public static string ToString(object ev)
+ {
+ string result = string.Empty;
+ Type type = ev.GetType();
+ System.Reflection.FieldInfo[] fields = type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance);
+ for (int i = 0; i < fields.Length; i++)
+ {
+ if (result != string.Empty)
+ {
+ result += ", ";
+ }
+ object value = fields[i].GetValue(ev);
+ result += fields[i].Name + "=" + (value == null ? "" : value.ToString());
+ }
+ return type.Name + " (" + result + ")";
+ }
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XSetWindowAttributes
+ {
+ internal IntPtr background_pixmap;
+ internal IntPtr background_pixel;
+ internal IntPtr border_pixmap;
+ internal IntPtr border_pixel;
+ internal Gravity bit_gravity;
+ internal Gravity win_gravity;
+ internal int backing_store;
+ internal IntPtr backing_planes;
+ internal IntPtr backing_pixel;
+ internal bool save_under;
+ internal IntPtr event_mask;
+ internal IntPtr do_not_propagate_mask;
+ internal bool override_redirect;
+ internal IntPtr colormap;
+ internal IntPtr cursor;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XWindowAttributes
+ {
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int border_width;
+ internal int depth;
+ internal IntPtr visual;
+ internal IntPtr root;
+ internal int c_class;
+ internal Gravity bit_gravity;
+ internal Gravity win_gravity;
+ internal int backing_store;
+ internal IntPtr backing_planes;
+ internal IntPtr backing_pixel;
+ internal bool save_under;
+ internal IntPtr colormap;
+ internal bool map_installed;
+ internal MapState map_state;
+ internal IntPtr all_event_masks;
+ internal IntPtr your_event_mask;
+ internal IntPtr do_not_propagate_mask;
+ internal bool override_direct;
+ internal IntPtr screen;
+
+ public override string ToString()
+ {
+ return XEvent.ToString(this);
+ }
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XTextProperty
+ {
+ internal string value;
+ internal IntPtr encoding;
+ internal int format;
+ internal IntPtr nitems;
+ }
+
+ internal enum XWindowClass
+ {
+ InputOutput = 1,
+ InputOnly = 2
+ }
+
+ internal enum XEventName
+ {
+ KeyPress = 2,
+ KeyRelease = 3,
+ ButtonPress = 4,
+ ButtonRelease = 5,
+ MotionNotify = 6,
+ EnterNotify = 7,
+ LeaveNotify = 8,
+ FocusIn = 9,
+ FocusOut = 10,
+ KeymapNotify = 11,
+ Expose = 12,
+ GraphicsExpose = 13,
+ NoExpose = 14,
+ VisibilityNotify = 15,
+ CreateNotify = 16,
+ DestroyNotify = 17,
+ UnmapNotify = 18,
+ MapNotify = 19,
+ MapRequest = 20,
+ ReparentNotify = 21,
+ ConfigureNotify = 22,
+ ConfigureRequest = 23,
+ GravityNotify = 24,
+ ResizeRequest = 25,
+ CirculateNotify = 26,
+ CirculateRequest = 27,
+ PropertyNotify = 28,
+ SelectionClear = 29,
+ SelectionRequest = 30,
+ SelectionNotify = 31,
+ ColormapNotify = 32,
+ ClientMessage = 33,
+ MappingNotify = 34,
+
+ LASTEvent
+ }
+
+ [Flags]
+ internal enum SetWindowValuemask
+ {
+ Nothing = 0,
+ BackPixmap = 1,
+ BackPixel = 2,
+ BorderPixmap = 4,
+ BorderPixel = 8,
+ BitGravity = 16,
+ WinGravity = 32,
+ BackingStore = 64,
+ BackingPlanes = 128,
+ BackingPixel = 256,
+ OverrideRedirect = 512,
+ SaveUnder = 1024,
+ EventMask = 2048,
+ DontPropagate = 4096,
+ ColorMap = 8192,
+ Cursor = 16384
+ }
+
+ internal enum CreateWindowArgs
+ {
+ CopyFromParent = 0,
+ ParentRelative = 1,
+ InputOutput = 1,
+ InputOnly = 2
+ }
+
+ internal enum Gravity
+ {
+ ForgetGravity = 0,
+ NorthWestGravity = 1,
+ NorthGravity = 2,
+ NorthEastGravity = 3,
+ WestGravity = 4,
+ CenterGravity = 5,
+ EastGravity = 6,
+ SouthWestGravity = 7,
+ SouthGravity = 8,
+ SouthEastGravity = 9,
+ StaticGravity = 10
+ }
+
+ internal enum XKeySym : uint
+ {
+ XK_BackSpace = 0xFF08,
+ XK_Tab = 0xFF09,
+ XK_Clear = 0xFF0B,
+ XK_Return = 0xFF0D,
+ XK_Home = 0xFF50,
+ XK_Left = 0xFF51,
+ XK_Up = 0xFF52,
+ XK_Right = 0xFF53,
+ XK_Down = 0xFF54,
+ XK_Page_Up = 0xFF55,
+ XK_Page_Down = 0xFF56,
+ XK_End = 0xFF57,
+ XK_Begin = 0xFF58,
+ XK_Menu = 0xFF67,
+ XK_Shift_L = 0xFFE1,
+ XK_Shift_R = 0xFFE2,
+ XK_Control_L = 0xFFE3,
+ XK_Control_R = 0xFFE4,
+ XK_Caps_Lock = 0xFFE5,
+ XK_Shift_Lock = 0xFFE6,
+ XK_Meta_L = 0xFFE7,
+ XK_Meta_R = 0xFFE8,
+ XK_Alt_L = 0xFFE9,
+ XK_Alt_R = 0xFFEA,
+ XK_Super_L = 0xFFEB,
+ XK_Super_R = 0xFFEC,
+ XK_Hyper_L = 0xFFED,
+ XK_Hyper_R = 0xFFEE,
+ }
+
+ [Flags]
+ internal enum EventMask// : long
+ {
+ NoEventMask = 0,
+ KeyPressMask = 1 << 0,
+ KeyReleaseMask = 1 << 1,
+ ButtonPressMask = 1 << 2,
+ ButtonReleaseMask = 1 << 3,
+ EnterWindowMask = 1 << 4,
+ LeaveWindowMask = 1 << 5,
+ PointerMotionMask = 1 << 6,
+ PointerMotionHintMask = 1 << 7,
+ Button1MotionMask = 1 << 8,
+ Button2MotionMask = 1 << 9,
+ Button3MotionMask = 1 << 10,
+ Button4MotionMask = 1 << 11,
+ Button5MotionMask = 1 << 12,
+ ButtonMotionMask = 1 << 13,
+ KeymapStateMask = 1 << 14,
+ ExposureMask = 1 << 15,
+ VisibilityChangeMask = 1 << 16,
+ StructureNotifyMask = 1 << 17,
+ ResizeRedirectMask = 1 << 18,
+ SubstructureNotifyMask = 1 << 19,
+ SubstructureRedirectMask = 1 << 20,
+ FocusChangeMask = 1 << 21,
+ PropertyChangeMask = 1 << 22,
+ ColormapChangeMask = 1 << 23,
+ OwnerGrabButtonMask = 1 << 24
+ }
+
+ internal enum GrabMode
+ {
+ GrabModeSync = 0,
+ GrabModeAsync = 1
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XStandardColormap
+ {
+ internal IntPtr colormap;
+ internal IntPtr red_max;
+ internal IntPtr red_mult;
+ internal IntPtr green_max;
+ internal IntPtr green_mult;
+ internal IntPtr blue_max;
+ internal IntPtr blue_mult;
+ internal IntPtr base_pixel;
+ internal IntPtr visualid;
+ internal IntPtr killid;
+ }
+
+ [StructLayout(LayoutKind.Sequential, Pack = 2)]
+ internal struct XColor
+ {
+ internal IntPtr pixel;
+ internal ushort red;
+ internal ushort green;
+ internal ushort blue;
+ internal byte flags;
+ internal byte pad;
+ }
+
+ internal enum Atom
+ {
+ AnyPropertyType = 0,
+ XA_PRIMARY = 1,
+ XA_SECONDARY = 2,
+ XA_ARC = 3,
+ XA_ATOM = 4,
+ XA_BITMAP = 5,
+ XA_CARDINAL = 6,
+ XA_COLORMAP = 7,
+ XA_CURSOR = 8,
+ XA_CUT_BUFFER0 = 9,
+ XA_CUT_BUFFER1 = 10,
+ XA_CUT_BUFFER2 = 11,
+ XA_CUT_BUFFER3 = 12,
+ XA_CUT_BUFFER4 = 13,
+ XA_CUT_BUFFER5 = 14,
+ XA_CUT_BUFFER6 = 15,
+ XA_CUT_BUFFER7 = 16,
+ XA_DRAWABLE = 17,
+ XA_FONT = 18,
+ XA_INTEGER = 19,
+ XA_PIXMAP = 20,
+ XA_POINT = 21,
+ XA_RECTANGLE = 22,
+ XA_RESOURCE_MANAGER = 23,
+ XA_RGB_COLOR_MAP = 24,
+ XA_RGB_BEST_MAP = 25,
+ XA_RGB_BLUE_MAP = 26,
+ XA_RGB_DEFAULT_MAP = 27,
+ XA_RGB_GRAY_MAP = 28,
+ XA_RGB_GREEN_MAP = 29,
+ XA_RGB_RED_MAP = 30,
+ XA_STRING = 31,
+ XA_VISUALID = 32,
+ XA_WINDOW = 33,
+ XA_WM_COMMAND = 34,
+ XA_WM_HINTS = 35,
+ XA_WM_CLIENT_MACHINE = 36,
+ XA_WM_ICON_NAME = 37,
+ XA_WM_ICON_SIZE = 38,
+ XA_WM_NAME = 39,
+ XA_WM_NORMAL_HINTS = 40,
+ XA_WM_SIZE_HINTS = 41,
+ XA_WM_ZOOM_HINTS = 42,
+ XA_MIN_SPACE = 43,
+ XA_NORM_SPACE = 44,
+ XA_MAX_SPACE = 45,
+ XA_END_SPACE = 46,
+ XA_SUPERSCRIPT_X = 47,
+ XA_SUPERSCRIPT_Y = 48,
+ XA_SUBSCRIPT_X = 49,
+ XA_SUBSCRIPT_Y = 50,
+ XA_UNDERLINE_POSITION = 51,
+ XA_UNDERLINE_THICKNESS = 52,
+ XA_STRIKEOUT_ASCENT = 53,
+ XA_STRIKEOUT_DESCENT = 54,
+ XA_ITALIC_ANGLE = 55,
+ XA_X_HEIGHT = 56,
+ XA_QUAD_WIDTH = 57,
+ XA_WEIGHT = 58,
+ XA_POINT_SIZE = 59,
+ XA_RESOLUTION = 60,
+ XA_COPYRIGHT = 61,
+ XA_NOTICE = 62,
+ XA_FONT_NAME = 63,
+ XA_FAMILY_NAME = 64,
+ XA_FULL_NAME = 65,
+ XA_CAP_HEIGHT = 66,
+ XA_WM_CLASS = 67,
+ XA_WM_TRANSIENT_FOR = 68,
+
+ XA_LAST_PREDEFINED = 68
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XScreen
+ {
+ internal IntPtr ext_data;
+ internal IntPtr display;
+ internal IntPtr root;
+ internal int width;
+ internal int height;
+ internal int mwidth;
+ internal int mheight;
+ internal int ndepths;
+ internal IntPtr depths;
+ internal int root_depth;
+ internal IntPtr root_visual;
+ internal IntPtr default_gc;
+ internal IntPtr cmap;
+ internal IntPtr white_pixel;
+ internal IntPtr black_pixel;
+ internal int max_maps;
+ internal int min_maps;
+ internal int backing_store;
+ internal bool save_unders;
+ internal IntPtr root_input_mask;
+ }
+
+ [Flags]
+ internal enum ChangeWindowFlags
+ {
+ CWX = 1 << 0,
+ CWY = 1 << 1,
+ CWWidth = 1 << 2,
+ CWHeight = 1 << 3,
+ CWBorderWidth = 1 << 4,
+ CWSibling = 1 << 5,
+ CWStackMode = 1 << 6
+ }
+
+ internal enum StackMode
+ {
+ Above = 0,
+ Below = 1,
+ TopIf = 2,
+ BottomIf = 3,
+ Opposite = 4
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct XWindowChanges
+ {
+ internal int x;
+ internal int y;
+ internal int width;
+ internal int height;
+ internal int border_width;
+ internal IntPtr sibling;
+ internal StackMode stack_mode;
+ }
+
+ [Flags]
+ internal enum ColorFlags
+ {
+ DoRed = 1 << 0,
+ DoGreen = 1 << 1,
+ DoBlue = 1 << 2
+ }
+
+ internal enum NotifyMode
+ {
+ NotifyNormal = 0,
+ NotifyGrab = 1,
+ NotifyUngrab = 2
+ }
+
+ internal enum NotifyDetail
+ {
+ NotifyAncestor = 0,
+ NotifyVirtual = 1,
+ NotifyInferior = 2,
+ NotifyNonlinear = 3,
+ NotifyNonlinearVirtual = 4,
+ NotifyPointer = 5,
+ NotifyPointerRoot = 6,
+ NotifyDetailNone = 7
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct MotifWmHints
+ {
+ internal IntPtr flags;
+ internal IntPtr functions;
+ internal IntPtr decorations;
+ internal IntPtr input_mode;
+ internal IntPtr status;
+
+ public override string ToString()
+ {
+ return string.Format("MotifWmHints
public void CreateWindow(DisplayMode mode)
{
- Debug.Print("Creating native window with mode: {0}", mode.ToString());
- Debug.Indent();
-
- info.Display = API.OpenDisplay(null); // null == default display
- if (info.Display == IntPtr.Zero)
+ if (created)
{
- throw new Exception("Could not open connection to X");
+ throw new ApplicationException("Render window already exists!");
}
- info.Screen = API.DefaultScreen(info.Display);
- info.RootWindow = API.RootWindow(info.Display, info.Screen);
-
- Debug.Print(
- "Display: {0}, Screen {1}, Root window: {2}",
- info.Display,
- info.Screen,
- info.RootWindow
- );
-
- glContext = new X11GLContext(info, mode);
- info.VisualInfo = glContext.CreateVisual();
-
- // Create a window on this display using the visual above
- Debug.Write("Creating output window... ");
-
- SetWindowAttributes wnd_attributes = new SetWindowAttributes();
- wnd_attributes.background_pixel = 0;
- wnd_attributes.border_pixel = 0;
- wnd_attributes.colormap = glContext.XColormap;
- //API.CreateColormap(display, rootWindow, glxVisualInfo.visual, 0/*AllocNone*/);
- wnd_attributes.event_mask =
- EventMask.StructureNotifyMask;// |
- //EventMask.SubstructureNotifyMask |
- //EventMask.ExposureMask;
-
- CreateWindowMask cw_mask =
- CreateWindowMask.CWBackPixel |
- CreateWindowMask.CWBorderPixel |
- CreateWindowMask.CWColormap |
- CreateWindowMask.CWEventMask;
-
- info.Handle = API.CreateWindow(
- info.Display,
- info.RootWindow,
- 0, 0,
- mode.Width, mode.Height,
- 0,
- glContext.XVisualInfo.depth,
- Constants.InputOutput,
- glContext.XVisualInfo.visual,
- cw_mask,
- wnd_attributes
- );
-
- if (info.Handle == IntPtr.Zero)
+ else
{
- throw new Exception("Could not create window.");
+ Debug.Print("Creating native window with mode: {0}", mode.ToString());
+ Debug.Indent();
+
+ window.Display = API.OpenDisplay(null); // null == default display
+ if (window.Display == IntPtr.Zero)
+ {
+ throw new Exception("Could not open connection to X");
+ }
+ window.Screen = API.DefaultScreen(window.Display);
+ window.RootWindow = API.RootWindow(window.Display, window.Screen);
+
+ Debug.Print(
+ "Display: {0}, Screen {1}, Root window: {2}",
+ window.Display,
+ window.Screen,
+ window.RootWindow
+ );
+
+ glContext = new X11GLContext(window, mode);
+ window.VisualInfo = glContext.CreateVisual();
+
+ // Create a window on this display using the visual above
+ Debug.Write("Creating output window... ");
+
+ XSetWindowAttributes attributes = new XSetWindowAttributes();
+ attributes.colormap = glContext.colormap;
+ attributes.event_mask = (IntPtr)(EventMask.StructureNotifyMask);
+
+ SetWindowValuemask mask = SetWindowValuemask.ColorMap | SetWindowValuemask.EventMask;
+
+ window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
+ 0, 0, mode.Width, mode.Height, 0, glContext.XVisualInfo.depth,
+ (int)CreateWindowArgs.InputOutput, glContext.XVisualInfo.visual, (UIntPtr)mask,
+ ref attributes);
+
+ if (window.Handle == IntPtr.Zero)
+ {
+ throw new Exception("Could not create window.");
+ }
+ /*
+ // Set the window hints
+ XSizeHints hints = new XSizeHints();
+ hints.x = 0;
+ hints.y = 0;
+ hints.width = 640;
+ hints.height = 480;
+ hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition);
+ Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);
+ XTextProperty text = new XTextProperty();
+ text.value = "OpenTK Game Window";
+ text.format = 8;
+ Functions.XSetWMName(window.Display, window.Handle, ref text);
+ Functions.XSetWMProperties(
+ display,
+ window,
+ name,
+ name,
+ 0, // None
+ null,
+ 0,
+ hints
+ );*/
+
+ Debug.Print("done! (id: {0})", window.Handle);
+
+ glContext.windowInfo.Handle = window.Handle;
+ glContext.CreateContext(null, true);
+
+ API.MapRaised(window.Display, window.Handle);
+
+ Debug.WriteLine("Mapped window.");
+
+ //glContext.MakeCurrent();
+
+ Debug.WriteLine("Our shiny new context is now current - ready to rock 'n' roll!");
+ Debug.Unindent();
+ created = true;
}
-
- Debug.WriteLine("done! (id: " + info.Handle + ")");
-/*
- // Set the window hints
- SizeHints hints = new SizeHints();
- hints.x = 0;
- hints.y = 0;
- hints.width = 640;
- hints.height = 480;
- hints.flags = USSize | USPosition;
- API.SetNormalHints(display, window, hints);
- API.SetStandardProperties(
- display,
- window,
- name,
- name,
- 0, // None
- null,
- 0,
- hints
- );
-
- //glContext.ContainingWindow = info.Window;
-*/
-
- glContext.windowInfo.Handle = info.Handle;
- glContext.CreateContext(null, true);
-
- API.MapRaised(info.Display, info.Handle);
-
- Debug.WriteLine("Mapped window.");
-
- //glContext.MakeCurrent();
-
- Debug.WriteLine("Our shiny new context is now current - ready to rock 'n' roll!");
- Debug.Unindent();
- created = true;
}
#endregion
@@ -200,70 +181,60 @@ namespace OpenTK.Platform.X11
// Process all pending events
while (true)
{
- pending = API.Pending(info.Display);
+ //pending = Functions.XPending(info.Display);
+ pending = Functions.XPending(window.Display);
if (pending == 0)
return;
- //API.NextEvent(info.Display, e);
- API.PeekEvent(info.Display, e);
- //API.NextEvent(info.Display, eventPtr);
+ Functions.XNextEvent(window.Display, ref e);
-
- 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.
- Debug.Assert(memGuard == 0, "memGuard2 tripped", String.Format("Guard: {0}", memGuard));
- memGuard = 0;
+ Debug.WriteLine(String.Format("Event: {0} ({1} pending)", e.type, pending));
// Respond to the event e
- switch (e.Type)
+ switch (e.type)
{
- case EventType.ReparentNotify:
- API.NextEvent(info.Display, reparent);
-
+ case XEventName.ReparentNotify:
// TODO: Is there a more suitable place to raise the Create event?
// ReparentNotify seems to be the first event raised on window creation.
this.OnCreate(EventArgs.Empty);
break;
- case EventType.CreateNotify:
- API.NextEvent(info.Display, createWindow);
+ case XEventName.CreateNotify:
// A child was created - nothing to do
break;
- case EventType.DestroyNotify:
- API.NextEvent(info.Display, destroyWindow);
+ case XEventName.DestroyNotify:
+ glContext.Dispose();
+ Functions.XDestroyWindow(window.Display, window.Handle);
+ window = null;
+ glContext = null;
quit = true;
Debug.WriteLine("Window destroyed, shutting down.");
break;
- case EventType.ConfigureNotify:
- API.NextEvent(info.Display, configure);
-
+ case XEventName.ConfigureNotify:
// If the window size changed, raise the C# Resize event.
- if (configure.width != mode.Width ||
- configure.height != mode.Height)
+ if (e.ConfigureEvent.width != mode.Width ||
+ e.ConfigureEvent.height != mode.Height)
{
Debug.WriteLine(
String.Format(
"New res: {0}x{1}",
- configure.width,
- configure.height
+ e.ConfigureEvent.width,
+ e.ConfigureEvent.height
)
);
- resizeEventArgs.Width = configure.width;
- resizeEventArgs.Height = configure.height;
+ resizeEventArgs.Width = e.ConfigureEvent.width;
+ resizeEventArgs.Height = e.ConfigureEvent.height;
this.OnResize(resizeEventArgs);
}
break;
default:
- API.NextEvent(info.Display, e);
- Debug.WriteLine(String.Format("{0} event was not handled", e.Type));
+ Debug.WriteLine(String.Format("{0} event was not handled", e.type));
break;
}
}
@@ -279,7 +250,7 @@ namespace OpenTK.Platform.X11
{
if (this.Create != null)
{
- Debug.Print("Create event fired from window: {0}", info.ToString());
+ Debug.Print("Create event fired from window: {0}", window.ToString());
this.Create(this, e);
}
}
@@ -351,7 +322,7 @@ namespace OpenTK.Platform.X11
///
public IntPtr Handle
{
- get { return this.info.Handle; }
+ get { return this.window.Handle; }
}
#endregion
@@ -360,7 +331,7 @@ namespace OpenTK.Platform.X11
public IWindowInfo WindowInfo
{
- get { return info; }
+ get { return window; }
}
#endregion
@@ -457,14 +428,16 @@ namespace OpenTK.Platform.X11
{
if (!disposed)
{
- API.DestroyWindow(info.Display, info.Handle);
+ if (window != null)
+ Functions.XDestroyWindow(window.Display, window.Handle);
// Kills connection to the X-Server. We don't want that,
// 'cause it kills the ExampleLauncher too.
//API.CloseDisplay(display);
if (manuallyCalled)
{
- glContext.Dispose();
+ if (glContext != null)
+ glContext.Dispose();
}
disposed = true;
}
diff --git a/Source/OpenTK/Platform/X11/X11Input.cs b/Source/OpenTK/Platform/X11/X11Input.cs
index c571bdd5..176f4983 100644
--- a/Source/OpenTK/Platform/X11/X11Input.cs
+++ b/Source/OpenTK/Platform/X11/X11Input.cs
@@ -16,9 +16,7 @@ namespace OpenTK.Platform.X11
private X11Keyboard keyboardDriver;
private WindowInfo window;
- Event e = new Event();
- KeyEvent keyEvent = new KeyEvent();
- int pending;
+ XEvent e = new XEvent();
#region --- Constructors ---
@@ -37,14 +35,15 @@ namespace OpenTK.Platform.X11
{
throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");
}
-
+ /*
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;
+ wnd_attributes.event_mask = EventMask.KeyPressMask | EventMask.KeyReleaseMask |
+ EventMask.FocusChangeMask;
CreateWindowMask cw_mask =
CreateWindowMask.CWEventMask;
@@ -55,10 +54,11 @@ namespace OpenTK.Platform.X11
window.Display,
window.Parent.Handle,
0, 0,
- 0, 0,
+ 1, 1,
0, 0,
Constants.InputOnly,
- window.VisualInfo.visual,
+ //window.VisualInfo.visual,
+ (IntPtr)0,
cw_mask,
wnd_attributes
);
@@ -69,14 +69,20 @@ namespace OpenTK.Platform.X11
}
API.MapWindow(window.Display, window.Handle);
+ API.GrabKeyboard(window.Display, window.Handle, false, GrabMode.GrabModeAsync, GrabMode.GrabModeAsync, 0);
Debug.WriteLine("done! (id: " + window + ")");
// Select input events to be reported here.
- //API.SelectInput(window.Display, window.Handle,
+ //API.SelectInput(window.Display, window.Parent.Handle,
// EventMask.KeyReleaseMask | EventMask.KeyPressMask);
-
+
keyboardDriver = new X11Keyboard(window);
+ */
+
+ keyboardDriver = new X11Keyboard(parent);
+ API.SelectInput(parent.Display, parent.Handle,
+ EventMask.KeyReleaseMask | EventMask.KeyPressMask);
Debug.Unindent();
}
@@ -118,28 +124,34 @@ namespace OpenTK.Platform.X11
///
public void ProcessEvents()
{
- pending = API.Pending(window.Display);
-
- if (pending == 0)
- return;
-
- API.PeekEvent(window.Display, e);
- Debug.Write(String.Format("Input window received {0} event... ", e.Type.ToString()));
-
- switch (e.Type)
+ try
{
- case EventType.KeyPress:
- case EventType.KeyRelease:
- API.NextEvent(window.Display, keyEvent);
- Debug.WriteLine(" consumed!");
- keyboardDriver.ProcessKeyboardEvent(keyEvent);
- break;
-
- default:
- API.NextEvent(window.Display, e);
- Debug.WriteLine(" not consumed.");
- break;
+ while (API.CheckIfEvent(window.Display, ref e, check, IntPtr.Zero))
+ {
+ Debug.Print("Input window received {0} event... ", e.type.ToString());
+ keyboardDriver.ProcessKeyboardEvent(e.KeyEvent);
+ }
}
+ catch (Exception e)
+ {
+ Debug.Print("DANGER: Possible callback exception: {0}", e.ToString());
+ }
+ }
+
+ API.CheckEventPredicate check = KeyEventPredicate;
+
+ private static bool KeyEventPredicate(IntPtr display, ref XEvent @event, IntPtr arg)
+ {
+ bool ret = false;
+ try
+ {
+ ret = (@event.type == XEventName.KeyRelease || @event.type == XEventName.KeyPress);
+ }
+ catch (Exception e)
+ {
+ Debug.Print("DANGER: Exception caught during unmanaged callback: {0}", e.ToString());
+ }
+ return ret;
}
#endregion
diff --git a/Source/OpenTK/Platform/X11/X11Keyboard.cs b/Source/OpenTK/Platform/X11/X11Keyboard.cs
index d0614fb0..3cc87c5f 100644
--- a/Source/OpenTK/Platform/X11/X11Keyboard.cs
+++ b/Source/OpenTK/Platform/X11/X11Keyboard.cs
@@ -103,8 +103,11 @@ namespace OpenTK.Platform.X11
Initialize();
API.DisplayKeycodes(window.Display, ref firstKeyCode, ref lastKeyCode);
+ Debug.Print("First keycode: {0}, last {1}", firstKeyCode, lastKeyCode);
+
IntPtr keysym_ptr = API.GetKeyboardMapping(window.Display, (byte)firstKeyCode,
lastKeyCode - firstKeyCode + 1, ref keysyms_per_keycode);
+ Debug.Print("{0} keysyms per keycode.", keysyms_per_keycode);
keysyms = new IntPtr[(lastKeyCode - firstKeyCode + 1) * keysyms_per_keycode];
Marshal.PtrToStructure(keysym_ptr, keysyms);
@@ -125,11 +128,11 @@ namespace OpenTK.Platform.X11
///
/// The X11.KeyEvent to process
/// True if the event was processed, false otherwise.
- internal bool ProcessKeyboardEvent(X11.KeyEvent e)
+ internal bool ProcessKeyboardEvent(X11.XKeyEvent e)
{
int keysym = keysyms[(e.keycode - firstKeyCode) * keysyms_per_keycode].ToInt32();
int keysym2 = keysyms[(e.keycode - firstKeyCode) * keysyms_per_keycode].ToInt32();
- bool pressed = e.type == EventType.KeyPress;
+ bool pressed = e.type == XEventName.KeyPress;
switch (keysym)
{