gtk: Support keyboard translation for hosts running Windows
PATCH 1/1 gtk: Support keyboard translation for hosts running Windows
GTK uses different hardware keycodes on Windows hosts, so some special handling is needed to get the QEMU keycode.
--- ui/gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
ui/gtk.c +15 -3
@@ -34,6 +34,10 @@#define GETTEXT_PACKAGE "qemu"#define LOCALEDIR "po" +#ifdef _WIN32 +# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */ +#endif +#include "qemu-common.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
@@ -704,11 +708,18 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,static gboolean gd_key_event (GtkWidget *widget,GdkEventKey *key,void *opaque) {GtkDisplayState *s = opaque; -int gdk_keycode; -int qemu_keycode; +int gdk_keycode = key->hardware_keycode;int i; - gdk_keycode = key->hardware_keycode; +#ifdef _WIN32 +UINT qemu_keycode =MapVirtualKey (gdk_keycode,MAPVK_VK_TO_VSC ); +switch (qemu_keycode) { +case 103 :/* alt gr */ + qemu_keycode =56 |SCANCODE_GREY ; +break ; + } +#else +int qemu_keycode;if (gdk_keycode <9 ) { qemu_keycode =0 ;
@@ -723,6 +734,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } else { qemu_keycode =0 ; } +#endif trace_gd_key_event (gdk_keycode, qemu_keycode, (key->type ==GDK_KEY_PRESS ) ?"down" :"up" );
Signature · 1 line
1.7.10.4
Am 07.12.2013 16:25, schrieb Stefan Weil:
Quoted 46 lines
GTK uses different hardware keycodes on Windows hosts, so some special handling is needed to get the QEMU keycode.
Signed-off-by Stefan Weil <[email protected]>--- ui/gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)ui/gtk.c +14
-3@@ -34,6 +34,10 @@#define GETTEXT_PACKAGE "qemu"#define LOCALEDIR "po" +#ifdef _WIN32 +# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */ +#endif +#include "qemu-common.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE @@ -704,11 +708,18 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,static gboolean gd_key_event (GtkWidget *widget,GdkEventKey *key,void *opaque) {GtkDisplayState *s = opaque; -int gdk_keycode; -int qemu_keycode; +int gdk_keycode = key->hardware_keycode;int i; - gdk_keycode = key->hardware_keycode; +#ifdef _WIN32 +UINT qemu_keycode =MapVirtualKey (gdk_keycode,MAPVK_VK_TO_VSC ); +switch (qemu_keycode) { +case 103 :/* alt gr */ + qemu_keycode =56 |SCANCODE_GREY ; +break ; + } +#else +int qemu_keycode;if (gdk_keycode <9 ) { qemu_keycode =0 ;
ui/gtk.c static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) · line 740
Quoted 7 lines
ui/gtk.c +1
-0@@ -723,6 +734,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } else { qemu_keycode =0 ; } +#endif trace_gd_key_event (gdk_keycode, qemu_keycode, (key->type ==GDK_KEY_PRESS ) ?"down" :"up" );
Ping? Should I send a MinGW pull request for this patch?
Am 18.12.2013 19:14, schrieb Stefan Weil:
Quoted 52 lines
Am 07.12.2013 16:25, schrieb Stefan Weil:
Quoted 51 lines
GTK uses different hardware keycodes on Windows hosts, so some special handling is needed to get the QEMU keycode.
Signed-off-by Stefan Weil <[email protected]>--- ui/gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)ui/gtk.c +15
-3@@ -34,6 +34,10 @@#define GETTEXT_PACKAGE "qemu"#define LOCALEDIR "po" +#ifdef _WIN32 +# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */ +#endif +#include "qemu-common.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE @@ -704,11 +708,18 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,static gboolean gd_key_event (GtkWidget *widget,GdkEventKey *key,void *opaque) {GtkDisplayState *s = opaque; -int gdk_keycode; -int qemu_keycode; +int gdk_keycode = key->hardware_keycode;int i; - gdk_keycode = key->hardware_keycode; +#ifdef _WIN32 +UINT qemu_keycode =MapVirtualKey (gdk_keycode,MAPVK_VK_TO_VSC ); +switch (qemu_keycode) { +case 103 :/* alt gr */ + qemu_keycode =56 |SCANCODE_GREY ; +break ; + } +#else +int qemu_keycode;if (gdk_keycode <9 ) { qemu_keycode =0 ;@@ -723,6 +734,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } else { qemu_keycode =0 ; } +#endif
Quoted 5 lines
ui/gtk.c static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) · line 740
Quoted 2 lines
ui/gtk.c +0
-0trace_gd_key_event (gdk_keycode, qemu_keycode, (key->type ==GDK_KEY_PRESS ) ?"down" :"up" );Ping? Should I send a MinGW pull request for this patch?
Ping^2? I tried to answer Andreas' questions. Are there any more?
Stefan
Am 10.01.2014 20:02, schrieb Stefan Weil:
Quoted 60 lines
Am 18.12.2013 19:14, schrieb Stefan Weil:
Quoted 52 lines
Am 07.12.2013 16:25, schrieb Stefan Weil:
Quoted 51 lines
GTK uses different hardware keycodes on Windows hosts, so some special handling is needed to get the QEMU keycode.
Signed-off-by Stefan Weil <[email protected]>--- ui/gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)ui/gtk.c +15
-3@@ -34,6 +34,10 @@#define GETTEXT_PACKAGE "qemu"#define LOCALEDIR "po" +#ifdef _WIN32 +# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */ +#endif +#include "qemu-common.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE @@ -704,11 +708,18 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,static gboolean gd_key_event (GtkWidget *widget,GdkEventKey *key,void *opaque) {GtkDisplayState *s = opaque; -int gdk_keycode; -int qemu_keycode; +int gdk_keycode = key->hardware_keycode;int i; - gdk_keycode = key->hardware_keycode; +#ifdef _WIN32 +UINT qemu_keycode =MapVirtualKey (gdk_keycode,MAPVK_VK_TO_VSC ); +switch (qemu_keycode) { +case 103 :/* alt gr */ + qemu_keycode =56 |SCANCODE_GREY ; +break ; + } +#else +int qemu_keycode;if (gdk_keycode <9 ) { qemu_keycode =0 ;@@ -723,6 +734,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } else { qemu_keycode =0 ; } +#endif Quoted 5 lines
ui/gtk.c static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) · line 740
Quoted 2 lines
ui/gtk.c +0
-0trace_gd_key_event (gdk_keycode, qemu_keycode, (key->type ==GDK_KEY_PRESS ) ?"down" :"up" );Ping? Should I send a MinGW pull request for this patch?
Quoted 4 lines
Ping^2? I tried to answer Andreas' questions. Are there any more?
Stefan
Ping^3. What is missing to get this patch applied? It was sent more than a month ago (2012-12-07).
Stefan
Il 19/01/2014 22:18, Stefan Weil ha scritto:
Quoted 2 lines
Ping^3. What is missing to get this patch applied? It was sent more than a month ago (2012-12-07).
You are Win32 maintainer, just send a pull request.
Paolo
Am 07.12.2013 16:25, schrieb Stefan Weil:
Quoted 13 lines
GTK uses different hardware keycodes on Windows hosts, so some special handling is needed to get the QEMU keycode.
Signed-off-by Stefan Weil <[email protected]>--- ui/gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)ui/gtk.c +0
-0
ui/gtk.c line 38
Quoted 5 lines
ui/gtk.c +2
-0@@ -34,6 +34,10 @@#define GETTEXT_PACKAGE "qemu"#define LOCALEDIR "po" +#ifdef _WIN32 +# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */
IIRC that symbol forces compilation for that particular Windows version and later versions but won't work on lower versions then, right? In that case shouldn't that live somewhere more central than gtk.c, like QEMU_CFLAGS in configure?
Quoted 7 lines
ui/gtk.c +2
-0+#endif +#include "qemu-common.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE @@ -704,11 +708,18 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,static gboolean gd_key_event (GtkWidget *widget,GdkEventKey *key,void *opaque)
ui/gtk.c static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, · line 715
Quoted 10 lines
ui/gtk.c +3
-3{GtkDisplayState *s = opaque; -int gdk_keycode; -int qemu_keycode; +int gdk_keycode = key->hardware_keycode;int i; - gdk_keycode = key->hardware_keycode; +#ifdef _WIN32 +UINT qemu_keycode =MapVirtualKey (gdk_keycode,MAPVK_VK_TO_VSC );
Possibly handle the #ifndef MAPVK_VK_TO_VSC case? What Windows version are we talking about anyway? XP? Vista? 7?
Regards,
Andreas
Quoted 19 lines
ui/gtk.c +8
-0+switch (qemu_keycode) { +case 103 :/* alt gr */ + qemu_keycode =56 |SCANCODE_GREY ; +break ; + } +#else +int qemu_keycode;if (gdk_keycode <9 ) { qemu_keycode =0 ;@@ -723,6 +734,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) } else { qemu_keycode =0 ; } +#endif trace_gd_key_event (gdk_keycode, qemu_keycode, (key->type ==GDK_KEY_PRESS ) ?"down" :"up" );
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Am 18.12.2013 19:28, schrieb Andreas Färber:
Quoted 17 lines
Am 07.12.2013 16:25, schrieb Stefan Weil:
Quoted 16 lines
GTK uses different hardware keycodes on Windows hosts, so some special handling is needed to get the QEMU keycode.
Signed-off-by Stefan Weil <[email protected]>--- ui/gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)ui/gtk.c +0
-0@@ -34,6 +34,10 @@#define GETTEXT_PACKAGE "qemu"#define LOCALEDIR "po"
Quoted 6 lines
ui/gtk.c line 38
Quoted 2 lines
ui/gtk.c +2
-0+#ifdef _WIN32 +# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */ IIRC that symbol forces compilation for that particular Windows version and later versions but won't work on lower versions then, right? In that case shouldn't that live somewhere more central than
gtk.c, likeQEMU_CFLAGSin configure?
The MinGW include files only define MAPVK_VK_TO_VSC if _WIN32_WINNT >= 0x0601 (== _WIN32_WINNT_WIN7). By default, _WIN32_WINNT == 0x0502 (== _WIN32_WINNT_WS03).
A more central place is fine for the future, but for now I'd prefer to minimize potential cross effects. We already have a name conflict between Windows macros and local QEMU macros in a file which is not Windows related at all. Ideally, only few source files would include Windows include file - then _WIN32_WINNT could be defined in include/sysemu/os-win32.h.
Quoted 14 lines
Quoted 14 lines
ui/gtk.c +3
-2+#endif +#include "qemu-common.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE @@ -704,11 +708,18 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,static gboolean gd_key_event (GtkWidget *widget,GdkEventKey *key,void *opaque) {GtkDisplayState *s = opaque; -int gdk_keycode; -int qemu_keycode; +int gdk_keycode = key->hardware_keycode;int i;
Quoted 5 lines
ui/gtk.c static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, · line 715
Quoted 3 lines
ui/gtk.c +2
-1- gdk_keycode = key->hardware_keycode; +#ifdef _WIN32 +UINT qemu_keycode =MapVirtualKey (gdk_keycode,MAPVK_VK_TO_VSC );Possibly handle the #ifndef
MAPVK_VK_TO_VSCcase? What Windows version are we talking about anyway? XP? Vista? 7?
I have no solution for the #ifndef MAPVK_VK_TO_VSC case. The code works for me with Windows 7 and 8.1, but might work with older versions, too. If someone has Windows XP, a test can be run with
http://qemu.weilnetz.de/w32/qemu-w32-setup-20131128.exe. According to MSDN, MapVirtualKey is available since Windows 2000 Professional.
Quoted 2 lines
Regards,
Andreas
Regards,
Stefan
Am 18.12.2013 21:12, schrieb Stefan Weil:
Quoted 5 lines
I have no solution for the #ifndef
MAPVK_VK_TO_VSCcase. The code works for me with Windows 7 and 8.1, but might work with older versions, too. If someone has Windows XP, a test can be run with
http://qemu.weilnetz.de/w32/qemu-w32-setup-20131128.exe. According to MSDN, MapVirtualKey is available since Windows 2000 Professional.
I forgot to mention that the patch fixes keyboard input for QEMU running with Wine, too. So obviously Wine supports the MapVirtualKey interface.
Cheers, Stefan