qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCHv3 0/4] Move getting XWindow ID from baum driver to graphical backend
@ 2016-10-31 16:00 Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID Samuel Thibault
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Samuel Thibault @ 2016-10-31 16:00 UTC (permalink / raw)
  To: qemu-devel, kraxel; +Cc: Samuel Thibault

Hello,

This is a respin of moving getting XWindow ID from baum to actual
graphical backends.  This only contains the new API, the move
of existing code to the new API, and the addition of support for
SDL2. Gtk will need more discussion and work.

Compared to v2, this fixes build on 64bit windows, where the window
handle needs to be explictly truncated to 32bit (such handles are
guaranteed to be 32bit)

Samuel

Samuel Thibault (4):
  console: add API to get underlying gui window ID
  console: move window ID code from baum to sdl
  sdl2: set window ID
  gtk: set window ID

 backends/baum.c      | 25 +++----------------------
 include/ui/console.h |  3 +++
 ui/console.c         | 15 +++++++++++++++
 ui/gtk.c             | 25 +++++++++++++++++++++++--
 ui/sdl.c             | 25 +++++++++++++++++++++++++
 ui/sdl2.c            |  7 +++++++
 6 files changed, 76 insertions(+), 24 deletions(-)

-- 
2.10.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID
  2016-10-31 16:00 [Qemu-devel] [PATCHv3 0/4] Move getting XWindow ID from baum driver to graphical backend Samuel Thibault
@ 2016-10-31 16:00 ` Samuel Thibault
  2016-11-01 10:11   ` Gerd Hoffmann
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 2/4] console: move window ID code from baum to sdl Samuel Thibault
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Samuel Thibault @ 2016-10-31 16:00 UTC (permalink / raw)
  To: qemu-devel, kraxel; +Cc: Samuel Thibault

This adds two console functions, qemu_console_set_window_id and
qemu_graphic_console_get_window_id, to let graphical backend record the
window id in the QemuConsole structure, and let the baum driver read it.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 include/ui/console.h |  3 +++
 ui/console.c         | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index e2589e2..cf07e41 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -394,6 +394,9 @@ uint32_t qemu_console_get_head(QemuConsole *con);
 QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
 int qemu_console_get_width(QemuConsole *con, int fallback);
 int qemu_console_get_height(QemuConsole *con, int fallback);
+/* Return the low-level window id for the first graphical console */
+int qemu_graphic_console_get_window_id(void);
+void qemu_console_set_window_id(int index, int window_id);
 
 void console_select(unsigned int index);
 void qemu_console_resize(QemuConsole *con, int width, int height);
diff --git a/ui/console.c b/ui/console.c
index ed888e5..aa3c4c7 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -124,6 +124,7 @@ struct QemuConsole {
     int dcls;
     DisplayChangeListener *gl;
     bool gl_block;
+    int window_id;
 
     /* Graphic console state.  */
     Object *device;
@@ -273,6 +274,20 @@ void graphic_hw_gl_block(QemuConsole *con, bool block)
     }
 }
 
+int qemu_graphic_console_get_window_id(void)
+{
+    if (consoles[0]->console_type == GRAPHIC_CONSOLE) {
+        return consoles[0]->window_id;
+    }
+    return -1;
+}
+
+void qemu_console_set_window_id(int index, int window_id)
+{
+    assert(index >= 0 && index < nb_consoles);
+    consoles[index]->window_id = window_id;
+}
+
 void graphic_hw_invalidate(QemuConsole *con)
 {
     if (!con) {
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/4] console: move window ID code from baum to sdl
  2016-10-31 16:00 [Qemu-devel] [PATCHv3 0/4] Move getting XWindow ID from baum driver to graphical backend Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID Samuel Thibault
@ 2016-10-31 16:00 ` Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 3/4] sdl2: set window ID Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 4/4] gtk: " Samuel Thibault
  3 siblings, 0 replies; 8+ messages in thread
From: Samuel Thibault @ 2016-10-31 16:00 UTC (permalink / raw)
  To: qemu-devel, kraxel; +Cc: Samuel Thibault

This moves the SDL bits for window ID from the baum driver to SDL, as
well as fixing the build for non-X11.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 backends/baum.c | 25 +++----------------------
 ui/sdl.c        | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/backends/baum.c b/backends/baum.c
index b92369d..5d7d27c 100644
--- a/backends/baum.c
+++ b/backends/baum.c
@@ -27,12 +27,10 @@
 #include "sysemu/char.h"
 #include "qemu/timer.h"
 #include "hw/usb.h"
+#include "ui/console.h"
 #include <brlapi.h>
 #include <brlapi_constants.h>
 #include <brlapi_keycodes.h>
-#ifdef CONFIG_SDL
-#include <SDL_syswm.h>
-#endif
 
 #if 0
 #define DPRINTF(fmt, ...) \
@@ -227,11 +225,6 @@ static const uint8_t nabcc_translation[2][256] = {
 /* The guest OS has started discussing with us, finish initializing BrlAPI */
 static int baum_deferred_init(BaumDriverState *baum)
 {
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
-    SDL_SysWMinfo info;
-#endif
-#endif
     int tty;
 
     if (baum->deferred_init) {
@@ -243,21 +236,9 @@ static int baum_deferred_init(BaumDriverState *baum)
         return 0;
     }
 
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
-    memset(&info, 0, sizeof(info));
-    SDL_VERSION(&info.version);
-    if (SDL_GetWMInfo(&info)) {
-        tty = info.info.x11.wmwindow;
-    } else {
-#endif
-#endif
+    tty = qemu_graphic_console_get_window_id();
+    if (tty == -1)
         tty = BRLAPI_TTY_DEFAULT;
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
-    }
-#endif
-#endif
 
     if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) {
         brlapi_perror("baum: brlapi__enterTtyMode");
diff --git a/ui/sdl.c b/ui/sdl.c
index d8cf5bc..8d9d171 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -947,6 +947,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     int flags;
     uint8_t data = 0;
     const SDL_VideoInfo *vi;
+    SDL_SysWMinfo info;
     char *filename;
 
 #if defined(__APPLE__)
@@ -1023,5 +1024,29 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
     sdl_cursor_normal = SDL_GetCursor();
 
+    memset(&info, 0, sizeof(info));
+    SDL_VERSION(&info.version);
+    if (SDL_GetWMInfo(&info)) {
+        int i;
+        for (i = 0; ; i++) {
+            /* All consoles share the same window */
+            QemuConsole *con = qemu_console_lookup_by_index(i);
+            if (con) {
+#if defined(SDL_VIDEO_DRIVER_X11)
+                qemu_console_set_window_id(i, info.info.x11.wmwindow);
+#elif defined(SDL_VIDEO_DRIVER_NANOX) || \
+      defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || \
+      defined(SDL_VIDEO_DRIVER_GAPI) || \
+      defined(SDL_VIDEO_DRIVER_RISCOS)
+                qemu_console_set_window_id(i, (int) (uintptr_t) info.window);
+#else
+                qemu_console_set_window_id(i, info.data);
+#endif
+            } else {
+                break;
+            }
+        }
+    }
+
     atexit(sdl_cleanup);
 }
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/4] sdl2: set window ID
  2016-10-31 16:00 [Qemu-devel] [PATCHv3 0/4] Move getting XWindow ID from baum driver to graphical backend Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 2/4] console: move window ID code from baum to sdl Samuel Thibault
@ 2016-10-31 16:00 ` Samuel Thibault
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 4/4] gtk: " Samuel Thibault
  3 siblings, 0 replies; 8+ messages in thread
From: Samuel Thibault @ 2016-10-31 16:00 UTC (permalink / raw)
  To: qemu-devel, kraxel; +Cc: Samuel Thibault

This uses the console API to record the window ID of the SDL2 windows.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 ui/sdl2.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 30d2a3c..b464f16 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -761,6 +761,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     uint8_t data = 0;
     char *filename;
     int i;
+    SDL_SysWMinfo info;
 
     if (no_frame) {
         gui_noframe = 1;
@@ -786,6 +787,8 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
         exit(1);
     }
     SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
+    memset(&info, 0, sizeof(info));
+    SDL_VERSION(&info.version);
 
     for (i = 0;; i++) {
         QemuConsole *con = qemu_console_lookup_by_index(i);
@@ -813,6 +816,10 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 #endif
         sdl2_console[i].dcl.con = con;
         register_displaychangelistener(&sdl2_console[i].dcl);
+
+        if (SDL_GetWindowWMInfo(sdl2_console[i].real_window, &info)) {
+            qemu_console_set_window_id(i, info.info.x11.window);
+        }
     }
 
     /* Load a 32x32x4 image. White pixels are transparent. */
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 4/4] gtk: set window ID
  2016-10-31 16:00 [Qemu-devel] [PATCHv3 0/4] Move getting XWindow ID from baum driver to graphical backend Samuel Thibault
                   ` (2 preceding siblings ...)
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 3/4] sdl2: set window ID Samuel Thibault
@ 2016-10-31 16:00 ` Samuel Thibault
  2016-10-31 16:01   ` Samuel Thibault
  2016-10-31 16:59   ` Daniel P. Berrange
  3 siblings, 2 replies; 8+ messages in thread
From: Samuel Thibault @ 2016-10-31 16:00 UTC (permalink / raw)
  To: qemu-devel, kraxel; +Cc: Samuel Thibault

This uses the console API to record the window ID of the GTK windows.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 ui/gtk.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index ca737c4..d75f255 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2170,6 +2170,13 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
     GtkDisplayState *s = g_malloc0(sizeof(*s));
     char *filename;
     GdkDisplay *window_display;
+    GdkWindow *gdk_window;
+#ifdef GDK_WINDOWING_X11
+    Window window_id;
+#elif defined(GDK_WINDOWING_WIN32)
+    HWND window_id;
+#endif
+    int i;
 
     if (!gtkinit) {
         fprintf(stderr, "gtk initialization failed\n");
@@ -2232,8 +2239,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
     {
         VirtualConsole *cur = gd_vc_find_current(s);
         if (cur) {
-            int i;
-
             for (i = 0; i < s->nb_vcs; i++) {
                 VirtualConsole *vc = &s->vc[i];
                 if (vc && vc->type == GD_VC_VTE && vc != cur) {
@@ -2253,6 +2258,22 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
     }
 
     gd_set_keycode_type(s);
+
+    gdk_window = gtk_widget_get_window(s->window);
+#ifdef GDK_WINDOWING_X11
+    window_id = GDK_WINDOW_XID(gdk_window);
+#elif defined(GDK_WINDOWING_WIN32)
+    window_id = gdk_win32_window_get_impl_hwnd(gdk_window);
+#endif
+    for (i = 0; ; i++) {
+        /* All consoles share the same window */
+        QemuConsole *con = qemu_console_lookup_by_index(i);
+        if (con) {
+            qemu_console_set_window_id(i, (int) window_id);
+        } else {
+            break;
+        }
+    }
 }
 
 void early_gtk_display_init(int opengl)
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] gtk: set window ID
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 4/4] gtk: " Samuel Thibault
@ 2016-10-31 16:01   ` Samuel Thibault
  2016-10-31 16:59   ` Daniel P. Berrange
  1 sibling, 0 replies; 8+ messages in thread
From: Samuel Thibault @ 2016-10-31 16:01 UTC (permalink / raw)
  To: qemu-devel, kraxel

Samuel Thibault, on Mon 31 Oct 2016 17:00:07 +0100, wrote:
> This uses the console API to record the window ID of the GTK windows.

Ah, sorry, I let this one through, please ignore it, it'll need rework
as discussed in the other thread.

Samuel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] gtk: set window ID
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 4/4] gtk: " Samuel Thibault
  2016-10-31 16:01   ` Samuel Thibault
@ 2016-10-31 16:59   ` Daniel P. Berrange
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel P. Berrange @ 2016-10-31 16:59 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: qemu-devel, kraxel

