Skip to contentSkip to conversation

ui: use evdev keymap when running under wayland

PATCH In review Daniel P. Berrange 3 participants 8 messages Dec 1, 2016 – Jan 3, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ui: use evdev keymap when running under wayland

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -0
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
Signature · 1 line
2.9.3
Tested-by on v2 1/1
#1 lore raw
Quoted 55 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -1
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
--
Quoted 2 lines

2.9.3

Great, you've fixed Wayland!

This is GTK3-only so I used ./configure --with-gtkabi=3.0 on my system that has both GTK2 and GTK3 headers installed. ./configure will select GTK2 by default and I'm not sure if that is a good idea nowadays.

#2 lore raw
Quoted 67 lines · Stefan Hajnoczi
Quoted 55 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -1
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
--
Quoted 2 lines

2.9.3

Great, you've fixed Wayland!

This is GTK3-only so I used ./configure --with-gtkabi=3.0 on my system that has both GTK2 and GTK3 headers installed. ./configure will select GTK2 by default and I'm not sure if that is a good idea nowadays.

#3 lore raw
Quoted 62 lines · Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -1
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
--
Quoted 2 lines

2.9.3

Great, you've fixed Wayland!

Quoted 6 lines
Quoted 6 lines

This is GTK3-only so I used ./configure --with-gtkabi=3.0 on my system that has both GTK2 and GTK3 headers installed. ./configure will select GTK2 by default and I'm not sure if that is a good idea nowadays.

Sorry, Cole. I pressed Send too quickly :). I meant to add:

This patch is especially relevant for Fedora 25 where Wayland is the default. Without the GTK UI will not handle cursor and other keys correctly.

Dan: Come to think of it, ui/sdl.c also has X11 keycode mangling. Perhaps that is broken too... :(

Stefan

#4 lore raw
Quoted 70 lines · Stefan Hajnoczi
Quoted 62 lines · Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -1
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
--
Quoted 2 lines

2.9.3

Great, you've fixed Wayland!

Quoted 6 lines
Quoted 6 lines

This is GTK3-only so I used ./configure --with-gtkabi=3.0 on my system that has both GTK2 and GTK3 headers installed. ./configure will select GTK2 by default and I'm not sure if that is a good idea nowadays.

Quoted 8 lines

Sorry, Cole. I pressed Send too quickly :). I meant to add:

This patch is especially relevant for Fedora 25 where Wayland is the default. Without the GTK UI will not handle cursor and other keys correctly.

Dan: Come to think of it, ui/sdl.c also has X11 keycode mangling. Perhaps that is broken too... :(

SDL doesn't have native Wayland support, so it will be running via Xwayland, which will use regulard Xorg evdev mapping, so that should be fine still.

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#5 lore raw
In reply to Stefan Hajnoczi
Quoted 68 lines · Stefan Hajnoczi
Quoted 67 lines · Stefan Hajnoczi
Quoted 66 lines · Stefan Hajnoczi
Quoted 55 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -1
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
--
Quoted 2 lines

2.9.3

Great, you've fixed Wayland!

This is GTK3-only so I used ./configure --with-gtkabi=3.0 on my system that has both GTK2 and GTK3 headers installed. ./configure will select GTK2 by default and I'm not sure if that is a good idea nowadays.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Sorry, Cole. I pressed Send too quickly :). I meant to add:

This patch is especially relevant for Fedora 25 where Wayland is the default. Without the GTK UI will not handle cursor and other keys correctly.

Thanks for the pointer, I made a note in
https://bugzilla.redhat.com/show_bug.cgi?id=1401211 and I'll do a build ASAP

- Cole

#6 lore raw
In reply to Stefan Hajnoczi
Quoted 61 lines · Stefan Hajnoczi
Quoted 55 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -1
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
--
Quoted 2 lines

2.9.3

Great, you've fixed Wayland!

Quoted 4 lines

This is GTK3-only so I used ./configure --with-gtkabi=3.0 on my system that has both GTK2 and GTK3 headers installed. ./configure will select GTK2 by default and I'm not sure if that is a good idea nowadays.

We had a discussion on IRC a few weeks back about default UI frontends.

We should certainly prefer GTK3 over GTK2 if both a present, since GTK2 is essentially a dead technology at this time.

Quoted 1 line

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#7 lore raw
In reply to Daniel P. Berrange

CC'ing Gerd as the ui/ maintainer

Quoted 57 lines · Daniel P. Berrange

Wayland always uses evdev as its input source, so QEMU can use the existing evdev keymap data

---

Changed in v2

- Actually add all changed files to commit - gtk.h :-)

 include/ui/gtk.h | 4 ++++
 ui/gtk.c         | 7 +++++++
 2 files changed, 11 insertions(+)
include/ui/gtk.h +4 -0
index 42ca0fe..b3b5005 100644
@@ -18,6 +18,10 @@
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef GDK_WINDOWING_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif
+
 #if defined(CONFIG_OPENGL)
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
ui/gtk.c +7 -0
index e816428..81dba57 100644
@@ -90,6 +90,9 @@
 #ifndef GDK_IS_X11_DISPLAY
 #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
 #endif
+#ifndef GDK_IS_WAYLAND_DISPLAY
+#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
+#endif
 #ifndef GDK_IS_WIN32_DISPLAY
 #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
 #endif
@@ -1054,6 +1057,10 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
 #endif
+#ifdef GDK_WINDOWING_WAYLAND
+    } else if (GDK_IS_WAYLAND_DISPLAY(dpy) && gdk_keycode < 158) {
+        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
Signature · 1 line
2.9.3

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|