diff mbox series

[1/1] ui/gtk: Added a no-input mode

Message ID MW3PR11MB46848D06ADD48751C810EE769F9C9@MW3PR11MB4684.namprd11.prod.outlook.com
State New
Headers show
Series [1/1] ui/gtk: Added a no-input mode | expand

Commit Message

Satyeshwar Singh April 17, 2023, 11:02 p.m. UTC
In a multi-seat scenario where multiple keyboards and mice are connected
to the host but some are dedicated for the guests only (through pass
through mode) and some are only for the host, there is a strong use case
where a customer does not want a HID device connected to the host to be
able to control the guest.
In such a scenario, neither should we bind any input events to Qemu UI,
nor should we show menu options like "Grab on Hover" or "Grab Input".
This patch adds a GTK command line option called "no-input".
It can be set like this:
  gtk,no-input=off/on

If set to off or completely left out, it will default to normal
operation where host HID devices can control the guests. However, if
turned on, then host HID devices will not be able to control the guest
windows.

Signed-off-by: Satyeshwar Singh <satyeshwar.singh@intel.com>
Cc: Dongwon Kim <dongwon.kim@intel.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qapi/ui.json    |  5 ++++-
 qemu-options.hx |  4 +++-
 ui/gtk.c        | 39 +++++++++++++++++++++++++++------------
 3 files changed, 34 insertions(+), 14 deletions(-)

Comments

Daniel P. Berrangé April 18, 2023, 8:17 a.m. UTC | #1
On Mon, Apr 17, 2023 at 11:02:00PM +0000, Singh, Satyeshwar wrote:
> In a multi-seat scenario where multiple keyboards and mice are connected
> to the host but some are dedicated for the guests only (through pass
> through mode) and some are only for the host, there is a strong use case
> where a customer does not want a HID device connected to the host to be
> able to control the guest.
> In such a scenario, neither should we bind any input events to Qemu UI,
> nor should we show menu options like "Grab on Hover" or "Grab Input".
> This patch adds a GTK command line option called "no-input".
> It can be set like this:
>   gtk,no-input=off/on
> 
> If set to off or completely left out, it will default to normal
> operation where host HID devices can control the guests. However, if
> turned on, then host HID devices will not be able to control the guest
> windows.
> 
> Signed-off-by: Satyeshwar Singh <satyeshwar.singh@intel.com>
> Cc: Dongwon Kim <dongwon.kim@intel.com>
> Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  qapi/ui.json    |  5 ++++-
>  qemu-options.hx |  4 +++-
>  ui/gtk.c        | 39 +++++++++++++++++++++++++++------------
>  3 files changed, 34 insertions(+), 14 deletions(-)
> 
> diff --git a/qapi/ui.json b/qapi/ui.json
> index 98322342f7..cd3ef4678e 100644
> --- a/qapi/ui.json
> +++ b/qapi/ui.json
> @@ -1214,6 +1214,8 @@
>  #               Since 7.1
>  # @show-menubar: Display the main window menubar. Defaults to "on".
>  #                Since 8.0
> +# @no-input: Don't let host's HID devices control the guest. Defaults to "off".
> +#                Since 8.0
>  #
>  # Since: 2.12
>  ##
> @@ -1221,7 +1223,8 @@
>    'data'    : { '*grab-on-hover' : 'bool',
>                  '*zoom-to-fit'   : 'bool',
>                  '*show-tabs'     : 'bool',
> -                '*show-menubar'  : 'bool'  } }
> +                '*show-menubar'  : 'bool',
> +                '*no-input'      : 'bool'  } }

We don't generally like negative boolean options.

IOW, we would prefer '*input':  'bool'  with the default being
'on' if omitted, of course.

With regards,
Daniel
diff mbox series

Patch

diff --git a/qapi/ui.json b/qapi/ui.json
index 98322342f7..cd3ef4678e 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1214,6 +1214,8 @@ 
 #               Since 7.1
 # @show-menubar: Display the main window menubar. Defaults to "on".
 #                Since 8.0
+# @no-input: Don't let host's HID devices control the guest. Defaults to "off".
+#                Since 8.0
 #
 # Since: 2.12
 ##
@@ -1221,7 +1223,8 @@ 
   'data'    : { '*grab-on-hover' : 'bool',
                 '*zoom-to-fit'   : 'bool',
                 '*show-tabs'     : 'bool',
-                '*show-menubar'  : 'bool'  } }
+                '*show-menubar'  : 'bool',
+                '*no-input'      : 'bool'  } }
 
 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index 59bdf67a2c..a678f66c5d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1977,7 +1977,7 @@  DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_GTK)
     "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
     "            [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]\n"
-    "            [,show-menubar=on|off]\n"
+    "            [,show-menubar=on|off][,no-input=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
@@ -2072,6 +2072,8 @@  SRST
 
         ``show-menubar=on|off`` : Display the main window menubar, defaults to "on"
 
+        ``no-input=on|off`` : Don't let host's HID devices control the guest
+
     ``curses[,charset=<encoding>]``
         Display video output via curses. For graphics device models
         which support a text mode, QEMU can display this output using a
diff --git a/ui/gtk.c b/ui/gtk.c
index f16e0f8dee..e58f71358c 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1967,6 +1967,20 @@  static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
                          G_CALLBACK(gd_resize_event), vc);
     }
 #endif
+    if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
+        g_signal_connect(vc->gfx.drawing_area, "configure-event",
+                         G_CALLBACK(gd_configure), vc);
+    }
+
+    /*
+     * Don't configure input events if the user has provided an option
+     * for no-input, instead opting for passthrough HID devices to control the
+     * guest.
+     */
+    if (vc->s->opts->u.gtk.has_no_input && vc->s->opts->u.gtk.no_input ) {
+        return;
+    }
+
     if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
         g_signal_connect(vc->gfx.drawing_area, "event",
                          G_CALLBACK(gd_event), vc);
@@ -1989,8 +2003,6 @@  static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
                          G_CALLBACK(gd_focus_in_event), vc);
         g_signal_connect(vc->gfx.drawing_area, "focus-out-event",
                          G_CALLBACK(gd_focus_out_event), vc);
-        g_signal_connect(vc->gfx.drawing_area, "configure-event",
-                         G_CALLBACK(gd_configure), vc);
         g_signal_connect(vc->gfx.drawing_area, "grab-broken-event",
                          G_CALLBACK(gd_grab_broken_event), vc);
     } else {
@@ -2228,18 +2240,21 @@  static GtkWidget *gd_create_menu_view(GtkDisplayState *s, DisplayOptions *opts)
     s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit"));
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fit_item);
 
-    separator = gtk_separator_menu_item_new();
-    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
 
-    s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover"));
-    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);
+    if (!s->opts->u.gtk.has_no_input || !s->opts->u.gtk.no_input ) {
+       separator = gtk_separator_menu_item_new();
+       gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
 
-    s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
-    gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
-                                 "<QEMU>/View/Grab Input");
-    gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g,
-                            HOTKEY_MODIFIERS);
-    gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
+       s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover"));
+       gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);
+
+       s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
+       gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
+                                    "<QEMU>/View/Grab Input");
+       gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g,
+                               HOTKEY_MODIFIERS);
+       gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);
+    }
 
     separator = gtk_separator_menu_item_new();
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);