* X11Keyboard.cs: Use XQueryKeymap to discover key state.
* X11Factory.cs: Use new X11Keyboard interface. Temporarily disabled XI2Mouse for testing. * Functions.cs: Fixed type declaration for Time. Added support for XIGrabDevice, XIUngrabDevice, XGrabKey, XUngrabKey, XAllowEvents and XKeycodeToKeysym/XKeysymToKeycode. * API.cs: Enumerate modes for XAllowEvents.
This commit is contained in:
parent
bf89608157
commit
915f8e559f
4 changed files with 63 additions and 69 deletions
|
@ -1638,6 +1638,19 @@ XF86VidModeGetGammaRampSize(
|
|||
Functions.XUnlockDisplay(Display);
|
||||
}
|
||||
}
|
||||
|
||||
// XAllowEvent modes
|
||||
enum EventMode
|
||||
{
|
||||
AsyncPointer = 0,
|
||||
SyncPointer,
|
||||
ReplayPointer,
|
||||
AsyncKeyboard,
|
||||
SyncKeyboard,
|
||||
ReplayKeyboard,
|
||||
AsyncBoth,
|
||||
SyncBoth
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore 3019
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace OpenTK.Platform.X11
|
|||
using Mask = System.IntPtr;
|
||||
using Atom = System.IntPtr;
|
||||
using VisualID = System.IntPtr;
|
||||
using Time = System.UInt32;
|
||||
using Time = System.IntPtr;
|
||||
using KeyCode = System.Byte; // Or maybe ushort?
|
||||
|
||||
using Display = System.IntPtr;
|
||||
|
@ -185,12 +185,24 @@ namespace OpenTK.Platform.X11
|
|||
[DllImport("libX11", EntryPoint = "XTranslateCoordinates")]
|
||||
public 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")]
|
||||
public extern static int XGrabKey(IntPtr display, int keycode, uint modifiers,
|
||||
Window grab_window, bool owner_events, GrabMode pointer_mode, GrabMode keyboard_mode);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public extern static int XUngrabKey(IntPtr display, int keycode, uint modifiers, Window grab_window);
|
||||
|
||||
[DllImport("libX11", EntryPoint = "XGrabKeyboard")]
|
||||
public extern static int XGrabKeyboard(IntPtr display, IntPtr window, bool owner_events, GrabMode pointer_mode, GrabMode keyboard_mode, IntPtr timestamp);
|
||||
public extern static int XGrabKeyboard(IntPtr display, IntPtr window, bool owner_events,
|
||||
GrabMode pointer_mode, GrabMode keyboard_mode, IntPtr timestamp);
|
||||
|
||||
[DllImport("libX11", EntryPoint = "XUngrabKeyboard")]
|
||||
public extern static int XUngrabKeyboard(IntPtr display, IntPtr timestamp);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public extern static int XAllowEvents(IntPtr display, EventMode event_mode, Time time);
|
||||
|
||||
[DllImport("libX11", EntryPoint = "XGetGeometry")]
|
||||
public 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);
|
||||
|
||||
|
@ -468,6 +480,12 @@ namespace OpenTK.Platform.X11
|
|||
public static extern int XLookupString(ref XKeyEvent event_struct, [Out] byte[] buffer_return,
|
||||
int bytes_buffer, [Out] KeySym[] keysym_return, IntPtr status_in_out);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public static extern KeyCode XKeysymToKeycode(IntPtr display, KeySym keysym);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public static extern KeySym XKeycodeToKeysym(IntPtr display, KeyCode keycode, int index);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public static extern int XRefreshKeyboardMapping(ref XMappingEvent event_map);
|
||||
|
||||
|
@ -492,6 +510,13 @@ namespace OpenTK.Platform.X11
|
|||
return XISelectEvents(dpy, win, ref mask, 1);
|
||||
}
|
||||
|
||||
[DllImport("libXi")]
|
||||
static extern Status XIGrabDevice(IntPtr display, int deviceid, Window grab_window, Time time,
|
||||
Cursor cursor, int grab_mode, int paired_device_mode, Bool owner_events, XIEventMask[] mask);
|
||||
|
||||
[DllImport("libXi")]
|
||||
static extern Status XIUngrabDevice(IntPtr display, int deviceid, Time time);
|
||||
|
||||
static readonly IntPtr CopyFromParent = IntPtr.Zero;
|
||||
|
||||
public static void SendNetWMMessage(X11WindowInfo window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2)
|
||||
|
|
|
@ -80,14 +80,14 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
||||
{
|
||||
return new X11Keyboard(null);
|
||||
return new X11Keyboard();
|
||||
}
|
||||
|
||||
public virtual OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
||||
{
|
||||
if (XI2Mouse.IsSupported(IntPtr.Zero))
|
||||
return new XI2Mouse(null); // Requires xorg 1.7 or higher.
|
||||
else
|
||||
//if (XI2Mouse.IsSupported(IntPtr.Zero))
|
||||
// return new XI2Mouse(null); // Requires xorg 1.7 or higher.
|
||||
//else
|
||||
return new X11Mouse(null); // Always supported.
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
|
@ -35,35 +36,14 @@ namespace OpenTK.Platform.X11
|
|||
// Only one keyboard supported.
|
||||
sealed class X11Keyboard : IKeyboardDriver2
|
||||
{
|
||||
readonly X11WindowInfo window;
|
||||
readonly X11KeyMap keymap = new X11KeyMap();
|
||||
readonly static X11KeyMap keymap = new X11KeyMap();
|
||||
readonly static string name = "Core X11 keyboard";
|
||||
KeyboardState state = new KeyboardState();
|
||||
|
||||
readonly byte[] keys = new byte[32];
|
||||
|
||||
// Can either attach itself to the specified window or can hook the root window.
|
||||
public X11Keyboard(X11WindowInfo win)
|
||||
public X11Keyboard()
|
||||
{
|
||||
if (win != null)
|
||||
{
|
||||
window = win;
|
||||
}
|
||||
else
|
||||
{
|
||||
using (new XLock(API.DefaultDisplay))
|
||||
{
|
||||
window = new X11WindowInfo();
|
||||
window.Display = API.DefaultDisplay;
|
||||
window.Screen = Functions.XDefaultScreen(window.Display);
|
||||
window.RootWindow = Functions.XRootWindow(window.Display, window.Screen);
|
||||
window.WindowHandle = window.RootWindow;
|
||||
window.EventMask =EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.KeymapStateMask;
|
||||
|
||||
Functions.XGrabKeyboard(window.Display, window.RootWindow, true,
|
||||
GrabMode.GrabModeAsync, GrabMode.GrabModeAsync, IntPtr.Zero);
|
||||
Functions.XSelectInput(window.Display, window.RootWindow, new IntPtr((int)window.EventMask));
|
||||
}
|
||||
}
|
||||
Debug.WriteLine("Using X11Keyboard.");
|
||||
}
|
||||
|
||||
public KeyboardState GetState()
|
||||
|
@ -92,48 +72,24 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
void ProcessEvents()
|
||||
{
|
||||
XEvent e = new XEvent();
|
||||
|
||||
while (true)
|
||||
IntPtr display = API.DefaultDisplay;
|
||||
using (new XLock(display))
|
||||
{
|
||||
using (new XLock(window.Display))
|
||||
Functions.XQueryKeymap(display, keys);
|
||||
for (int keycode = 8; keycode < 256; keycode++)
|
||||
{
|
||||
if (!Functions.XCheckWindowEvent(window.Display, window.WindowHandle, window.EventMask, ref e))
|
||||
break;
|
||||
IntPtr keysym = Functions.XKeycodeToKeysym(display, (byte)keycode, 0);
|
||||
IntPtr keysym2 = Functions.XKeycodeToKeysym(display, (byte)keycode, 1);
|
||||
bool pressed = (keys[keycode >> 3] >> (keycode & 0x07) & 0x01) != 0;
|
||||
|
||||
switch (e.type)
|
||||
Key key;
|
||||
if (keymap.TryGetValue((XKey)keysym, out key) ||
|
||||
keymap.TryGetValue((XKey)keysym2, out key))
|
||||
{
|
||||
case XEventName.KeyPress:
|
||||
case XEventName.KeyRelease:
|
||||
bool pressed = e.type == XEventName.KeyPress;
|
||||
|
||||
IntPtr keysym = API.LookupKeysym(ref e.KeyEvent, 0);
|
||||
IntPtr keysym2 = API.LookupKeysym(ref e.KeyEvent, 1);
|
||||
|
||||
if (keymap.ContainsKey((XKey)keysym))
|
||||
{
|
||||
if (pressed)
|
||||
state.EnableBit((int)keymap[(XKey)keysym]);
|
||||
else
|
||||
state.DisableBit((int)keymap[(XKey)keysym]);
|
||||
}
|
||||
else if (keymap.ContainsKey((XKey)keysym2))
|
||||
{
|
||||
if (pressed)
|
||||
state.EnableBit((int)keymap[(XKey)keysym2]);
|
||||
else
|
||||
state.DisableBit((int)keymap[(XKey)keysym2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.Print("KeyCode {0} (Keysym: {1}, {2}) not mapped.",
|
||||
e.KeyEvent.keycode, (XKey)keysym, (XKey)keysym2);
|
||||
}
|
||||
break;
|
||||
|
||||
case XEventName.KeymapNotify:
|
||||
System.Diagnostics.Debug.Print("Keymap event: {0}", e.KeymapEvent.key_vector0);
|
||||
break;
|
||||
if (pressed)
|
||||
state.EnableBit((int)key);
|
||||
else
|
||||
state.DisableBit((int)key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue