[spice-gtk] Spice-widget: Use new gdk_event_get_scancode if available

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

 



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.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 src/spice-widget.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

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)
+    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) {
+        native_scancode = MapVirtualKey(key->hardware_keycode, MAPVK_VK_TO_VSC);
+        /* MapVirtualKey doesn't return scancode with needed higher byte */
+        scancode = native_scancode | (scancode & 0xff00);
+    }
 
     /* Some virtual-key codes are missed in MapVirtualKey(). */
     switch (langid) {
-- 
2.5.5

_______________________________________________
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]