ArchiveOrangemail archive

X.Org user support and discussion


xorg.lists.freedesktop.org
(List home) (Recent threads) (87 other Freedesktop.org lists)

Subscription Options

  • RSS or Atom: Read-only subscription using a browser or aggregator. This is the recommended way if you don't need to send messages to the list. You can learn more about feed syndication and clients here.
  • Conventional: All messages are delivered to your mail address, and you can reply. To subscribe, send an email to the list's subscribe address with "subscribe" in the subject line, or visit the list's homepage here.
  • This list contains about 53,515 messages, beginning Dec 2003
  • This list doesn't seem to be active
Report the Spam
This button sends a spam report to the moderator. Please use it sparingly. For other removal requests, read this.
Are you sure? yes no

Key continue repeating if setting global autorepeat off while the key was already repeating.

Ad
Octavio Alvarez 1258950713Mon, 23 Nov 2009 04:31:53 +0000 (UTC)
Hi.

If I turn global autorepeat off while a key is already being repeated,
the key doesn't stop repeating. It continues on and on.

I have prepared the following code for demonstrating the issue: reptest.c

After the code, I quote 5 results from tests by running this code. The
tests involve pressing a combination of a hotkey (in this code, Super_L)
and the letter "k" in different combinations and timing.

Tests A and B are OK, but tests C and D are not.

Tests A, B, C, and D are under plain X11: startx `which xterm` -- :1

I'm running X.org version 1.6.5 under Debian Sid. I think (but not sure)
I'm using the evdev driver.

A friend tried test D for me under 1.7.1.901 and happens too.

I tried putting a lot of XFlush(dpy) all over the place, but it still
happens.

evtest and showkey output look pretty normal to me, but I can attach a
sample if needed.

This problem happens also under Ubuntu Jaunty box (X 7.4, 1.6.0) but
I remember previous distros not failing. Say Ubuntu Hardy or Gutsy and
before.

Is it a bug, or am I missing something? Thanks.

/*
    * reptest.c: extract from Superkb to test autorepeat misbehavior.
    *
    * Copyright (C) 2005-2009, Octavio Alvarez Piza.
    * License: GNU General Public License v2.
    *
    * Compile with: gcc -Wall -std=gnu99 -pedantic -lX11 -o reptest  
reptest.c
    */

#include <X11/Xlib.h>

#include <errno.h>
#include <stdio.h>
#include <stdarg.h>

int main()
{

      /* X11 connection setup */
      Display *dpy;
      dpy = XOpenDisplay(NULL);

      /* Get code for "Super_L", as a sample hotkey. */
      KeyCode hotkey;
      hotkey = XKeysymToKeycode(dpy, XStringToKeysym("Super_L"));

      Window rootwin;
      rootwin = DefaultRootWindow(dpy);

      /* Grab the hotkey */
      XGrabKey(dpy, hotkey, AnyModifier, rootwin, True,
         GrabModeAsync, GrabModeAsync);

      XKeyboardState xkbs;

      /* Save hotkey autorepeat state */
      int saved_hotkey_autorepeat_mode;
      XGetKeyboardControl(dpy, &xkbs);
      saved_hotkey_autorepeat_mode = (xkbs.auto_repeats[(int) hotkey/8] &
         hotkey % 8) > 0;

      /* Turn autorepeat off for the hotkey */
      XKeyboardControl xkbc;
      xkbc.key = hotkey;
      xkbc.auto_repeat_mode = AutoRepeatModeOff;
      XChangeKeyboardControl(dpy, KBAutoRepeatMode | KBKey, &xkbc);

      /* This variable holds the autorepeat state for the whole keyboard
         while the hotkey is NOT pressed. */
      int saved_autorepeat_mode = 0;

      while (1) {

         XEvent ev;

         XNextEvent(dpy, &ev);

         if (ev.xkey.keycode == hotkey && ev.type == KeyPress) {

            printf("[sk] Hotkey has been pressed, code: %d, name: %s.\n",
               ev.xkey.keycode,
               XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0)));

            XKeyboardState xkbs;

            /* Save autorepeat current state state, in order to restore it
               after hotkey is released. Autorepeat will be turned off
               in the meanwhile. */
            XGetKeyboardControl(dpy, &xkbs);
            saved_autorepeat_mode = xkbs.global_auto_repeat;

            printf("[ar] AutoRepeat state has been saved: %d.\n",
               saved_autorepeat_mode);

            /* Turn autorepeat off. */
            XKeyboardControl xkbc;
            xkbc.auto_repeat_mode = AutoRepeatModeOff;
            XChangeKeyboardControl(dpy, KBAutoRepeatMode, &xkbc);

            printf("[ar] AutoRepeat state has been turned off.\n");

            /* Starting the "active mechanism" by grabbing the kb. */
            XGrabKeyboard(dpy, rootwin, False, GrabModeAsync,
               GrabModeAsync, CurrentTime);

         } else if (ev.xkey.keycode == hotkey && ev.type == KeyRelease) {

            printf("[sk] Hotkey has been released, code: %d, name: %s.\n",
               ev.xkey.keycode,
               XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0)));

            /* Restore saved_autorepeat_mode. */
            XKeyboardControl xkbc;
            xkbc.auto_repeat_mode = saved_autorepeat_mode;
            XChangeKeyboardControl(dpy, KBAutoRepeatMode, &xkbc);

            printf("[ar] AutoRepeat has been restored to: %d\n",
               saved_autorepeat_mode);

            /* End the "active state" by ungrabbing the keyboard. */
            XUngrabKeyboard(dpy, CurrentTime);

            printf("---------------------------------------------\n");

         } else if (ev.type == KeyRelease) {
            /* Released any other key. */
            printf("[ac] Due to bound key release, executed action for"
               " key code = %d, name: %s\n", ev.xkey.keycode,
               XKeysymToString(XKeycodeToKeysym(dpy, ev.xkey.keycode, 0)));
         }

      }
}




