>From d1d3289867263bf3fc42a27e3efb8c5d58c2ee38 Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Sun, 21 Dec 2014 17:17:11 +0100 Subject: [PATCH 2/3] input: gtk win32 ui handles altgr key correctly Linux guest / Windows host had a dead altgr key problem due to Windows mapping of altgr to ctrl-alt. This commit fixes it by sending a fake ctrl-up event to the guest when appropriate. In case of turbo mode, only one fake event is sent. In a windows guest, altgr key still works as usual. Signed-off-by: Remi Thebault --- ui/gtk.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index 27696fa..a6c623c 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -230,6 +230,12 @@ struct GtkDisplayState { bool modifier_pressed[ARRAY_SIZE(modifier_keycode)]; bool has_evdev; + +#if defined(_WIN32) + /* win32 alt-gr handling */ + bool l_ctrl_down; + bool r_alt_down; +#endif }; static void gd_grab_pointer(VirtualConsole *vc); @@ -973,6 +979,30 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } } +#if defined(_WIN32) + /* Windows maps altgr key to l-ctrl + r-alt. + For proper handling in the guest, only r-alt is to be sent. + This is done by sending a fake "ctrl up" event when appropriate. */ + switch (qemu_keycode) { + case 0x1d: /* l-ctrl */ + if (!s->l_ctrl_down && s->r_alt_down) { + /* fake ctrl up already sent */ + return TRUE; + } + s->l_ctrl_down = (key->type == GDK_KEY_PRESS); + break; + case 0xb8: /* r-alt */ + if (s->l_ctrl_down && !s->r_alt_down && + key->type == GDK_KEY_PRESS) { + /* sending fake "ctrl up" event */ + qemu_input_event_send_key_number(vc->gfx.dcl.con, 0x1d, FALSE); + s->l_ctrl_down = FALSE; + } + s->r_alt_down = (key->type == GDK_KEY_PRESS); + break; + } +#endif + qemu_input_event_send_key_number(vc->gfx.dcl.con, qemu_keycode, key->type == GDK_KEY_PRESS); -- 1.8.5.2.msysgit.0