Skip to contentSkip to conversation

handling guest multiple displays

PATCH Superseded Dongwon Kim 2 participants 5 messages Jun 15, 2022 – Jun 21, 2022

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover handling guest multiple displays

This patch seires is for adding some useful features for the guest os with multi-displays. First patch is to make all of guest displays visible when guest os is launched using "detach". Second patch is for providing a method to assign each guest display to specific physical monitor, which would be useful if someone wants to directly full-screen individual guest scanouts to host's physical displays.

Changes in v2:

* ui/gtk: detach VCS for additional guest displays

- check if the type of VC is GD_VC_GFX before qemu_console_is_graphic (Gerd Hoffman)
- vc[0] is always primary guest display so we won't need n_gfx_vcs (Gerd Hoffmann)
- making sure detached window's size same as original surface size (Daniel P. Berrangé)

Dongwon Kim (2):
ui/gtk: detach VCS for additional guest displays (v2) ui/gtk: a new array param monitor to specify the target displays (v2)

 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 43 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 48 insertions(+), 4 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/2 ui/gtk: detach VCS for additional guest displays

Detaching any addtional guest displays in case there are multiple displays assigned to the guest OS (e.g. max_outputs=n) so that all of them are visible upon lauching.

v2: - check if the type of VC is GD_VC_GFX before qemu_console_is_graphic
(Gerd Hoffman)
- vc[0] is always primary guest display so we won't need n_gfx_vcs (Gerd Hoffmann)
- making sure detached window's size same as original surface size (Daniel P. Berrangé)

Cc Daniel P. Berrangé <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 ui/gtk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
ui/gtk.c +12 -1
index 2a791dd2aa..e6878c3209 100644
@@ -1361,6 +1361,11 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
 
         g_signal_connect(vc->window, "delete-event",
                          G_CALLBACK(gd_tab_window_close), vc);
+
+        gtk_window_set_default_size(GTK_WINDOW(vc->window),
+                                    surface_width(vc->gfx.ds),
+                                    surface_height(vc->gfx.ds));
+
         gtk_widget_show_all(vc->window);
 
         if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
@@ -2311,6 +2316,7 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     GtkDisplayState *s = g_malloc0(sizeof(*s));
     GdkDisplay *window_display;
     GtkIconTheme *theme;
+    int i;
     char *dir;
 
     if (!gtkinit) {
@@ -2381,7 +2387,12 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     gtk_widget_set_sensitive(s->copy_item,
                              vc && vc->type == GD_VC_VTE);
 #endif
-
+    for (i = 1; i < s->nb_vcs; i++) {
+        if (vc->type == GD_VC_GFX &&
+            qemu_console_is_graphic(s->vc[i].gfx.dcl.con)) {
+            gtk_menu_item_activate(GTK_MENU_ITEM(s->untabify_item));
+        }
+    }
     if (opts->has_full_screen &&
         opts->full_screen) {
         gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/2 ui/gtk: a new array param monitor to specify the target displays

In reply to Dongwon Kim

New integer array parameter, 'monitor' is for specifying the target displays where individual QEMU windows are placed upon launching.

The array contains a series of numbers representing the monitor where QEMU windows are placed.

Numbers in the array are mapped to QEMU windows like,

[1st detached window, 2nd detached window,.... Main window]

Usage example: -display gtk,monitor.0=0,monitor.1=1.....

Cc Daniel P. Berrangé <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 3 deletions(-)
qapi/ui.json +6 -1
index 413371d5e8..5980f30c7f 100644
@@ -1195,12 +1195,17 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
+# @monitor:     Array of numbers, each of which represents physical
+#               monitor where individual QEMU window is placed in case
+#               there are multiple of them
+#               since 7.1
 #
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+                '*monitor'       : ['uint16']  } }
 
 ##
 # @DisplayEGLHeadless:
qemu-options.hx +1 -1
index 377d22fbd8..f79f533e9d 100644
@@ -1938,7 +1938,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #endif
 #if defined(CONFIG_GTK)
     "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
-    "            [,show-cursor=on|off][,window-close=on|off]\n"
+    "            [,monitor.<order>=<value>][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
ui/gtk.c +31 -1
index e6878c3209..fc9bf04680 100644
@@ -2316,6 +2316,10 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     GtkDisplayState *s = g_malloc0(sizeof(*s));
     GdkDisplay *window_display;
     GtkIconTheme *theme;
+    GtkWidget *win;
+    GdkRectangle dest;
+    uint16List *mon;
+    int n_mon;
     int i;
     char *dir;
 
@@ -2393,7 +2397,33 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
             gtk_menu_item_activate(GTK_MENU_ITEM(s->untabify_item));
         }
     }
-    if (opts->has_full_screen &&
+    if (opts->u.gtk.has_monitor) {
+        i = 0;
+        n_mon = gdk_display_get_n_monitors(window_display);
+        for (mon = opts->u.gtk.monitor; mon; mon = mon->next) {
+            if (mon->value < n_mon) {
+                for (; i < s->nb_vcs; i++) {
+                    win = s->vc[i].window ? s->vc[i].window : s->window;
+                    if (opts->has_full_screen && opts->full_screen) {
+                        gtk_window_fullscreen_on_monitor(
+                            GTK_WINDOW(win),
+                            gdk_display_get_default_screen(window_display),
+                            mon->value);
+                    } else {
+                        gdk_monitor_get_geometry(
+                            gdk_display_get_monitor(window_display, mon->value),
+                            &dest);
+                        gtk_window_move(GTK_WINDOW(win),
+                                        dest.x, dest.y);
+                    }
+                    i++;
+                    break;
+                }
+            }
+        }
+    }
+    if (!opts->u.gtk.has_monitor &&
+        opts->has_full_screen &&
         opts->full_screen) {
         gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
     }
Signature · 1 line
2.30.2
#3 lore raw

Re: [PATCH v2 2/2] ui/gtk: a new array param monitor to specify the target displays

Quoted 30 lines · Dongwon Kim

New integer array parameter, 'monitor' is for specifying the target displays where individual QEMU windows are placed upon launching.

The array contains a series of numbers representing the monitor where QEMU windows are placed.

Numbers in the array are mapped to QEMU windows like,

[1st detached window, 2nd detached window,.... Main window]

Usage example: -display gtk,monitor.0=0,monitor.1=1.....

Cc Daniel P. Berrangé <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 3 deletions(-)
qapi/ui.json +0 -0
index 413371d5e8..5980f30c7f 100644

qapi/ui.json line 1200

Quoted 6 lines
qapi/ui.json +3 -0
@@ -1195,12 +1195,17 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
+# @monitor:     Array of numbers, each of which represents physical
+#               monitor where individual QEMU window is placed in case
+#               there are multiple of them

End you sentence with a period, and ...

qapi/ui.json line 1201

Quoted 1 line
qapi/ui.json +1 -0
+#               since 7.1

... start the next phrase with a capital letter.

The documentation text feels vague. Possibly because I lack familiarity with this part of the user interface. What are the "individual QEMU windows"? How are they numbered?

Quoted 56 lines
qapi/ui.json +2 -1
 #
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+                '*monitor'       : ['uint16']  } }
 
 ##
 # @DisplayEGLHeadless:
qemu-options.hx +1 -1
index 377d22fbd8..f79f533e9d 100644
@@ -1938,7 +1938,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #endif
 #if defined(CONFIG_GTK)
     "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
-    "            [,show-cursor=on|off][,window-close=on|off]\n"
+    "            [,monitor.<order>=<value>][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
ui/gtk.c +16 -1
index e6878c3209..fc9bf04680 100644
@@ -2316,6 +2316,10 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     GtkDisplayState *s = g_malloc0(sizeof(*s));
     GdkDisplay *window_display;
     GtkIconTheme *theme;
+    GtkWidget *win;
+    GdkRectangle dest;
+    uint16List *mon;
+    int n_mon;
     int i;
     char *dir;
 
@@ -2393,7 +2397,33 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
             gtk_menu_item_activate(GTK_MENU_ITEM(s->untabify_item));
         }
     }
-    if (opts->has_full_screen &&
+    if (opts->u.gtk.has_monitor) {
+        i = 0;
+        n_mon = gdk_display_get_n_monitors(window_display);
+        for (mon = opts->u.gtk.monitor; mon; mon = mon->next) {
+            if (mon->value < n_mon) {
+                for (; i < s->nb_vcs; i++) {
+                    win = s->vc[i].window ? s->vc[i].window : s->window;
+                    if (opts->has_full_screen && opts->full_screen) {
+                        gtk_window_fullscreen_on_monitor(
+                            GTK_WINDOW(win),
+                            gdk_display_get_default_screen(window_display),
+                            mon->value);

ui/gtk.c static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) · line 2421

Quoted 10 lines
ui/gtk.c +10 -0
+                    } else {
+                        gdk_monitor_get_geometry(
+                            gdk_display_get_monitor(window_display, mon->value),
+                            &dest);
+                        gtk_window_move(GTK_WINDOW(win),
+                                        dest.x, dest.y);
+                    }
+                    i++;
+                    break;
+                }

This loop is odd. It's of the form

                   for (; COND; STEP) {
                       ...
                       break;
                   }

STEP is unreachable. The whole thing boils down to

                   if (COND) {
                       ....
                   }

doesn't it?

ui/gtk.c static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) · line 2429

Quoted 8 lines
ui/gtk.c +5 -0
+            }
+        }
+    }
+    if (!opts->u.gtk.has_monitor &&
+        opts->has_full_screen &&
         opts->full_screen) {
         gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
     }

This is

       if (COND1) {
           ...
       }
       if (!COND1 && COND2) {
           ...
       }

