On Mon, Apr 25, 2016 at 04:03:47PM +0100, Frediano Ziglio wrote: > This new Gdk API allows in Windows to retrieve the raw scancodes sent > by Windows. > This allows us to do some translations getting the right value without > many hacks and supporting all possible layouts. For future reference, can you add some examples of situations where we had issues with MapVirtualKey, and where having the raw scancode helps? > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > --- > configure.ac | 8 ++++++++ > src/spice-widget.c | 22 +++++++++++++++++++--- > 2 files changed, 27 insertions(+), 3 deletions(-) > > Changes from v1: > - added configure.ac code so use using Gdk from > master can use it. > > diff --git a/configure.ac b/configure.ac > index ce80d88..ab7385f 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -142,6 +142,14 @@ AC_SUBST(GTK_CFLAGS) > AC_SUBST(GTK_LIBS) > SPICE_GTK_REQUIRES="${SPICE_GTK_REQUIRES} gtk+-3.0 >= $GTK_REQUIRED" > > +old_LIBS="$LIBS" > +old_CFLAGS="$CFLAGS" > +CFLAGS="$CFLAGS $GTK_CFLAGS" > +LIBS="$LIBS $GTK_LIBS" > +AC_CHECK_FUNCS(gdk_event_get_scancode) > +LIBS="$old_LIBS" > +CFLAGS="$old_CFLAGS" > + > PKG_CHECK_EXISTS([gtk+-quartz-$with_gtk], [have_quartz=yes], [have_quartz=no]) > AS_IF([test "x$have_quartz" = "xyes"], [AC_DEFINE([HAVE_QUARTZ], 1, [Have Quartz?])]) > AM_CONDITIONAL([WITH_DISPLAY_QUARTZ], [test "x$have_quartz" = "xyes"]) > diff --git a/src/spice-widget.c b/src/spice-widget.c > index b458909..d666642 100644 > --- a/src/spice-widget.c > +++ b/src/spice-widget.c > @@ -1455,9 +1455,25 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key) > scancode = vnc_display_keymap_gdk2xtkbd(d->keycode_map, d->keycode_maplen, > key->hardware_keycode); > #ifdef G_OS_WIN32 > - native_scancode = MapVirtualKey(key->hardware_keycode, MAPVK_VK_TO_VSC); > - /* MapVirtualKey doesn't return scancode with needed higher byte */ > - scancode = native_scancode | (scancode & 0xff00); > + /* 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 || GTK_CHECK_VERSION (3, 22, 0) You don't need the version check with HAVE_GDK_EVENT_GET_SCANCODE (but you could add a comment saying this was added in 3.22 to the configure.ac check). > + 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; > + } Should we have a log when native_scancode is NULL when we use the gdk_event_get_scancode codepath? A bit sad that even with get_scancode we end up needing to special case some keys :( Christophe
Attachment:
signature.asc
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel