[Spice-commits] gtk/spice-widget.c

Marc-André Lureau elmarco at kemper.freedesktop.org
Mon Nov 19 08:55:52 PST 2012

 gtk/spice-widget.c |    6 ++++++
 1 file changed, 6 insertions(+)

New commits:
commit 2300bfe1b69efcc44ba46e85a844e56ed567e6bb
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Oct 30 11:44:00 2012 +0100

    win32: translate virtual-key code to scancode via MapVirtualKey
    Local client keyboard layout shouldn't affect hardware scancode sent
    to guest, so that guest keyboard layout configuration can map it
    Unfortunately, the Win32 GdkEventKey.hardware_keycode isn't a hardware
    scancode, but the Windows virtual-key code. We could modify Gdk to
    return the scancode (available in MSG.lParam or via global hook), but
    that would mean some Gdk breakage, or some unnecessary complexity.
    Instead, we can rely on MapVirtualKey(), which translates the
    vitual-key code into a scan code using current keyboard layout.
    This solves the following bug:

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index c61a0c5..1282062 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -1240,6 +1240,12 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
     scancode = vnc_display_keymap_gdk2xtkbd(d->keycode_map, d->keycode_maplen,
+#ifdef WIN32
+    /* MapVirtualKey doesn't return scancode with needed higher byte */
+    scancode = MapVirtualKey(key->hardware_keycode, MAPVK_VK_TO_VSC) |
+        (scancode & 0xff00);
     switch (key->type) {
     case GDK_KEY_PRESS:
         send_key(display, scancode, SEND_KEY_PRESS, !key->is_modifier);

More information about the Spice-commits mailing list