* [Qemu-devel] alt-gr on Windows @ 2014-12-17 0:11 Thebault, Remi 2014-12-18 11:55 ` Kevin Wolf 0 siblings, 1 reply; 6+ messages in thread From: Thebault, Remi @ 2014-12-17 0:11 UTC (permalink / raw) To: qemu-devel Hi list! This is not the first post on this topic, but I haven't seen any solution about it. I tested so far linux guest on windows host and the AltGr key is dead in the guest. (using git master branch) On french keyboard, the keys to yield the bar "|" are alt-gr + 6. when executing this combination on keyboard, Windows generates this: - L-CTRL - R-ALT - 6 in Qemu (only digged gtk UI so far), pressing alt-gr + 6 generates the following trace - L-CTRL - L-ALT <-- note left here - 6 This comes from the Win32 call MapVirtualKey in gtk.c that maps to scancodes without left/right distinction. Even when sending the right alt to the guest, the alt-gr key remains dead because of ctrl being virtually pressed. I found out however that if R-ALT + 6 is sent without the ctrl key, the guest finally recognize it and prints the bar, @, # and other [}{]. To make things easier, Windows delivers the ctrl code before the alt code, so catching it cleanly before delivery to the guest is probably tough. I could however come to an easy and quick fix with sending the "ctrl up" signal to the guest before the "r-alt down" is sent. My current code do not handle all corner cases (eg: turbo mode) and only fixes the gtk ui, but would such fix be accepted in the repo? Would this break somehow the windows guest on windows host? Thanks, Rémi ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] alt-gr on Windows 2014-12-17 0:11 [Qemu-devel] alt-gr on Windows Thebault, Remi @ 2014-12-18 11:55 ` Kevin Wolf 2014-12-21 17:54 ` Thebault, Remi 2015-01-01 16:24 ` Andreas Färber 0 siblings, 2 replies; 6+ messages in thread From: Kevin Wolf @ 2014-12-18 11:55 UTC (permalink / raw) To: Thebault, Remi; +Cc: sw, qemu-devel Am 17.12.2014 um 01:11 hat Thebault, Remi geschrieben: > Hi list! > > This is not the first post on this topic, but I haven't seen any > solution about it. > I tested so far linux guest on windows host and the AltGr key is > dead in the guest. (using git master branch) > > On french keyboard, the keys to yield the bar "|" are alt-gr + 6. > when executing this combination on keyboard, Windows generates this: > - L-CTRL > - R-ALT > - 6 > > in Qemu (only digged gtk UI so far), pressing alt-gr + 6 generates > the following trace > - L-CTRL > - L-ALT <-- note left here > - 6 > > This comes from the Win32 call MapVirtualKey in gtk.c that maps to > scancodes without left/right distinction. > Even when sending the right alt to the guest, the alt-gr key remains > dead because of ctrl being virtually pressed. I found out however > that if R-ALT + 6 is sent without the ctrl key, the guest finally > recognize it and prints the bar, @, # and other [}{]. > > To make things easier, Windows delivers the ctrl code before the alt > code, so catching it cleanly before delivery to the guest is > probably tough. > I could however come to an easy and quick fix with sending the "ctrl > up" signal to the guest before the "r-alt down" is sent. > > My current code do not handle all corner cases (eg: turbo mode) and > only fixes the gtk ui, but would such fix be accepted in the repo? > Would this break somehow the windows guest on windows host? 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] alt-gr on Windows 2014-12-18 11:55 ` Kevin Wolf @ 2014-12-21 17:54 ` Thebault, Remi 2015-01-01 16:24 ` Andreas Färber 1 sibling, 0 replies; 6+ messages in thread From: Thebault, Remi @ 2014-12-21 17:54 UTC (permalink / raw) To: Kevin Wolf; +Cc: sw, qemu-devel [-- Attachment #1: Type: text/plain, Size: 1523 bytes --] 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 [-- Attachment #2: 0001-input-gtk-win32-ui-sends-r-ctrl-and-r-alt-key-events.patch --] [-- Type: text/plain, Size: 1530 bytes --] >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 --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; -- 1.8.5.2.msysgit.0 [-- Attachment #3: 0002-input-gtk-win32-ui-handles-altgr-key-correctly.patch --] [-- Type: text/plain, Size: 2188 bytes --] >From d1d3289867263bf3fc42a27e3efb8c5d58c2ee38 Mon Sep 17 00:00:00 2001 From: Remi Thebault <remi.thebault@outlook.com> 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 <remi.thebault@outlook.com> --- 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 [-- Attachment #4: 0003-input-sdl2-win32-ui-handles-altgr-key-correctly.patch --] [-- Type: text/plain, Size: 2625 bytes --] >From 9f755bea4f305e255e92f901e26f76e7a7364ecb Mon Sep 17 00:00:00 2001 From: Remi Thebault <remi.thebault@outlook.com> Date: Sun, 21 Dec 2014 17:18:05 +0100 Subject: [PATCH 3/3] input: sdl2 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 <remi.thebault@outlook.com> --- ui/sdl2.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/ui/sdl2.c b/ui/sdl2.c index 1ad74ba..42ed220 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -73,6 +73,12 @@ static SDL_Cursor *guest_sprite; static int scaling_active; static Notifier mouse_mode_notifier; +#if defined(_WIN32) +/* win32 alt-gr handling */ +static bool l_ctrl_down = 0; +static bool r_alt_down = 0; +#endif + static void sdl_update_caption(struct sdl2_state *scon); static struct sdl2_state *get_scon_from_window(uint32_t window_id) @@ -252,11 +258,37 @@ static void sdl_process_key(struct sdl2_state *scon, } else { modifiers_state[ev->keysym.scancode] = 1; } - /* fall though */ - default: - qemu_input_event_send_key_qcode(con, qcode, - ev->type == SDL_KEYDOWN); + break; } + +#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 (ev->keysym.scancode) { + case SDL_SCANCODE_LCTRL: /* l-ctrl */ + if (!l_ctrl_down && r_alt_down) { + /* fake ctrl up already sent */ + return; + } + l_ctrl_down = (ev->type == SDL_KEYDOWN); + break; + case SDL_SCANCODE_RALT: /* r-alt */ + if (l_ctrl_down && !r_alt_down && + ev->type == SDL_KEYDOWN) { + /* sending fake "ctrl up" event */ + qemu_input_event_send_key_qcode(con, + sdl2_scancode_to_qcode[SDL_SCANCODE_LCTRL], + false); + l_ctrl_down = false; + } + r_alt_down = (ev->type == SDL_KEYDOWN); + break; + } +#endif + + qemu_input_event_send_key_qcode(con, qcode, + ev->type == SDL_KEYDOWN); } static void sdl_update_caption(struct sdl2_state *scon) -- 1.8.5.2.msysgit.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] alt-gr on Windows 2014-12-18 11:55 ` Kevin Wolf 2014-12-21 17:54 ` Thebault, Remi @ 2015-01-01 16:24 ` Andreas Färber 2015-01-01 19:10 ` Stefan Weil 1 sibling, 1 reply; 6+ messages in thread From: Andreas Färber @ 2015-01-01 16:24 UTC (permalink / raw) To: Kevin Wolf, Thebault, Remi; +Cc: sw, qemu-devel, Tim Hardeck Hi, Am 18.12.2014 um 12:55 schrieb Kevin Wolf: > Am 17.12.2014 um 01:11 hat Thebault, Remi geschrieben: >> This is not the first post on this topic, but I haven't seen any >> solution about it. >> I tested so far linux guest on windows host and the AltGr key is >> dead in the guest. (using git master branch) >> >> On french keyboard, the keys to yield the bar "|" are alt-gr + 6. >> when executing this combination on keyboard, Windows generates this: >> - L-CTRL >> - R-ALT >> - 6 >> >> in Qemu (only digged gtk UI so far), pressing alt-gr + 6 generates >> the following trace >> - L-CTRL >> - L-ALT <-- note left here >> - 6 >> >> This comes from the Win32 call MapVirtualKey in gtk.c that maps to >> scancodes without left/right distinction. >> Even when sending the right alt to the guest, the alt-gr key remains >> dead because of ctrl being virtually pressed. I found out however >> that if R-ALT + 6 is sent without the ctrl key, the guest finally >> recognize it and prints the bar, @, # and other [}{]. >> >> To make things easier, Windows delivers the ctrl code before the alt >> code, so catching it cleanly before delivery to the guest is >> probably tough. >> I could however come to an easy and quick fix with sending the "ctrl >> up" signal to the guest before the "r-alt down" is sent. >> >> My current code do not handle all corner cases (eg: turbo mode) and >> only fixes the gtk ui, but would such fix be accepted in the repo? >> Would this break somehow the windows guest on windows host? > > 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. Tim and colleagues have been investigating some AltGr issues on Linux / NoVNC as well, so it may well have been broken before Stefan's commit. Regards, Andreas -- SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] alt-gr on Windows 2015-01-01 16:24 ` Andreas Färber @ 2015-01-01 19:10 ` Stefan Weil 2015-01-25 16:36 ` [Qemu-devel] [PATCH v2] " Thebault, Remi 0 siblings, 1 reply; 6+ messages in thread From: Stefan Weil @ 2015-01-01 19:10 UTC (permalink / raw) To: Andreas Färber, Kevin Wolf, Thebault, Remi; +Cc: Tim Hardeck, qemu-devel Am 01.01.2015 um 17:24 schrieb Andreas Färber: > Hi, Am 18.12.2014 um 12:55 schrieb Kevin Wolf: >> Am 17.12.2014 um 01:11 hat Thebault, Remi geschrieben: >>> This is not the first post on this topic, but I haven't seen any >>> solution about it. I tested so far linux guest on windows host and >>> the AltGr key is dead in the guest. (using git master branch) On >>> french keyboard, the keys to yield the bar "|" are alt-gr + 6. when >>> executing this combination on keyboard, Windows generates this: - >>> L-CTRL - R-ALT - 6 in Qemu (only digged gtk UI so far), pressing >>> alt-gr + 6 generates the following trace - L-CTRL - L-ALT <-- note >>> left here - 6 This comes from the Win32 call MapVirtualKey in gtk.c >>> that maps to scancodes without left/right distinction. Even when >>> sending the right alt to the guest, the alt-gr key remains dead >>> because of ctrl being virtually pressed. I found out however that if >>> R-ALT + 6 is sent without the ctrl key, the guest finally recognize >>> it and prints the bar, @, # and other [}{]. To make things easier, >>> Windows delivers the ctrl code before the alt code, so catching it >>> cleanly before delivery to the guest is probably tough. I could >>> however come to an easy and quick fix with sending the "ctrl up" >>> signal to the guest before the "r-alt down" is sent. My current code >>> do not handle all corner cases (eg: turbo mode) and only fixes the >>> gtk ui, but would such fix be accepted in the repo? Would this break >>> somehow the windows guest on windows host? >> 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. > Tim and colleagues have been investigating some AltGr issues on Linux > / NoVNC as well, so it may well have been broken before Stefan's > commit. Regards, Andreas Indeed, when I wrote that commit, it fixed an AltGr issue. I spent the last weeks (well, not all the time, but some minutes) to restore my previous test scenario, but without success. Remi's patch is a clear improvement of the current situation, but the problem is more complicated than one would think at a first glance. I suggest calling MapVirtualKey only for those keys which don't need special handling, so it would be in the default case of the switch statement. It looks like Alt-Ctrl is a valid alternative for pressing AltGr on Windows, so we have to take that into account, too. Wine also needs special handling because it sends a single (different) key code instead of two key codes. Regards Stefan ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2] alt-gr on Windows 2015-01-01 19:10 ` Stefan Weil @ 2015-01-25 16:36 ` Thebault, Remi 0 siblings, 0 replies; 6+ messages in thread From: Thebault, Remi @ 2015-01-25 16:36 UTC (permalink / raw) To: Stefan Weil, Andreas Färber, Kevin Wolf; +Cc: Tim Hardeck, qemu-devel [-- Attachment #1: Type: text/plain, Size: 871 bytes --] Hello attached is the v2 set of patchs. Le 01/01/2015 20:10, Stefan Weil a écrit : > I suggest calling MapVirtualKey only for those keys which don't need special handling, so it would be in the default case of the switch statement. Done (patch 0001) . updated code yields to same result as previous patch. Added a FIXME note regarding the previous alt gr fix, which do not look relevant anymore to me. > It looks like Alt-Ctrl is a valid alternative for pressing AltGr on Windows, so we have to take that into account, too. Few tests I did on a XP vm give correct keyboard behaviour. looks like this is transparent on Windows guest. > Wine also needs special handling because it sends a single (different) key code instead of two key codes. By this I understand that Wine should just be excluded from this fix (what I do by patch 0002) Regards, Rémi [-- Attachment #2: 0001-input-gtk-win32-ui-sends-r-ctrl-and-r-alt-key-events.patch --] [-- Type: text/plain, Size: 1882 bytes --] >From 3ecdd74fd12f33b6c00b66fce2e082c7fe9b273e Mon Sep 17 00:00:00 2001 From: Remi Thebault <remi.thebault@outlook.com> Date: Sun, 25 Jan 2015 16:57:45 +0100 Subject: [PATCH 1/4 v2] 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 | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 0385757..da593f7 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -900,10 +900,26 @@ 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); - switch (qemu_keycode) { - case 103: /* alt gr */ - qemu_keycode = 56 | SCANCODE_GREY; + /* + testing for right ctrl and right alt and give corresponding code. + for all other keystrokes, scan code is given by MapVirtualKey. + (MapVirtualKey maps same code for left and right ctrl and alt keys) + */ + switch (gdk_keycode) { + case 0xa3: // r-ctrl + qemu_keycode = 0x9d; + break; + case 0xa5: // r-alt + qemu_keycode = 0xb8; + break; + default: + qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC); + /* FIXME: is following check still needed? */ + switch (qemu_keycode) { + case 103: /* alt gr */ + qemu_keycode = 56 | SCANCODE_GREY; + break; + } break; } return qemu_keycode; -- 1.8.5.2.msysgit.0 [-- Attachment #3: 0002-input-introduce-INPUT_NEEDS_ALTGR_FIX-macro.patch --] [-- Type: text/plain, Size: 877 bytes --] >From b4866d32436e9b6bd9a9488eb5f998d196980e77 Mon Sep 17 00:00:00 2001 From: Remi Thebault <remi.thebault@outlook.com> Date: Sun, 25 Jan 2015 17:04:01 +0100 Subject: [PATCH 2/4 v2] input: introduce INPUT_NEEDS_ALTGR_FIX macro Common macro amoung all ui, to provide consistent alt gr fix. defined such as to have the fix on win32 (excluding wine) --- include/ui/input.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/ui/input.h b/include/ui/input.h index 5d5ac00..64e531c 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -10,6 +10,13 @@ #define INPUT_EVENT_ABS_SIZE 0x8000 +#ifndef INPUT_NEEDS_ALTGR_FIX +# if defined(_WIN32) && !defined(__WINE__) +# define INPUT_NEEDS_ALTGR_FIX 1 +# endif +#endif + + typedef struct QemuInputHandler QemuInputHandler; typedef struct QemuInputHandlerState QemuInputHandlerState; -- 1.8.5.2.msysgit.0 [-- Attachment #4: 0003-input-gtk-win32-ui-handles-altgr-key-correctly.patch --] [-- Type: text/plain, Size: 2216 bytes --] >From 23b3b8bfa8dfce05b72bde6a82adf6e122a5d74f Mon Sep 17 00:00:00 2001 From: Remi Thebault <remi.thebault@outlook.com> Date: Sun, 25 Jan 2015 17:06:11 +0100 Subject: [PATCH 3/4 v2] 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 <remi.thebault@outlook.com> --- ui/gtk.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index da593f7..1287409 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(INPUT_NEEDS_ALTGR_FIX) + /* win32 alt-gr handling */ + bool l_ctrl_down; + bool r_alt_down; +#endif }; static void gd_grab_pointer(VirtualConsole *vc); @@ -975,6 +981,30 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } } +#if defined(INPUT_NEEDS_ALTGR_FIX) + /* 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 [-- Attachment #5: 0004-input-sdl2-win32-ui-handles-altgr-key-correctly.patch --] [-- Type: text/plain, Size: 2650 bytes --] >From 8d685ff821480aabf28973d2f174f47921617c01 Mon Sep 17 00:00:00 2001 From: Remi Thebault <remi.thebault@outlook.com> Date: Sun, 25 Jan 2015 17:09:58 +0100 Subject: [PATCH 4/4 v2] input: sdl2 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 <remi.thebault@outlook.com> --- ui/sdl2.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/ui/sdl2.c b/ui/sdl2.c index 1ad74ba..bba8f4f 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -73,6 +73,12 @@ static SDL_Cursor *guest_sprite; static int scaling_active; static Notifier mouse_mode_notifier; +#if defined(INPUT_NEEDS_ALTGR_FIX) +/* win32 alt-gr handling */ +static bool l_ctrl_down = 0; +static bool r_alt_down = 0; +#endif + static void sdl_update_caption(struct sdl2_state *scon); static struct sdl2_state *get_scon_from_window(uint32_t window_id) @@ -252,11 +258,37 @@ static void sdl_process_key(struct sdl2_state *scon, } else { modifiers_state[ev->keysym.scancode] = 1; } - /* fall though */ - default: - qemu_input_event_send_key_qcode(con, qcode, - ev->type == SDL_KEYDOWN); + break; + } + +#if defined(INPUT_NEEDS_ALTGR_FIX) + /* 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 (ev->keysym.scancode) { + case SDL_SCANCODE_LCTRL: /* l-ctrl */ + if (!l_ctrl_down && r_alt_down) { + /* fake ctrl up already sent */ + return; + } + l_ctrl_down = (ev->type == SDL_KEYDOWN); + break; + case SDL_SCANCODE_RALT: /* r-alt */ + if (l_ctrl_down && !r_alt_down && + ev->type == SDL_KEYDOWN) { + /* sending fake "ctrl up" event */ + qemu_input_event_send_key_qcode(con, + sdl2_scancode_to_qcode[SDL_SCANCODE_LCTRL], + false); + l_ctrl_down = false; + } + r_alt_down = (ev->type == SDL_KEYDOWN); + break; } +#endif + + qemu_input_event_send_key_qcode(con, qcode, + ev->type == SDL_KEYDOWN); } static void sdl_update_caption(struct sdl2_state *scon) -- 1.8.5.2.msysgit.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-01-25 16:36 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-12-17 0:11 [Qemu-devel] alt-gr on Windows Thebault, Remi 2014-12-18 11:55 ` Kevin Wolf 2014-12-21 17:54 ` Thebault, Remi 2015-01-01 16:24 ` Andreas Färber 2015-01-01 19:10 ` Stefan Weil 2015-01-25 16:36 ` [Qemu-devel] [PATCH v2] " Thebault, Remi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).