Permalink
Browse files

Merge branch 'xkeyfix' of https://github.com/thefiddler/opentk into d…

…evelop
  • Loading branch information...
2 parents cfb2d45 + 4ede3ad commit ade8e6162547c169f02a048c290555c7252753c5 @thefiddler thefiddler committed May 19, 2014
@@ -697,7 +697,6 @@
<Compile Include="Platform\X11\X11Keyboard.cs" />
<Compile Include="Platform\X11\X11Mouse.cs" />
<Compile Include="Input\ButtonState.cs" />
- <Compile Include="Platform\X11\XI2Mouse.cs" />
<EmbeddedResource Include="OpenTK.dll.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
@@ -798,7 +797,11 @@
<Compile Include="Platform\MacOS\Quartz\CoreFoundation.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Platform\X11\Bindings\Xkb.cs" />
<Compile Include="Input\MouseScroll.cs" />
+ <Compile Include="Platform\X11\X11Input.cs" />
+ <Compile Include="Platform\X11\XI2Input.cs" />
+ <Compile Include="Platform\X11\XI2MouseKeyboard.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@@ -44,6 +44,9 @@ class XI
{
const string lib = "libXi";
+ internal const int XIAllDevices = 0;
+ internal const int XIAllMasterDevices = 1;
+
// mouse
internal static readonly IntPtr ButtonLeft = Functions.XInternAtom(API.DefaultDisplay, "Button Left", false);
internal static readonly IntPtr ButtonMiddle = Functions.XInternAtom(API.DefaultDisplay, "Button Middle", false);
@@ -124,4 +127,13 @@ public static int SelectEvents(IntPtr dpy, Window win, XIEventMask mask)
[DllImport(lib, EntryPoint = "XIQueryVersion")]
internal static extern Status QueryVersion(Display display, ref int major, ref int minor);
}
+
+ enum XIDeviceType
+ {
+ MasterPointer = 1,
+ MasterKeyboard = 2,
+ SlavePointer = 3,
+ SlaveKeyboard = 4,
+ FloatingSlave = 5,
+ }
}
@@ -0,0 +1,302 @@
+#region License
+//
+// Xkb.cs
+//
+// Author:
+// Stefanos Apostolopoulos <stapostol@gmail.com>
+//
+// Copyright (c) 2006-2014
+//
+// 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.
+//
+#endregion
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+namespace OpenTK.Platform.X11
+{
+ using Atom = IntPtr;
+ using KeyCode = Byte;
+ using XkbControlsPtr = IntPtr;
+ using XkbServerMapPtr = IntPtr;
+ using XkbClientMapPtr = IntPtr;
+ using XkbIndicatorPtr = IntPtr;
+ using XkbCompatMapPtr = IntPtr;
+ using XkbGeometryPtr = IntPtr;
+
+ class Xkb
+ {
+ const string lib = "libX11";
+
+ internal const int KeyNameLength = 4;
+ internal const int NumModifiers = 8;
+ internal const int NumVirtualMods = 16;
+ internal const int NumIndicators = 32;
+ internal const int NumKbdGroups = 4;
+ internal const int UseCoreKeyboard = 0x0100;
+
+ [DllImport(lib, EntryPoint = "XkbFreeKeyboard")]
+ unsafe internal extern static void FreeKeyboard(XkbDesc* descr, int which, bool free);
+
+ [DllImport(lib, EntryPoint = "XkbAllocKeyboard")]
+ unsafe internal extern static XkbDesc* AllocKeyboard(IntPtr display);
+
+ [DllImport(lib, EntryPoint = "XkbGetKeyboard")]
+ internal extern static IntPtr GetKeyboard(IntPtr display, XkbKeyboardMask which, int device_id);
+
+ [DllImport(lib, EntryPoint = "XkbGetMap")]
+ internal extern static IntPtr GetMap(IntPtr display, XkbKeyboardMask which, int device_spec);
+
+ [DllImport(lib, EntryPoint = "XkbGetNames")]
+ unsafe internal extern static IntPtr GetNames(IntPtr display, XkbNamesMask which, XkbDesc* xkb);
+
+ [DllImport(lib, EntryPoint = "XkbKeycodeToKeysym")]
+ internal extern static XKey KeycodeToKeysym(IntPtr display, int keycode, int group, int level);
+
+ [DllImport(lib, EntryPoint = "XkbQueryExtension")]
+ internal extern static bool QueryExtension(IntPtr display, out int opcode_rtrn, out int event_rtrn,
+ out int error_rtrn, ref int major_in_out, ref int minor_in_out);
+
+ [DllImport(lib, EntryPoint = "XkbSetDetectableAutoRepeat")]
+ internal extern static bool SetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported);
+
+ internal static bool IsSupported(IntPtr display)
+ {
+ // The XkbQueryExtension manpage says that we cannot
+ // use XQueryExtension with XKB.
+ int opcode, error, ev;
+ int major = 1;
+ int minor = 0;
+ bool supported = QueryExtension(display, out opcode, out ev, out error, ref major, ref minor);
+ Debug.Print("XKB extension is {0}.", supported ? "supported" : "not supported");
+ if (supported)
+ {
+ Debug.Print("XKB version is {0}.{1}", major, minor);
+ }
+ return supported;
+ }
+ }
+
+ [Flags]
+ enum XkbKeyboardMask
+ {
+ Controls = 1 << 0,
+ ServerMap = 1 << 1,
+ IClientMap = 1 << 2,
+ IndicatorMap = 1 << 3,
+ Names = 1 << 4,
+ CompatibilityMap = 1 << 5,
+ Geometry = 1 << 6,
+ AllComponents = 1 << 7,
+ }
+
+ [Flags]
+ enum XkbNamesMask
+ {
+ Keycodes = 1 << 0,
+ Geometry = 1 << 1,
+ Symbols = 1 << 2,
+ PhysSymbols = 1 << 3,
+ Types = 1 << 4,
+ Compat = 1 << 5,
+ KeyType = 1 << 6,
+ KTLevel = 1 << 7,
+ Indicator = 1 << 8,
+ Key = 1 << 9,
+ KeyAliasesMask = 1 << 10,
+ VirtualMod = 1 << 11,
+ Group = 1 << 12,
+ RG = 1 << 13,
+ Component = 0x3f,
+ All = 0x3fff
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ unsafe struct XkbDesc
+ {
+ internal IntPtr dpy;
+ internal ushort flags;
+ internal ushort device_spec;
+ internal KeyCode min_key_code;
+ internal KeyCode max_key_code;
+
+ internal XkbControlsPtr ctrls;
+ internal XkbServerMapPtr server;
+ internal XkbClientMapPtr map;
+ internal XkbIndicatorPtr indicators;
+ internal XkbNames* names;
+ internal XkbCompatMapPtr compat;
+ internal XkbGeometryPtr geom;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ unsafe struct XkbKeyAlias
+ {
+ internal fixed byte real[Xkb.KeyNameLength];
+ internal fixed byte alias[Xkb.KeyNameLength];
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ unsafe struct XkbKeyName
+ {
+ internal fixed byte name[Xkb.KeyNameLength];
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ unsafe struct XkbNames
+ {
+ #region Structs
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct Groups
+ {
+ Atom groups0;
+ Atom groups1;
+ Atom groups2;
+ Atom groups3;
+ internal Atom this[int i]
+ {
+ get
+ {
+ if (i < 0 || i > 3)
+ throw new IndexOutOfRangeException();
+
+ unsafe
+ {
+ fixed (Atom* ptr = &groups0)
+ {
+ return *(ptr + i);
+ }
+ }
+ }
+ }
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct Indicators
+ {
+ Atom indicators0;
+ Atom indicators1;
+ Atom indicators2;
+ Atom indicators3;
+ Atom indicators4;
+ Atom indicators5;
+ Atom indicators6;
+ Atom indicators7;
+ Atom indicators8;
+ Atom indicators9;
+ Atom indicators10;
+ Atom indicators11;
+ Atom indicators12;
+ Atom indicators13;
+ Atom indicators14;
+ Atom indicators15;
+ Atom indicators16;
+ Atom indicators17;
+ Atom indicators18;
+ Atom indicators19;
+ Atom indicators20;
+ Atom indicators21;
+ Atom indicators22;
+ Atom indicators23;
+ Atom indicators24;
+ Atom indicators25;
+ Atom indicators26;
+ Atom indicators27;
+ Atom indicators28;
+ Atom indicators29;
+ Atom indicators30;
+ Atom indicators31;
+ internal Atom this[int i]
+ {
+ get
+ {
+ if (i < 0 || i > 31)
+ throw new IndexOutOfRangeException();
+
+ unsafe
+ {
+ fixed (Atom* ptr = &indicators0)
+ {
+ return *(ptr + i);
+ } }
+ }
+ }
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct VMods
+ {
+ Atom vmods0;
+ Atom vmods1;
+ Atom vmods2;
+ Atom vmods3;
+ Atom vmods4;
+ Atom vmods5;
+ Atom vmods6;
+ Atom vmods7;
+ Atom vmods8;
+ Atom vmods9;
+ Atom vmods10;
+ Atom vmods11;
+ Atom vmods12;
+ Atom vmods13;
+ Atom vmods14;
+ Atom vmods15;
+ internal Atom this[int i]
+ {
+ get
+ {
+ if (i < 0 || i > 15)
+ throw new IndexOutOfRangeException();
+
+ unsafe
+ {
+ fixed (Atom* ptr = &vmods0)
+ {
+ return *(ptr + i);
+ }
+ }
+ }
+ }
+ }
+
+ #endregion
+
+ internal Atom keycodes;
+ internal Atom geometry;
+ internal Atom symbols;
+ internal Atom types;
+ internal Atom compat;
+ internal VMods vmods;
+ internal Indicators indicators;
+ internal Groups groups;
+ internal XkbKeyName* keys;
+ internal XkbKeyAlias* key_aliases;
+ internal Atom *radio_groups;
+ internal Atom phys_symbols;
+
+ internal byte num_keys;
+ internal byte num_key_aliases;
+ internal byte num_rg;
+ }
+}
+
@@ -440,9 +440,6 @@ public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, Even
public extern static bool XFilterEvent(ref XEvent xevent, IntPtr window);
[DllImport("libX11")]
- public extern static bool XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported);
-
- [DllImport("libX11")]
public extern static void XPeekEvent(IntPtr display, ref XEvent xevent);
[DllImport("libX11", EntryPoint = "XGetVisualInfo")]
@@ -945,7 +945,7 @@ internal struct XColor
public byte pad;
}
- internal enum Atom
+ internal enum AtomName
{
AnyPropertyType = 0,
XA_PRIMARY = 1,
@@ -1688,7 +1688,7 @@ struct XIDeviceInfo
{
public int deviceid;
public IntPtr name; // byte*
- public int use;
+ public XIDeviceType use;
public int attachment;
public Bool enabled;
public int num_classes;
Oops, something went wrong.

0 comments on commit ade8e61

Please sign in to comment.