[PATCH] ui/gtk: Allow user to select monitor number to display qemu in full screen through new gtk display option

sweeaun posted 1 patch 2 years, 10 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210614080542.5905-1-swee.aun.khor@intel.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Markus Armbruster <armbru@redhat.com>, Eric Blake <eblake@redhat.com>
There is a newer version of this series
qapi/ui.json    |  3 ++-
qemu-options.hx |  2 +-
ui/gtk.c        | 15 +++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
[PATCH] ui/gtk: Allow user to select monitor number to display qemu in full screen through new gtk display option
Posted by sweeaun 2 years, 10 months ago
 -display gtk,monitor-num=<value>

Signed-off-by: sweeaun <swee.aun.khor@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


Re: [PATCH] ui/gtk: Allow user to select monitor number to display qemu in full screen through new gtk display option
Posted by Eric Blake 2 years, 10 months ago
On Mon, Jun 14, 2021 at 04:05:42PM +0800, sweeaun wrote:
>  -display gtk,monitor-num=<value>
> 
> Signed-off-by: sweeaun <swee.aun.khor@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' } }

Missing documentation of the new member.  Also, get rid of the tab damage.


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


Re: [PATCH] ui/gtk: Allow user to select monitor number to display qemu in full screen through new gtk display option
Posted by Markus Armbruster 2 years, 10 months ago
Eric Blake <eblake@redhat.com> writes:

> On Mon, Jun 14, 2021 at 04:05:42PM +0800, sweeaun wrote:
>>  -display gtk,monitor-num=<value>
>> 
>> Signed-off-by: sweeaun <swee.aun.khor@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' } }
>
> Missing documentation of the new member.  Also, get rid of the tab damage.

Suggest to name it either @monitor-number or @monitor (because what else
than the number could 'int' be?)


RE: [PATCH] ui/gtk: Allow user to select monitor number to display qemu in full screen through new gtk display option
Posted by Khor, Swee Aun 2 years, 10 months ago
Thanks for review and feedback. I shall rework those in v2.

Regards,
SweeAun

-----Original Message-----
From: Markus Armbruster <armbru@redhat.com> 
Sent: Monday, June 14, 2021 11:01 PM
To: Eric Blake <eblake@redhat.com>
Cc: Khor, Swee Aun <swee.aun.khor@intel.com>; Romli, Khairul Anuar <khairul.anuar.romli@intel.com>; qemu-devel@nongnu.org; Kasireddy, Vivek <vivek.kasireddy@intel.com>
Subject: Re: [PATCH] ui/gtk: Allow user to select monitor number to display qemu in full screen through new gtk display option

Eric Blake <eblake@redhat.com> writes:

> On Mon, Jun 14, 2021 at 04:05:42PM +0800, sweeaun wrote:
>>  -display gtk,monitor-num=<value>
>> 
>> Signed-off-by: sweeaun <swee.aun.khor@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' } }
>
> Missing documentation of the new member.  Also, get rid of the tab damage.

Suggest to name it either @monitor-number or @monitor (because what else than the number could 'int' be?)