Skip to content

Commit

Permalink
* XplatUIX11.cs: Enable key auto repeat. If the user doesn't
Browse files Browse the repository at this point in the history
        * have
        XKB or key auto repeat, do it manually.  Without key auto
repeat,
        when a key is held down we get key press, key release, key
press,
        key release, ... with auto repeat we get key press, key press,
key
        press ..., and then a release when the key is actually released.



svn path=/trunk/mcs/; revision=62250
  • Loading branch information
Jackson Harper committed Jul 4, 2006
1 parent cb12001 commit c0fe875
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
@@ -1,3 +1,11 @@
2006-07-04 Jackson Harper <jackson@ximian.com>

* XplatUIX11.cs: Enable key auto repeat. If the user doesn't have
XKB or key auto repeat, do it manually. Without key auto repeat,
when a key is held down we get key press, key release, key press,
key release, ... with auto repeat we get key press, key press, key
press ..., and then a release when the key is actually released.

2006-07-03 Jackson Harper <jackson@ximian.com>

* TabControl.cs:
Expand Down
33 changes: 31 additions & 2 deletions mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs
Expand Up @@ -106,7 +106,7 @@ internal class XplatUIX11 : XplatUIDriver {
private static Socket wake; //
private static Socket wake_receive; //
private static byte[] network_buffer; //

private static bool detectable_key_auto_repeat;

// Focus tracking
private static IntPtr ActiveWindow; // Handle of the active window
Expand Down Expand Up @@ -181,6 +181,16 @@ internal class XplatUIX11 : XplatUIDriver {
SetDisplay(XOpenDisplay(IntPtr.Zero));
X11DesktopColors.Initialize();


// Disable keyboard autorepeat
try {
XkbSetDetectableAutoRepeat (DisplayHandle, true, IntPtr.Zero);
detectable_key_auto_repeat = true;
} catch {
Console.Error.WriteLine ("Could not disable keyboard auto repeat, will attempt to disable manually.");
detectable_key_auto_repeat = false;
}

// Handle any upcoming errors; we re-set it here, X11DesktopColor stuff might have stolen it (gtk does)
ErrorHandler = new XErrorHandler(HandleError);
XSetErrorHandler(ErrorHandler);
Expand Down Expand Up @@ -1344,8 +1354,21 @@ internal class XException : ApplicationException {
break;
}

case XEventName.KeyRelease:
if (!detectable_key_auto_repeat && XPending (DisplayHandle) != 0) {
XEvent nextevent = new XEvent ();

XPeekEvent (DisplayHandle, ref nextevent);

if (nextevent.type == XEventName.KeyPress &&
nextevent.KeyEvent.keycode == xevent.KeyEvent.keycode &&
nextevent.KeyEvent.time == xevent.KeyEvent.time) {
continue;
}
}
goto case XEventName.KeyPress;

case XEventName.KeyPress:
case XEventName.KeyRelease:
case XEventName.ButtonPress:
case XEventName.ButtonRelease:
case XEventName.MotionNotify:
Expand Down Expand Up @@ -4872,6 +4895,12 @@ internal override void SetAllowDrop (IntPtr handle, bool value)

[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);
#endregion
}
}

0 comments on commit c0fe875

Please sign in to comment.