diff mbox

alt-gr on Windows

Message ID BLU436-SMTP464639D8F0AB131F5E12FF6690@phx.gbl
State New
Headers show

Commit Message

Thebault, Remi Dec. 21, 2014, 5:54 p.m. UTC
Le 18/12/2014 12:55, Kevin Wolf a écrit :
> CCing Stefan Weil, who is both the Windows maintainer and the author of
> commit 2777ccc5, which introduced the MapVirtualKey() call. As there is
> a special case for Alt Gr in the code, I suppose he had this working
> back then.
>
>  From what I understand (which isn't much when it's about Windows), it
> seems very unlikely to me that the change would break anything that is
> working today; but you should probably give it some testing before
> posting a patch.
>
> Kevin
I could not find a case where this alt-gr code is actually useful.
 From what I tried, MapVirtualKey can only issue 103 value with input 
not relevant with alt-gr.

I have attached a set of 3 patchs for review. These are the first I 
issue, so please tell if the format is not the one expected.
0001 handles the rhs keystrokes in ui/gtk.c
0002 triggers the ctrl up event in ui/gtk.c
0003 triggers the ctrl up event in ui/sdl2.c

I had preferred to fix directly in ui/input.c in order to fix all UI at 
once (including vnc and sdl1, which I cannot run on my host), but this 
involves adding some state accessible to ui/input.c. QemuConsole looks 
most relevant but is private to ui/console.c.

The fix is successful in a Linux guest.
The fix has no noticeable effect in a Windows guest, precisely because 
the guest internally remaps alt-gr to ctrl-alt.
The one caveat I can raise is that the key combination l-ctrl + r-alt 
cannot be sent anymore to the guest.

Remi
From edec88edb24f5ec9abede2f3de7767f294c6cbc1 Mon Sep 17 00:00:00 2001
From: Remi Thebault <remi.thebault@outlook.com>
Date: Sun, 21 Dec 2014 17:15:56 +0100
Subject: [PATCH 1/3] input: gtk win32 ui sends r-ctrl and r-alt key events

gtk ui on win32 only sent left ctrl and alt code, whatever the keystroke.
In case of a right keystroke and left scan code, this commit corrects
the qemu code to fit the actual keystroke.

Signed-off-by: Remi Thebault <remi.thebault@outlook.com>
---
 ui/gtk.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index 0385757..27696fa 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -901,7 +901,21 @@  static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
 #ifdef GDK_WINDOWING_WIN32
     if (GDK_IS_WIN32_DISPLAY(dpy)) {
         qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
+        /*
+         * MapVirtualKey maps same code for left and right ctrl and alt keys.
+         * Following switch disambiguates the left and right codes.
+         */
         switch (qemu_keycode) {
+        case 0x1d: /* L-ctrl */
+            if (gdk_keycode == VK_RCONTROL) {
+                qemu_keycode |= SCANCODE_GREY;
+            }
+            break;
+        case 0x38: /* L-alt */
+            if (gdk_keycode == VK_RMENU) {
+                qemu_keycode |= SCANCODE_GREY;
+            }
+            break;
         case 103:   /* alt gr */
             qemu_keycode = 56 | SCANCODE_GREY;
             break;