[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: Qemu does not pass pressed caps lock to client

From: Paolo Bonzini
Subject: [Qemu-devel] Re: Qemu does not pass pressed caps lock to client
Date: Fri, 12 Feb 2010 13:39:32 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100120 Fedora/3.0.1-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.1

On 02/12/2010 12:09 PM, Shahar Havivi wrote:
It's not true that SDL is not sending up event like the comment say,

On Fedora 12 it behave like a toggle button, first press/release will send
caps-down event second press/release send caps-up event
On Ubuntu 9.10 it work like any other key, i.e. pressing caps will generate two
events down and up.

True. To see why, start at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=317010 and http://archive.ubuntu.com/ubuntu/pool/main/libs/libsdl1.2/libsdl1.2_1.2.13-4ubuntu4.diff.gz -- it's a nice code reading exercise, so I'll suggest a possible solution before pointing out the reason for this behavior. The solution would be to put hack after hack, i.e. something like this (untested):

    case 0x3a: /* caps lock */
        /* SDL will usually send only 2 events instead of 4, so we
           generate the missing ones.  However, on Debian/Ubuntu
           systems it may generate 4; in this case we have to discard
           the extra events.  On Debian/Ubuntu ev->key.keysym.mod
           will always be zero, but for other systems we need the
           complicated condition below.  */
        if ((ev->key.keysym.mod & KMOD_CAPS) ==
            (ev->type == SDL_KEYDOWN ? KMOD_CAPS : 0)) {
            kbd_put_keycode(keycode | 0x80);
    case 0x45: /* num lock */
        /* Same as above.  */
        if ((ev->key.keysym.mod & KMOD_NUM) ==
            (ev->type == SDL_KEYDOWN ? KMOD_NUM : 0)) {
            kbd_put_keycode(keycode | 0x80);

Now, the solution of the riddle.  The patch was correctly submitted as

+       SDL_UseLockKeys = getenv ("SDL_DISABLE_LOCK_KEYS") == NULL;


+       use_lock_keys = SDL_UseLockKeys;


+                               if (!use_lock_keys)
+                                       break;

(i.e. by default do not change anything) but the maintainer apparently morphed it into

+       SDL_UseLockKeys = getenv("SDL_DISABLE_LOCK_KEYS");


+       use_lock_keys = ( SDL_UseLockKeys && *SDL_UseLockKeys );


+                               if ( ! use_lock_keys )
+                                       break;

which changed the default and the meaning of SDL_DISABLE_LOCK_KEYS.

I initially thought about removing the caps lock/num lock hack altogether and add the following, however it would need SDL 1.2.14 because SDL_NO_LOCK_KEYS support was added exactly two months after 1.2.13 was released. :-( :-(

    /* There are two versions around of a Debian patch that changes the
       way Caps Lock and Num Lock are handled.  The first version
       by default sends only one of the KeyDown/KeyUp events, unless
       SDL_DISABLE_LOCK_KEYS is present in the environment.  The second
       version instead by default sends both events, unless
       SDL_DISABLE_LOCK_KEYS is present and not empty.  This version
       is the most commonly found (and a totally braindead idea).

       Upstream instead supports SDL_NO_LOCK_KEYS which, if set to 1,
       will generate all four events---which is what we want.  Luckily,
       there is a combination of environment variable that will satisfy
       all variant.  */

    putenv ("SDL_DISABLE_LOCK_KEYS", "");
    putenv ("SDL_NO_LOCK_KEYS", "1");

Yes, I love Debian.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]