Skip to contentSkip to conversation

ui/gtk: mon_num parameter to specify target monitor for launching Qemu

PATCH Superseded Dongwon Kim 3 participants 4 messages Nov 18, 2021 – Nov 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/gtk: mon_num parameter to specify target monitor for launching Qemu

Introducing a new integer parameter to specify the monitor where the Qemu window is placed upon launching.

Monitor index can start from 0 to (total number of monitors - 1). Default value for the parameter is -1, which doesn't affect anything.

It can be used together with full-screen=on, which will make the Qemu window full-screened on the targetted monitor.

Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
Cc sweeaun <[email protected]>
Cc Khairul Anuar Romli <[email protected]>
---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 10 ++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
qapi/ui.json +6 -1
index d7567ac866..7552b503b2 100644
@@ -1099,13 +1099,18 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
+# @mon-num:     Indicate monitor where Qemu window is lauched. mon-num
+#               could be any number from -1 to (total num of monitors - 1).
+#               (default: -1: use default monitor)
+#               since 6.2
 #
 # Since: 2.12
 #
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+                '*mon-num'       : 'int' } }
 
 ##
 # @DisplayEGLHeadless:
qemu-options.hx +1 -1
index 7749f59300..7a888b16b1 100644
@@ -1852,7 +1852,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"
+    "            [,mon-num=<value>][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
ui/gtk.c +10 -0
index d2892ea6b4..8d8aa55822 100644
@@ -2314,6 +2314,16 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
                              vc && vc->type == GD_VC_VTE);
 #endif
 
+    if (opts->u.gtk.has_mon_num && opts->u.gtk.mon_num &&
+        opts->u.gtk.mon_num >= 0) {
+        GdkRectangle mon_dest;
+        if (opts->u.gtk.mon_num < gdk_display_get_n_monitors(window_display)) {
+            gdk_monitor_get_geometry(
+                gdk_display_get_monitor(window_display, opts->u.gtk.mon_num),
+                &mon_dest);
+            gtk_window_move(GTK_WINDOW(s->window), mon_dest.x, mon_dest.y);
+        }
+    }
     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
#1 lore raw
Quoted 7 lines · Dongwon Kim

Introducing a new integer parameter to specify the monitor where the Qemu window is placed upon launching.

Monitor index can start from 0 to (total number of monitors - 1). Default value for the parameter is -1, which doesn't affect anything.

It can be used together with full-screen=on, which will make the Qemu

"QEMU"

Quoted 1 line

window full-screened on the targetted monitor.

Typo "targeted"

Quoted 16 lines
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
Cc sweeaun <[email protected]>
Cc Khairul Anuar Romli <[email protected]>
---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 10 ++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
qapi/ui.json +0 -0
index d7567ac866..7552b503b2 100644

qapi/ui.json line 1105

Quoted 7 lines
qapi/ui.json +4 -0
@@ -1099,13 +1099,18 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
+# @mon-num:     Indicate monitor where Qemu window is lauched. mon-num
+#               could be any number from -1 to (total num of monitors - 1).
+#               (default: -1: use default monitor)
+#               since 6.2

I believe this is 7.0 material now, so "since 7.0".

Quoted 47 lines
qapi/ui.json +2 -1
 #
 # Since: 2.12
 #
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+                '*mon-num'       : 'int' } }
 
 ##
 # @DisplayEGLHeadless:
qemu-options.hx +1 -1
index 7749f59300..7a888b16b1 100644
@@ -1852,7 +1852,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"
+    "            [,mon-num=<value>][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
ui/gtk.c +10 -0
index d2892ea6b4..8d8aa55822 100644
@@ -2314,6 +2314,16 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
                              vc && vc->type == GD_VC_VTE);
 #endif
 