On Mon, Oct 31, 2016 at 05:00:07PM +0100, Samuel Thibault wrote:
> This uses the console API to record the window ID of the GTK windows.
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
>  ui/gtk.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/ui/gtk.c b/ui/gtk.c
> index ca737c4..d75f255 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -2170,6 +2170,13 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
>      GtkDisplayState *s = g_malloc0(sizeof(*s));
>      char *filename;
>      GdkDisplay *window_display;
> +    GdkWindow *gdk_window;
> +#ifdef GDK_WINDOWING_X11
> +    Window window_id;
> +#elif defined(GDK_WINDOWING_WIN32)
> +    HWND window_id;
> +#endif
> +    int i;
>  
>      if (!gtkinit) {
>          fprintf(stderr, "gtk initialization failed\n");
> @@ -2232,8 +2239,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
>      {
>          VirtualConsole *cur = gd_vc_find_current(s);
>          if (cur) {
> -            int i;
> -
>              for (i = 0; i < s->nb_vcs; i++) {
>                  VirtualConsole *vc = &s->vc[i];
>                  if (vc && vc->type == GD_VC_VTE && vc != cur) {
> @@ -2253,6 +2258,22 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
>      }
>  
>      gd_set_keycode_type(s);
> +
> +    gdk_window = gtk_widget_get_window(s->window);
> +#ifdef GDK_WINDOWING_X11
> +    window_id = GDK_WINDOW_XID(gdk_window);
> +#elif defined(GDK_WINDOWING_WIN32)
> +    window_id = gdk_win32_window_get_impl_hwnd(gdk_window);
> +#endif

There are other GTK3 backends that may well be used - Wayland, Broadway
and Quartz. You can't use the compile time check on its own any more as
a single GTK can be built with multiple backends at once.

So to fully generalize you need
eg you'll need

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

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

    #ifdef GDK_WINDOWING_QUARTZ
    if (GDK_IS_QUARTZ_DISPLAY(dpy)) {
       ...
    }
    #endif

    ...and wayland, broadway...

> +    for (i = 0; ; i++) {
> +        /* All consoles share the same window */
> +        QemuConsole *con = qemu_console_lookup_by_index(i);
> +        if (con) {
> +            qemu_console_set_window_id(i, (int) window_id);
> +        } else {
> +            break;
> +        }
> +    }

If neither X11 or Win32 backends are defined, this will error
since window_id will not be declared.

Regards,
Daniel
-- 
|: 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/ :|

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID
  2016-10-31 16:00 ` [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID Samuel Thibault
@ 2016-11-01 10:11   ` Gerd Hoffmann
  0 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2016-11-01 10:11 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: qemu-devel

>  int qemu_console_get_width(QemuConsole *con, int fallback);
>  int qemu_console_get_height(QemuConsole *con, int fallback);
> +/* Return the low-level window id for the first graphical console */
> +int qemu_graphic_console_get_window_id(void);
> +void qemu_console_set_window_id(int index, int window_id);

Both qemu_console_{set,get}_window_id should have a QemuConsole *con
argument, like the other ones.

There is also no reason to limit this interface to graphic consoles.
baum.c can use qemu_console_lookup_by_index() and
qemu_console_is_graphic() to implement this logic (sorry, missed this on
the first review).

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-11-01 10:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-31 16:00 [Qemu-devel] [PATCHv3 0/4] Move getting XWindow ID from baum driver to graphical backend Samuel Thibault
2016-10-31 16:00 ` [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID Samuel Thibault
2016-11-01 10:11   ` Gerd Hoffmann
2016-10-31 16:00 ` [Qemu-devel] [PATCH 2/4] console: move window ID code from baum to sdl Samuel Thibault
2016-10-31 16:00 ` [Qemu-devel] [PATCH 3/4] sdl2: set window ID Samuel Thibault
2016-10-31 16:00 ` [Qemu-devel] [PATCH 4/4] gtk: " Samuel Thibault
2016-10-31 16:01   ` Samuel Thibault
2016-10-31 16:59   ` Daniel P. Berrange

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).