All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Khor, Swee Aun" <swee.aun.khor@intel.com>
To: qemu-devel@nongnu.org
Cc: swee.aun.khor@intel.com, khairul.anuar.romli@intel.com,
	Hazwan.Arif.Mazlan@intel.com, vivek.kasireddy@intel.com,
	armbru@redhat.com, kraxel@redhat.com, eblake@redhat.com
Subject: [PATCH v5] ui/gtk: New -display gtk option 'full-screen-on-monitor'.
Date: Fri, 25 Jun 2021 16:24:32 +0800	[thread overview]
Message-ID: <20210625082432.55842-1-swee.aun.khor@intel.com> (raw)

This lets user select monitor number to display QEMU in full screen
with -display gtk,full-screen-on-monitor=<value>.

v2:
 - https://patchew.org/QEMU/20210617020609.18089-1-swee.aun.khor@intel.com/.
 - Added documentation for new member.
 - Renamed member name from monitor-num to monitor.

v3:
- Changed commit message subject.
- Cleaned up signed-off format.
- Renamed member name from monitor to full-screen-on-monitor to make clear this option automatically enables full screen.
- Added more detail documentation to specify full-screen-on-monitor option index started from 1.
- Added code to check windows has been launched successfully at specified monitor.

v4:
- Used PRId64 format specifier for int64_t variable in warn_report().

v5:
- Removed gdk_screen and gdk_monitor variables as it used once only.
- Fixed issue where v3 and v4 doesn't showing up in https://patchew.org/QEMU/.

Signed-off-by: Khor Swee Aun <swee.aun.khor@intel.com>
---
 qapi/ui.json    | 10 +++++++---
 qemu-options.hx |  2 +-
 ui/gtk.c        | 30 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 1052ca9c38..d775c29534 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1035,13 +1035,17 @@
 #               assuming the guest will resize the display to match
 #               the window size then.  Otherwise it defaults to "off".
 #               Since 3.1
-#
+# @full-screen-on-monitor: Monitor number to display QEMU in full screen.
+#                          Monitor number started from index 1. If total number
+#                          of monitors is 3, possible values for this option are
+#                          1, 2 or 3.
 # Since: 2.12
 #
 ##
 { 'struct'  : 'DisplayGTK',
-  'data'    : { '*grab-on-hover' : 'bool',
-                '*zoom-to-fit'   : 'bool'  } }
+  'data'    : { '*grab-on-hover'          : 'bool',
+                '*zoom-to-fit'            : 'bool',
+                '*full-screen-on-monitor' : 'int' } }
 
 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index 14258784b3..29836db663 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][,full-screen-on-monitor=<value>]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
diff --git a/ui/gtk.c b/ui/gtk.c
index 98046f577b..4da904a024 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2189,6 +2189,8 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     GdkDisplay *window_display;
     GtkIconTheme *theme;
     char *dir;
+    int monitor_n;
+    bool monitor_status = false;
 
     if (!gtkinit) {
         fprintf(stderr, "gtk initialization failed\n");
@@ -2268,6 +2270,34 @@ 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_full_screen_on_monitor) {
+        monitor_n = gdk_display_get_n_monitors(window_display);
+
+        if (opts->u.gtk.full_screen_on_monitor <= monitor_n &&
+            opts->u.gtk.full_screen_on_monitor > 0) {
+            gtk_window_fullscreen_on_monitor(GTK_WINDOW(s->window),
+                gdk_display_get_default_screen(window_display),
+                opts->u.gtk.full_screen_on_monitor - 1);
+
+            if (gdk_display_get_monitor(window_display,
+                                        opts->u.gtk.full_screen_on_monitor
+                                        - 1) != NULL) {
+                monitor_status = true;
+            }
+        }
+        if (monitor_status == false) {
+            /*
+             * Calling GDK API to read the number of monitors again in case
+             * monitor added or removed since last read.
+             */
+            monitor_n = gdk_display_get_n_monitors(window_display);
+            warn_report("Failed to enable full screen on monitor %" PRId64 ". "
+                        "Current total number of monitors is %d, "
+                        "please verify full-screen-on-monitor option value.",
+                        opts->u.gtk.full_screen_on_monitor, monitor_n);
+        }
+    }
 }
 
 static void early_gtk_display_init(DisplayOptions *opts)
-- 
2.24.3



             reply	other threads:[~2021-06-25  8:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25  8:24 Khor, Swee Aun [this message]
2021-07-08 15:48 ` [PATCH v5] ui/gtk: New -display gtk option 'full-screen-on-monitor' Markus Armbruster
2021-07-28  3:19   ` Romli, Khairul Anuar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210625082432.55842-1-swee.aun.khor@intel.com \
    --to=swee.aun.khor@intel.com \
    --cc=Hazwan.Arif.Mazlan@intel.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=khairul.anuar.romli@intel.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vivek.kasireddy@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.