Skip to content

Commit

Permalink
[X11] Use XKB for layout-independent input
Browse files Browse the repository at this point in the history
The code will fall back to core X11 if XKB is not available.
  • Loading branch information
thefiddler committed May 14, 2014
1 parent e8176ef commit 7cce215
Show file tree
Hide file tree
Showing 5 changed files with 346 additions and 44 deletions.
3 changes: 0 additions & 3 deletions Source/OpenTK/Platform/X11/Functions.cs
Expand Up @@ -439,9 +439,6 @@ public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, Even
[DllImport("libX11", EntryPoint = "XFilterEvent")] [DllImport("libX11", EntryPoint = "XFilterEvent")]
public extern static bool XFilterEvent(ref XEvent xevent, IntPtr window); 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")] [DllImport("libX11")]
public extern static void XPeekEvent(IntPtr display, ref XEvent xevent); public extern static void XPeekEvent(IntPtr display, ref XEvent xevent);


Expand Down
2 changes: 1 addition & 1 deletion Source/OpenTK/Platform/X11/Structs.cs
Expand Up @@ -945,7 +945,7 @@ internal struct XColor
public byte pad; public byte pad;
} }


internal enum Atom internal enum AtomName
{ {
AnyPropertyType = 0, AnyPropertyType = 0,
XA_PRIMARY = 1, XA_PRIMARY = 1,
Expand Down
28 changes: 18 additions & 10 deletions Source/OpenTK/Platform/X11/X11GLNative.cs
Expand Up @@ -55,7 +55,8 @@ internal sealed class X11GLNative : NativeWindowBase


const int _min_width = 30, _min_height = 30; const int _min_width = 30, _min_height = 30;


X11WindowInfo window = new X11WindowInfo(); readonly X11WindowInfo window = new X11WindowInfo();
readonly X11KeyMap KeyMap;


// Window manager hints for fullscreen windows. // Window manager hints for fullscreen windows.
// Not used right now (the code is written, but is not 64bit-correct), but could be useful for older WMs which // Not used right now (the code is written, but is not 64bit-correct), but could be useful for older WMs which
Expand Down Expand Up @@ -231,12 +232,18 @@ internal sealed class X11GLNative : NativeWindowBase
Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle)); Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
Debug.Unindent(); Debug.Unindent();


// Request that auto-repeat is only set on devices that support it physically. using (new XLock(window.Display))
// This typically means that it's turned off for keyboards (which is what we want). {
// We prefer this method over XAutoRepeatOff/On, because the latter needs to // Request that auto-repeat is only set on devices that support it physically.
// be reset before the program exits. // This typically means that it's turned off for keyboards (which is what we want).
bool supported; // We prefer this method over XAutoRepeatOff/On, because the latter needs to
Functions.XkbSetDetectableAutoRepeat(window.Display, true, out supported); // be reset before the program exits.
if (Xkb.IsSupported(window.Display))
{
bool supported;
Xkb.SetDetectableAutoRepeat(window.Display, true, out supported);
}
}


// The XInput2 extension makes keyboard and mouse handling much easier. // The XInput2 extension makes keyboard and mouse handling much easier.
// Check whether it is available. // Check whether it is available.
Expand Down Expand Up @@ -271,6 +278,7 @@ public X11GLNative()
{ {
window.Screen = Functions.XDefaultScreen(window.Display); //API.DefaultScreen; window.Screen = Functions.XDefaultScreen(window.Display); //API.DefaultScreen;
window.RootWindow = Functions.XRootWindow(window.Display, window.Screen); // API.RootWindow; window.RootWindow = Functions.XRootWindow(window.Display, window.Screen); // API.RootWindow;
KeyMap = new X11KeyMap(window.Display);
} }


Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen,
Expand Down Expand Up @@ -677,7 +685,7 @@ bool RefreshWindowBorders()
{ {
Functions.XGetWindowProperty(window.Display, window.Handle, Functions.XGetWindowProperty(window.Display, window.Handle,
_atom_net_frame_extents, IntPtr.Zero, new IntPtr(16), false, _atom_net_frame_extents, IntPtr.Zero, new IntPtr(16), false,
(IntPtr)Atom.XA_CARDINAL, out atom, out format, out nitems, out bytes_after, ref prop); (IntPtr)AtomName.XA_CARDINAL, out atom, out format, out nitems, out bytes_after, ref prop);
} }


if ((prop != IntPtr.Zero)) if ((prop != IntPtr.Zero))
Expand Down Expand Up @@ -870,7 +878,7 @@ public override void ProcessEvents()
case XEventName.KeyRelease: case XEventName.KeyRelease:
bool pressed = e.type == XEventName.KeyPress; bool pressed = e.type == XEventName.KeyPress;
Key key; Key key;
if (X11KeyMap.TranslateKey(ref e.KeyEvent, out key)) if (KeyMap.TranslateKey(ref e.KeyEvent, out key))
{ {
if (pressed) if (pressed)
{ {
Expand Down Expand Up @@ -1005,6 +1013,7 @@ public override void ProcessEvents()
{ {
Debug.Print("keybard mapping refreshed"); Debug.Print("keybard mapping refreshed");
Functions.XRefreshKeyboardMapping(ref e.MappingEvent); Functions.XRefreshKeyboardMapping(ref e.MappingEvent);
KeyMap.RefreshKeycodes(window.Display);
} }
break; break;


Expand Down Expand Up @@ -1738,7 +1747,6 @@ protected override void Dispose(bool manuallyCalled)
} }


window.Dispose(); window.Dispose();
window = null;
} }
} }
else else
Expand Down

0 comments on commit 7cce215

Please sign in to comment.