+    if (opts->u.gtk.has_mon_num && opts->u.gtk.mon_num &&
+        opts->u.gtk.mon_num >= 0) {
+        GdkRectangle mon_dest;
+        if (opts->u.gtk.mon_num < gdk_display_get_n_monitors(window_display)) {
+            gdk_monitor_get_geometry(
+                gdk_display_get_monitor(window_display, opts->u.gtk.mon_num),
+                &mon_dest);
+            gtk_window_move(GTK_WINDOW(s->window), mon_dest.x, mon_dest.y);
+        }
+    }
     if (opts->has_full_screen &&
         opts->full_screen) {
         gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
#2 lore raw
In reply to Dongwon Kim

qapi/ui.json line 1105

Quoted 4 lines · Dongwon Kim
qapi/ui.json +4 -0
+# @mon-num:     Indicate monitor where Qemu window is lauched. mon-num
+#               could be any number from -1 to (total num of monitors - 1).
+#               (default: -1: use default monitor)
+#               since 6.2

There is no need to accept -1; the opts->u.gtk struct uses a separate boolean field to indicate the default. Instead, the parameter should be an unsigned integer ("uint32").

Also please use "monitor", not "mon-num". We usually avoid abbreviations.

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

Quoted 2 lines
ui/gtk.c +2 -0
+    if (opts->u.gtk.has_mon_num && opts->u.gtk.mon_num &&
+        opts->u.gtk.mon_num >= 0) {

Rejecting 0 ("opts->u.gtk.mon_num") is incorrect. If you declare it as unsigned, you can just use "if (opts->u.gtk.has_mon_num").

Thanks,

Paolo

Quoted 12 lines
ui/gtk.c +8 -0
+        GdkRectangle mon_dest;
+        if (opts->u.gtk.mon_num < gdk_display_get_n_monitors(window_display)) {
+            gdk_monitor_get_geometry(
+                gdk_display_get_monitor(window_display, opts->u.gtk.mon_num),
+                &mon_dest);
+            gtk_window_move(GTK_WINDOW(s->window), mon_dest.x, mon_dest.y);
+        }
+    }
      if (opts->has_full_screen &&
          opts->full_screen) {
          gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
#3 lore raw

PATCH v2 1/1 ui/gtk: new param monitor to specify target monitor for launching QEMU

In reply to Dongwon Kim

Introducing a new integer parameter to specify the monitor where the Qemu window is placed upon launching.

Monitor can be any number between 0 and (total number of monitors - 1).

It can be used together with full-screen=on, which will make the QEMU window full-screened on the targeted monitor.

v2: fixed typos and updated commit subject and msg
(Philippe Mathieu-Daudé)

changed param name to monitor, removed unnecessary condition check on the parameter
(Paolo Bonzini)

Cc Philippe Mathieu-Daudé <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
Cc sweeaun <[email protected]>
Cc Khairul Anuar Romli <[email protected]>
---
 qapi/ui.json    | 6 +++++-
 qemu-options.hx | 2 +-
 ui/gtk.c        | 8 ++++++++
 3 files changed, 14 insertions(+), 2 deletions(-)
qapi/ui.json +5 -1
index d7567ac866..9dc1ad284f 100644
@@ -1099,13 +1099,17 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
+# @monitor:     Indicate monitor where QEMU window is lauched. monitor
+#               could be any number from 0 to (total num of monitors - 1).
+#               since 7.0
 #
 # Since: 2.12
 #
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+                '*monitor'       : 'uint32' } }
 
 ##
 # @DisplayEGLHeadless:
qemu-options.hx +1 -1
index 7749f59300..6d062b8aa1 100644
@@ -1852,7 +1852,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=<value>][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
ui/gtk.c +8 -0
index d2892ea6b4..7abe1a69d8 100644
@@ -2314,6 +2314,14 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
                              vc && vc->type == GD_VC_VTE);
 #endif
 
+    if (opts->u.gtk.has_monitor &&
+        opts->u.gtk.monitor < gdk_display_get_n_monitors(window_display)) {
+        GdkRectangle mon_dest;
+        gdk_monitor_get_geometry(
+            gdk_display_get_monitor(window_display, opts->u.gtk.monitor),
+            &mon_dest);
+        gtk_window_move(GTK_WINDOW(s->window), mon_dest.x, mon_dest.y);
+    }
     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