-display gtk,monitor-num=<value>

Signed-off-by: sweeaun <swee.aun.k...@intel.com>
---
 qapi/ui.json    |  3 ++-
 qemu-options.hx |  2 +-
 ui/gtk.c        | 15 +++++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 1052ca9c38..c3363c7ad5 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1041,7 +1041,8 @@
 ##
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+                '*zoom-to-fit'   : 'bool',
+               '*monitor-num' : 'int' } }
 
 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index 14258784b3..6bd524c8c2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1787,7 +1787,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
     "            [,window_close=on|off][,gl=on|core|es|off]\n"
 #endif
 #if defined(CONFIG_GTK)
-    "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n"
+    "-display gtk[,grab_on_hover=on|off][,gl=on|off][,monitor-num=<value>]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
diff --git a/ui/gtk.c b/ui/gtk.c
index 98046f577b..0716b3abbc 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2268,6 +2268,21 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
         gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_on_hover_item));
     }
     gd_clipboard_init(s);
+
+    if (opts->u.gtk.has_monitor_num) {
+        int n_monitor;
+        n_monitor = gdk_display_get_n_monitors(window_display);
+
+        if ((opts->u.gtk.monitor_num <= n_monitor) &&
+            (opts->u.gtk.monitor_num > 0)) {
+            GdkScreen *gdk_screen;
+            gdk_screen = gdk_display_get_default_screen(window_display);
+            gtk_window_fullscreen_on_monitor(GTK_WINDOW(s->window), gdk_screen,
+                                             (opts->u.gtk.monitor_num - 1));
+        } else {
+            fprintf(stderr, "Invalid GTK monitor-num argument\n");
+        }
+    }
 }
 
 static void early_gtk_display_init(DisplayOptions *opts)
-- 
2.24.3


Reply via email to