From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>,
Anthony Liguori <aliguori@amazon.com>,
Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 2/4] gtk: cleanup backend dependencies
Date: Thu, 12 Jun 2014 10:38:21 +0200 [thread overview]
Message-ID: <1402562303-16930-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1402562303-16930-1-git-send-email-kraxel@redhat.com>
Make configure detect gtk x11 backend and link libX11 then. Make
gtk backend specific code properly #ifdef'ed on the GTK_WINDOWING_*
backends at runtime). Our gtk ui code should build and run fine on
any platform now.
This also fixes the linker failute due to the new XkbGetKeyboard call
added by commit 3158a3482b0093e41f2b2596fba50774ea31ae08.
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
---
configure | 4 ++++
ui/gtk.c | 70 ++++++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 46 insertions(+), 28 deletions(-)
diff --git a/configure b/configure
index a994f41..23514ec 100755
--- a/configure
+++ b/configure
@@ -1993,6 +1993,7 @@ fi
if test "$gtk" != "no"; then
gtkpackage="gtk+-$gtkabi"
+ gtkx11package="gtk+-x11-$gtkabi"
if test "$gtkabi" = "3.0" ; then
gtkversion="3.0.0"
else
@@ -2001,6 +2002,9 @@ if test "$gtk" != "no"; then
if $pkg_config --exists "$gtkpackage >= $gtkversion"; then
gtk_cflags=`$pkg_config --cflags $gtkpackage`
gtk_libs=`$pkg_config --libs $gtkpackage`
+ if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
+ gtk_libs="$gtk_libs -lX11"
+ fi
libs_softmmu="$gtk_libs $libs_softmmu"
gtk="yes"
elif test "$gtk" = "yes"; then
diff --git a/ui/gtk.c b/ui/gtk.c
index 01d48cc..d201190 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -68,7 +68,7 @@
#include "keymaps.h"
#include "sysemu/char.h"
#include "qom/object.h"
-#ifndef _WIN32
+#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#include <X11/XKBlib.h>
#endif
@@ -112,6 +112,13 @@ static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
#define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget)
#endif
+#ifndef GDK_IS_X11_DISPLAY
+#define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
+#endif
+#ifndef GDK_IS_WIN32_DISPLAY
+#define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
+#endif
+
#ifndef GDK_KEY_0
#define GDK_KEY_0 GDK_0
#define GDK_KEY_1 GDK_1
@@ -877,29 +884,34 @@ static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll,
return TRUE;
}
-static int gd_map_keycode(GtkDisplayState *s, int gdk_keycode)
+static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
{
int qemu_keycode;
-#ifdef _WIN32
- qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
- switch (qemu_keycode) {
- case 103: /* alt gr */
- qemu_keycode = 56 | SCANCODE_GREY;
- break;
+#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;
+ break;
+ }
+ return qemu_keycode;
}
-#else
+#endif
if (gdk_keycode < 9) {
qemu_keycode = 0;
} else if (gdk_keycode < 97) {
qemu_keycode = gdk_keycode - 8;
- } else if (gdk_keycode < 158) {
+#ifdef GDK_WINDOWING_X11
+ } else if (GDK_IS_X11_DISPLAY(dpy) && gdk_keycode < 158) {
if (s->has_evdev) {
qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
} else {
qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
}
+#endif
} else if (gdk_keycode == 208) { /* Hiragana_Katakana */
qemu_keycode = 0x70;
} else if (gdk_keycode == 211) { /* backslash */
@@ -907,7 +919,6 @@ static int gd_map_keycode(GtkDisplayState *s, int gdk_keycode)
} else {
qemu_keycode = 0;
}
-#endif
return qemu_keycode;
}
@@ -920,7 +931,8 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
int qemu_keycode;
int i;
- qemu_keycode = gd_map_keycode(s, gdk_keycode);
+ qemu_keycode = gd_map_keycode(s, gtk_widget_get_display(widget),
+ gdk_keycode);
trace_gd_key_event(vc->label, gdk_keycode, qemu_keycode,
(key->type == GDK_KEY_PRESS) ? "down" : "up");
@@ -1802,23 +1814,25 @@ static void gd_create_menus(GtkDisplayState *s)
static void gd_set_keycode_type(GtkDisplayState *s)
{
-#ifndef _WIN32
- char *keycodes = NULL;
+#ifdef GDK_WINDOWING_X11
GdkDisplay *display = gtk_widget_get_display(s->window);
- Display *x11_display = gdk_x11_display_get_xdisplay(display);
- XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask,
- XkbUseCoreKbd);
-
- if (desc && desc->names) {
- keycodes = XGetAtomName(x11_display, desc->names->keycodes);
- }
- if (keycodes == NULL) {
- fprintf(stderr, "could not lookup keycode name\n");
- } else if (strstart(keycodes, "evdev", NULL)) {
- s->has_evdev = true;
- } else if (!strstart(keycodes, "xfree86", NULL)) {
- fprintf(stderr, "unknown keycodes `%s', please report to "
- "qemu-devel@nongnu.org\n", keycodes);
+ if (GDK_IS_X11_DISPLAY(display)) {
+ Display *x11_display = gdk_x11_display_get_xdisplay(display);
+ XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask,
+ XkbUseCoreKbd);
+ char *keycodes = NULL;
+
+ if (desc && desc->names) {
+ keycodes = XGetAtomName(x11_display, desc->names->keycodes);
+ }
+ if (keycodes == NULL) {
+ fprintf(stderr, "could not lookup keycode name\n");
+ } else if (strstart(keycodes, "evdev", NULL)) {
+ s->has_evdev = true;
+ } else if (!strstart(keycodes, "xfree86", NULL)) {
+ fprintf(stderr, "unknown keycodes `%s', please report to "
+ "qemu-devel@nongnu.org\n", keycodes);
+ }
}
#endif
}
--
1.8.3.1
next prev parent reply other threads:[~2014-06-12 8:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-12 8:38 [Qemu-devel] [PULL 0/4] gtk patch queue Gerd Hoffmann
2014-06-12 8:38 ` [Qemu-devel] [PULL 1/4] gtk: factor out keycode mapping Gerd Hoffmann
2014-06-12 8:38 ` Gerd Hoffmann [this message]
2014-06-12 8:38 ` [Qemu-devel] [PULL 3/4] gtk: factor out gtk3 grab into the new gd_grab_devices function Gerd Hoffmann
2014-06-12 8:38 ` [Qemu-devel] [PULL 4/4] gtk: update window size after showing/hiding tabs Gerd Hoffmann
2014-06-12 9:49 ` [Qemu-devel] [PULL 0/4] gtk patch queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1402562303-16930-3-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=aliguori@amazon.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).