From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nfuo9-0001Et-Mt for qemu-devel@nongnu.org; Fri, 12 Feb 2010 07:39:41 -0500 Received: from [199.232.76.173] (port=49385 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nfuo9-0001Eg-Dz for qemu-devel@nongnu.org; Fri, 12 Feb 2010 07:39:41 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nfuo8-0000L9-DV for qemu-devel@nongnu.org; Fri, 12 Feb 2010 07:39:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22236) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nfuo7-0000Kx-TM for qemu-devel@nongnu.org; Fri, 12 Feb 2010 07:39:40 -0500 Message-ID: <4B754C04.4080907@redhat.com> Date: Fri, 12 Feb 2010 13:39:32 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <4B752548.1040108@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: Qemu does not pass pressed caps lock to client List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, shaharh@gmail.com, kwolf@redhat.com 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); kbd_put_keycode(keycode | 0x80); } return; 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); kbd_put_keycode(keycode | 0x80); } return; 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. Paolo