Permalink
Browse files

[X11] Use XKB for layout-independent input

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 7cce215a4b05340847a951aa4a3497bd2d15ec71
@@ -439,9 +439,6 @@ public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, Even
[DllImport("libX11", EntryPoint = "XFilterEvent")]
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);
@@ -945,7 +945,7 @@ internal struct XColor
public byte pad;
}
- internal enum Atom
+ internal enum AtomName
{
AnyPropertyType = 0,
XA_PRIMARY = 1,
@@ -55,7 +55,8 @@ internal sealed class X11GLNative : NativeWindowBase
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.
// Not used right now (the code is written, but is not 64bit-correct), but could be useful for older WMs which
@@ -231,12 +232,18 @@ internal sealed class X11GLNative : NativeWindowBase
Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
Debug.Unindent();
- // Request that auto-repeat is only set on devices that support it physically.
- // 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
- // be reset before the program exits.
- bool supported;
- Functions.XkbSetDetectableAutoRepeat(window.Display, true, out supported);
+ using (new XLock(window.Display))
+ {
+ // Request that auto-repeat is only set on devices that support it physically.
+ // 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
+ // 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.
// Check whether it is available.
@@ -271,6 +278,7 @@ public X11GLNative()
{
window.Screen = Functions.XDefaultScreen(window.Display); //API.DefaultScreen;
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,
@@ -677,7 +685,7 @@ bool RefreshWindowBorders()
{
Functions.XGetWindowProperty(window.Display, window.Handle,
_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))
@@ -870,7 +878,7 @@ public override void ProcessEvents()
case XEventName.KeyRelease:
bool pressed = e.type == XEventName.KeyPress;
Key key;
- if (X11KeyMap.TranslateKey(ref e.KeyEvent, out key))
+ if (KeyMap.TranslateKey(ref e.KeyEvent, out key))
{
if (pressed)
{
@@ -1005,6 +1013,7 @@ public override void ProcessEvents()
{
Debug.Print("keybard mapping refreshed");
Functions.XRefreshKeyboardMapping(ref e.MappingEvent);
+ KeyMap.RefreshKeycodes(window.Display);
}
break;
@@ -1738,7 +1747,6 @@ protected override void Dispose(bool manuallyCalled)
}
window.Dispose();
- window = null;
}
}
else
Oops, something went wrong.

0 comments on commit 7cce215

Please sign in to comment.