Re: [spice-gtk v2] widget: Do not ignore unsupported keys from keyboard

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

 



Hi,

On Thu, Jun 09, 2016 at 10:18:32AM +0100, Frediano Ziglio wrote:
> If Windows layout does not support a given key the resulting virtual code
> is set to 0xFF. To avoid losing this raw key (causing the key not been
> sent to remote machine) detect this condition and handle the key.
> The check for raw scancode is there to understand if we can handle
> correctly the key in following code.
> This problem can happen for instance using a 106 key Japanese keyboard
> while the layout is set in English; in this case keys like CONVERT not
> forwarded correctly.
> 
> Some note on how to reproduce and test this problem.
> 
> Physical way:
> 1- get a 106 key Japanese keyboard for your Windows client machine;
> 2- setup your client to English keyboard layout;
> 3- connect to a Linux machine (no matter the distro or version or
>    keyboard configuration);
> 4- open "xinput test-xi2 <device>" command on Linux (device is
>    the "AT" device in this case);
> 5- press CONVERT or other keys not present on an English keyboard.
> 
> Virtual way (Windows machine on a VM):
> - set machine remote to VNC;
> - assure Qmeu has lock-key-sync=off option to vnc;
> - connect to Windows machine with a VNC client (I suggest TigerVNC
>   as remote-viewer do some keyboard insertion);
> - do steps 2, 3, 4 above
> - press the CONVERT key. If you don't have you can simulate, either
>   - change VNC client code to insert scancode 0x70 instead of another
>     key and press this key;
>   - disconnect main VNC client and use some tool to inject keys
>     (I use a modifier version of vncdotool).
> 
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> ---
>  src/spice-widget.c | 38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/src/spice-widget.c b/src/spice-widget.c
> index 51a2055..b5936bc 100644
> --- a/src/spice-widget.c
> +++ b/src/spice-widget.c
> @@ -1406,7 +1406,7 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
>  {
>      SpiceDisplay *display = SPICE_DISPLAY(widget);
>      SpiceDisplayPrivate *d = display->priv;
> -    int scancode;
> +    int scancode = 0;
>  #ifdef G_OS_WIN32
>      int native_scancode;
>      WORD langid = LOWORD(GetKeyboardLayout(0));
> @@ -1414,8 +1414,23 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
>  #endif
>  
>  #ifdef G_OS_WIN32
> +    /* Try to get scancode with gdk_event_get_scancode.
> +     * This API is available from 3.22 or if backported.
> +     */
> +#if HAVE_GDK_EVENT_GET_SCANCODE
> +    native_scancode = gdk_event_get_scancode((GdkEvent *) key);
> +    if (native_scancode) {
> +        scancode = native_scancode & 0x1ff;
> +        /* Windows always set extended attribute for these keys */
> +        if (scancode == (0x100|DIK_NUMLOCK) || scancode == (0x100|DIK_RSHIFT))
> +            scancode &= 0xff;
> +    }
> +#else
> +    native_scancode = 0;
> +#endif
> +
>      /* on windows, we ought to ignore the reserved key event? */
> -    if (key->hardware_keycode == 0xff)
> +    if (!native_scancode && key->hardware_keycode == 0xff)
>          return false;
>  
>      if (!d->keyboard_grab_active) {
> @@ -1455,23 +1470,10 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
>      if (!d->inputs)
>          return true;
>  
> -    scancode = vnc_display_keymap_gdk2xtkbd(d->keycode_map, d->keycode_maplen,
> -                                            key->hardware_keycode);
> +    if (!scancode)
> +        scancode = vnc_display_keymap_gdk2xtkbd(d->keycode_map, d->keycode_maplen,
> +                                                key->hardware_keycode);

I think at this point, the if (!scancode) condition is the same as the
if (!native_scancode) condition below (as we unconditionnally set
scancode when native_scancode is not 0 in a hunk above that one)...

>  #ifdef G_OS_WIN32
> -    /* Try to get scancode with gdk_event_get_scancode.
> -     * This API is available from 3.22 or if backported.
> -     */
> -#if HAVE_GDK_EVENT_GET_SCANCODE
> -    native_scancode = gdk_event_get_scancode((GdkEvent *) key);
> -    if (native_scancode) {
> -        scancode = native_scancode & 0x1ff;
> -        /* Windows always set extended attribute for these keys */
> -        if (scancode == (0x100|DIK_NUMLOCK) || scancode == (0x100|DIK_RSHIFT))
> -            scancode &= 0xff;
> -    }
> -#else
> -    native_scancode = 0;
> -#endif
>      if (!native_scancode) {

... so scancode = vnc_display_keymap_gdk2xtkbd(d->keycode_map, d->keycode_maplen, key->hardware_keycode);
can just go there rather than in an additional block.

Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>

Christophe

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]