All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org, Anthony Liguori <aliguori@amazon.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] gtk: cleanup backend dependencies
Date: Mon, 2 Jun 2014 12:10:44 +0100	[thread overview]
Message-ID: <20140602111044.GD28039@redhat.com> (raw)
In-Reply-To: <1401706713-24909-1-git-send-email-kraxel@redhat.com>

On Mon, Jun 02, 2014 at 12:58:33PM +0200, Gerd Hoffmann wrote:
> diff --git a/configure b/configure
> index 0e516f9..b02f822 100755
> --- a/configure
> +++ b/configure
> @@ -1986,6 +1986,8 @@ fi
>  
>  if test "$gtk" != "no"; then
>      gtkpackage="gtk+-$gtkabi"
> +    gtkx11package="gtk+-x11-$gtkabi"
> +    gtkwin32package="gtk+-win32-$gtkabi"
>      if test "$gtkabi" = "3.0" ; then
>        gtkversion="3.0.0"
>      else
> @@ -1996,6 +1998,13 @@ if test "$gtk" != "no"; then
>          gtk_libs=`$pkg_config --libs $gtkpackage`
>          libs_softmmu="$gtk_libs $libs_softmmu"
>          gtk="yes"
> +        if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
> +            gtkx11="yes"
> +            gtk_libs="$gtk_libs -lX11"
> +        fi
> +        if $pkg_config --exists "$gtkwin32package >= $gtkversion"; then
> +            gtkwin32="yes"
> +        fi
>      elif test "$gtk" = "yes"; then
>          feature_not_found "gtk" "Install gtk2 or gtk3 devel"
>      else
> @@ -4459,6 +4468,12 @@ if test "$gtk" = "yes" ; then
>    echo "CONFIG_GTKABI=$gtkabi" >> $config_host_mak
>    echo "GTK_CFLAGS=$gtk_cflags" >> $config_host_mak
>  fi
> +if test "$gtkx11" = "yes" ; then
> +  echo "CONFIG_GTK_X11=y" >> $config_host_mak
> +fi
> +if test "$gtkwin32" = "yes" ; then
> +  echo "CONFIG_GTK_WIN32=y" >> $config_host_mak
> +fi
>  if test "$vte" = "yes" ; then
>    echo "CONFIG_VTE=y" >> $config_host_mak
>    echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak

None of this configure time detection is needed, as GTK already
defines macros in its header which let you check this eg you can
just do

 #ifdef GDK_WINDOWING_WIN32
 ...Windows stuf...
 #endif

 #ifdef GDK_WINDOWING_QUARTZ
 ...OS-X stuff...
 #endif
 

 #ifdef GDK_WINDOWING_X11
 ...Xorg stuf...
 #endif

This works for GTK 2 and 3 - we're using this in GTK-VNC for
a while now [1].

> diff --git a/ui/gtk.c b/ui/gtk.c
> index 9d06df3..773a987 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 CONFIG_GTK_X11
>  #include <gdk/gdkx.h>
>  #include <X11/XKBlib.h>
>  #endif
> @@ -925,7 +925,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
>      int gdk_keycode = key->hardware_keycode;
>      int i;
>  
> -#ifdef _WIN32
> +#ifdef CONFIG_GTK_WIN32
>      UINT qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
>      switch (qemu_keycode) {
>      case 103:   /* alt gr */
> @@ -939,12 +939,14 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
>          qemu_keycode = 0;
>      } else if (gdk_keycode < 97) {
>          qemu_keycode = gdk_keycode - 8;
> +#ifdef CONFIG_GTK_X11
>      } else if (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

With GTK3 you can have multiple backends compiled into the GTK library
so as well as using the #ifdef GDK_WINDOWING_X11 you should also check
whether the window system is the active backend using one of the
GDK_IS_*_DISPLAY() macros

eg With GTK3 you'd do

#ifdef GDK_WINDOWING_X11
    if (GDK_IS_X11_DISPLAY(dpy)) {
       ....Xorg stuff...
    }
#endif

#ifdef GDK_WINDOWING_WIN32
    if (GDK_IS_WIN32_DISPLAY(dpy)) {
       ...Windows stuff...
    }
#endif

The only painpoint is that the GDK_IS_*_DISPLAY macros don't exist
with GTK2, but with GTK2 you can only have 1 windowing system compiled
into the binary, so you can stub out those macros to no-ops that
evaluate true

eg

/* GTK2 compat */
#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_IS_QUARTZ_DISPLAY
#define GDK_IS_QUARTZ_DISPLAY(dpy) (dpy == dpy)
#endif



Regards,
Daniel

[1] https://git.gnome.org/browse/gtk-vnc/tree/src/vncdisplaykeymap.c
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2014-06-02 11:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-02 10:58 [Qemu-devel] [PATCH] gtk: cleanup backend dependencies Gerd Hoffmann
2014-06-02 11:10 ` Daniel P. Berrange [this message]
2014-06-02 11:13   ` Daniel P. Berrange
  -- strict thread matches above, loose matches on Subject: below --
2014-06-02 11:50 Gerd Hoffmann
2014-06-02 11:54 ` Daniel P. Berrange
2014-06-02 18:13 ` Richard Henderson

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=20140602111044.GD28039@redhat.com \
    --to=berrange@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=kraxel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.