[Sun Nov 22 16:48:20 -0800 -- alvarezp@octavio:~/temp/xorg-repeat-test]
$ ./reptest

=== TEST A: HOLD HOTKEY, HIT K, RELEASE HOTKEY ==
[sk] Hotkey has been pressed, code: 133, name: Super_L.
[ar] AutoRepeat state has been saved: 1.
[ar] AutoRepeat state has been turned off.
[ac] Due to bound key release, executed action for key code = 45, name: k
[sk] Hotkey has been released, code: 133, name: Super_L.
[ar] AutoRepeat has been restored to: 1
---------------------------------------------

== TEST B: HOLD HOTKEY, HOLD K, RELEASE K, RELEASE HOTKEY ==
[sk] Hotkey has been pressed, code: 133, name: Super_L.
[ar] AutoRepeat state has been saved: 1.
[ar] AutoRepeat state has been turned off.
[ac] Due to bound key release, executed action for key code = 45, name: k
[sk] Hotkey has been released, code: 133, name: Super_L.
[ar] AutoRepeat has been restored to: 1
---------------------------------------------

== TEST C: HOLD K, LET AUTOREPEAT, HOLD HOTKEY, RELEASE HOTKEY,
==         RELEASE K ==
kkkkkkkkkkkkkkkk[sk] Hotkey has been pressed, code: 133, name: Super_L.
[ar] AutoRepeat state has been saved: 1.
[ar] AutoRepeat state has been turned off.
        [ == AUTOREPEAT IS OFF NOW. REPETITIONS SHOULDN'T HAVE HAPPENED == ]
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[sk] Hotkey has been released, code: 133, name: Super_L.
[ar] AutoRepeat has been restored to: 1
---------------------------------------------
kkkkkkkkkkkkkkk [ == K RELEASED == ]


== TEST D: HOLD K, LET AUTOREPEAT, HOLD HOTKEY, RELEASE K,
==         RELEASE HOTKEY, LET RUN AND HIT K AGAIN TO FIX (UNDER PLAIN
==         X11) ==
kkkkkkkkkkkk[sk] Hotkey has been pressed, code: 133, name: Super_L.
[ar] AutoRepeat state has been saved: 1.
[ar] AutoRepeat state has been turned off.
        [ == AUTOREPEAT IS OFF NOW. REPETITIONS SHOULDN'T HAVE HAPPENED == ]
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
[ac] Due to bound key release, executed action for key code = 45, name: k
        [ == K RELEASED == ]
        [ == HOTKEY RELEASED == ]
[sk] Hotkey has been released, code: 133, name: Super_L.
[ar] AutoRepeat has been restored to: 1
Daniel Stone 1274167687Tue, 18 May 2010 07:28:07 +0000 (UTC)
On Sun, Nov 22, 2009 at 08:27:47PM -0800, Octavio Alvarez wrote: > If I turn global autorepeat off while a key is already being repeated, > the key doesn't stop repeating. It continues on and on.
At least according to XKB, I believe that's correct; almost all XKB actions are specified to not affect any keys currently down. Cheers, Daniel
Octavio Alvarez 1274307432Wed, 19 May 2010 22:17:12 +0000 (UTC)
On Tue, 18 May 2010 00:26:27 -0700, Daniel Stone wrote: > On Sun, Nov 22, 2009 at 08:27:47PM -0800, Octavio Alvarez wrote: >> If I turn global autorepeat off while a key is already being repeated, >> the key doesn't stop repeating. It continues on and on. > > At least according to XKB, I believe that's correct; almost all XKB > actions are specified to not affect any keys currently down.
I didn't find that in the XKB Library Reference. Also, does this apply to controls too? For test C (hold k, let repeat, hold Super, release Super, release k), it might make sense to say that the app should detect it somehow. However, for test D, I would call it a bug, because the sequence "hold k, let repeat, hold Super, release k, release Super" leaves the keyboard sending k press/releases to the input window without any key being physically down. Octavio.
Home | About | Privacy