diff mbox

[4/4] gtk: set window ID

Message ID 20161031160007.6047-5-samuel.thibault@ens-lyon.org (mailing list archive)
State New, archived
Headers show

Commit Message

Samuel Thibault Oct. 31, 2016, 4 p.m. UTC
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(-)

Comments

Samuel Thibault Oct. 31, 2016, 4:01 p.m. UTC | #1
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
Daniel P. Berrangé Oct. 31, 2016, 4:59 p.m. UTC | #2
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
diff mbox

Patch

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)