I'd prefer

       if (COND1) {
           ...
       } else if (COND2) {
           ...
       }
#4 lore raw

Re: [PATCH v2 2/2] ui/gtk: a new array param monitor to specify the target displays

Hi Markus,

Quoted 41 lines · Markus Armbruster
Quoted 30 lines · Dongwon Kim

New integer array parameter, 'monitor' is for specifying the target displays where individual QEMU windows are placed upon launching.

The array contains a series of numbers representing the monitor where QEMU windows are placed.

Numbers in the array are mapped to QEMU windows like,

[1st detached window, 2nd detached window,.... Main window]

Usage example: -display gtk,monitor.0=0,monitor.1=1.....

Cc Daniel P. Berrangé <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 3 deletions(-)
qapi/ui.json +0 -0
index 413371d5e8..5980f30c7f 100644

qapi/ui.json line 1200

Quoted 6 lines
qapi/ui.json +3 -0
@@ -1195,12 +1195,17 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
+# @monitor:     Array of numbers, each of which represents physical
+#               monitor where individual QEMU window is placed in case
+#               there are multiple of them

End you sentence with a period, and ...

Quoted 8 lines

qapi/ui.json line 1201

Quoted 1 line
qapi/ui.json +1 -0
+#               since 7.1

... start the next phrase with a capital letter.

The documentation text feels vague. Possibly because I lack familiarity with this part of the user interface. What are the "individual QEMU windows"? How are they numbered?

Will rework on the phrase. So there is only one QEMU window normally when you start the guest os. And this window usually contains multiple virtual consoles by default. You can detach any of them by clicking detach menu item from UI. In this case, a new window will be created for the detached VC. By doing this, we could have primary window and newly created n number of windows. Individual windows means these windows.

In this patch, VC number is being used as windows number. The primary one - guest display is '0'. The guest's secondary display will be '1' and so on.

Thanks for the feedback.

Quoted 74 lines
Quoted 56 lines
qapi/ui.json +2 -1
 #
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+                '*monitor'       : ['uint16']  } }
 
 ##
 # @DisplayEGLHeadless:
qemu-options.hx +1 -1
index 377d22fbd8..f79f533e9d 100644
@@ -1938,7 +1938,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #endif
 #if defined(CONFIG_GTK)
     "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
-    "            [,show-cursor=on|off][,window-close=on|off]\n"
+    "            [,monitor.<order>=<value>][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
ui/gtk.c +16 -1
index e6878c3209..fc9bf04680 100644
@@ -2316,6 +2316,10 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     GtkDisplayState *s = g_malloc0(sizeof(*s));
     GdkDisplay *window_display;
     GtkIconTheme *theme;
+    GtkWidget *win;
+    GdkRectangle dest;
+    uint16List *mon;
+    int n_mon;
     int i;
     char *dir;
 
@@ -2393,7 +2397,33 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
             gtk_menu_item_activate(GTK_MENU_ITEM(s->untabify_item));
         }
     }
-    if (opts->has_full_screen &&
+    if (opts->u.gtk.has_monitor) {
+        i = 0;
+        n_mon = gdk_display_get_n_monitors(window_display);
+        for (mon = opts->u.gtk.monitor; mon; mon = mon->next) {
+            if (mon->value < n_mon) {
+                for (; i < s->nb_vcs; i++) {
+                    win = s->vc[i].window ? s->vc[i].window : s->window;
+                    if (opts->has_full_screen && opts->full_screen) {
+                        gtk_window_fullscreen_on_monitor(
+                            GTK_WINDOW(win),
+                            gdk_display_get_default_screen(window_display),
+                            mon->value);

ui/gtk.c static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) · line 2421

Quoted 10 lines
ui/gtk.c +10 -0
+                    } else {
+                        gdk_monitor_get_geometry(
+                            gdk_display_get_monitor(window_display, mon->value),
+                            &dest);
+                        gtk_window_move(GTK_WINDOW(win),
+                                        dest.x, dest.y);
+                    }
+                    i++;
+                    break;
+                }

This loop is odd. It's of the form

                   for (; COND; STEP) {
                       ...
                       break;
                   }
Quoted 7 lines

STEP is unreachable. The whole thing boils down to

                   if (COND) {
                       ....
                   }

doesn't it?

You are definitely right. if (COND) should be the one here. I will fix this in the next version.

Quoted 20 lines

ui/gtk.c static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) · line 2429

Quoted 9 lines
ui/gtk.c +5 -0
+            }
+        }
+    }
+    if (!opts->u.gtk.has_monitor &&
+        opts->has_full_screen &&
         opts->full_screen) {
         gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
     }

This is

       if (COND1) {
           ...
       }
       if (!COND1 && COND2) {
           ...
       }
Quoted 8 lines

I'd prefer

       if (COND1) {
           ...
       } else if (COND2) {
           ...
       }

I will take a look at this as well.