qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/1] ui/gtk: Added an input mode


From: Singh, Satyeshwar
Subject: [PATCH v2 1/1] ui/gtk: Added an input mode
Date: Wed, 26 Apr 2023 23:53:25 +0000

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 "input".
It can be set like this:
  gtk,input=off/on

If set to on or completely left out, it will default to normal
operation where host HID devices can control the guests. However, if
turned off, 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>
Cc: Daniel P. Berrangé <berrange@redhat.com>
---
 qapi/ui.json    |  6 +++++-
 qemu-options.hx |  5 ++++-
 ui/gtk.c        | 43 ++++++++++++++++++++++++++++++-------------
 3 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 98322342f7..f8644e6f48 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1214,6 +1214,9 @@
 #               Since 7.1
 # @show-menubar: Display the main window menubar. Defaults to "on".
 #                Since 8.0
+# @input:       Don't let host's HID devices control the guest. Defaults to 
"on" so
+#               they can control the guest.
+#               Since 8.0
 #
 # Since: 2.12
 ##
@@ -1221,7 +1224,8 @@
   'data'    : { '*grab-on-hover' : 'bool',
                 '*zoom-to-fit'   : 'bool',
                 '*show-tabs'     : 'bool',
-                '*show-menubar'  : 'bool'  } }
+                '*show-menubar'  : 'bool',
+                '*input'         : 'bool'  } }
 
 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index 59bdf67a2c..22a78e294f 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][,input=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
     "-display vnc=<display>[,<optargs>]\n"
@@ -2072,6 +2072,9 @@ SRST
 
         ``show-menubar=on|off`` : Display the main window menubar, defaults to 
"on"
 
+        ``input=on|off``        : Don't let host's HID devices control the 
guest
+                                  if set to "off", defaults to "on"
+
     ``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..00446121c3 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 input and explicitly set it to off. In this case, they want
+     * passthrough HID devices to control the guest.
+     */
+    if (vc->s->opts->u.gtk.has_input && !vc->s->opts->u.gtk.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 {
@@ -2033,8 +2045,10 @@ static void gd_connect_signals(GtkDisplayState *s)
                      G_CALLBACK(gd_menu_zoom_fixed), s);
     g_signal_connect(s->zoom_fit_item, "activate",
                      G_CALLBACK(gd_menu_zoom_fit), s);
-    g_signal_connect(s->grab_item, "activate",
+    if (!s->opts->u.gtk.has_input || s->opts->u.gtk.input) {
+           g_signal_connect(s->grab_item, "activate",
                      G_CALLBACK(gd_menu_grab_input), s);
+    }
     g_signal_connect(s->notebook, "switch-page",
                      G_CALLBACK(gd_change_page), s);
 }
@@ -2228,18 +2242,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_input || s->opts->u.gtk.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);
-- 
2.33.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]