diff mbox

[2/2] gtk: Avoid accel key leakage into guest on console switch

Message ID 8f8ddd75a1834c92d95f18856e260ac8faae40e5.1430075061.git.jan.kiszka@web.de
State New
Headers show

Commit Message

Jan Kiszka April 26, 2015, 7:04 p.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

GTK2 sends the accel key to the guest when switching to the graphic
console via that shortcut. Resolve this by ignoring any keys until the
next key-release event. However, do not ignore keys when switching via
the menu or when on GTK3.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/gtk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Gerd Hoffmann April 27, 2015, 9:24 a.m. UTC | #1
On So, 2015-04-26 at 21:04 +0200, Jan Kiszka wrote:
> GTK2 sends the accel key to the guest when switching to the graphic
> console via that shortcut. Resolve this by ignoring any keys until the
> next key-release event. However, do not ignore keys when switching via
> the menu or when on GTK3.

Added to gtk queue

thanks,
  Gerd
diff mbox

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index 76d9b73..0ef03e7 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -230,6 +230,7 @@  struct GtkDisplayState {
 
     bool modifier_pressed[ARRAY_SIZE(modifier_keycode)];
     bool has_evdev;
+    bool ignore_keys;
 };
 
 static void gd_grab_pointer(VirtualConsole *vc);
@@ -953,6 +954,11 @@  static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
     int qemu_keycode;
     int i;
 
+    if (s->ignore_keys) {
+        s->ignore_keys = (key->type == GDK_KEY_PRESS);
+        return TRUE;
+    }
+
     if (key->keyval == GDK_KEY_Pause) {
         qemu_input_event_send_key_qcode(vc->gfx.dcl.con, Q_KEY_CODE_PAUSE,
                                         key->type == GDK_KEY_PRESS);
@@ -1033,12 +1039,18 @@  static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
             gtk_widget_grab_focus(vc->tab_item);
         }
     }
+    s->ignore_keys = false;
 }
 
 static void gd_accel_switch_vc(void *opaque)
 {
     VirtualConsole *vc = opaque;
+
     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE);
+#if !GTK_CHECK_VERSION(3, 0, 0)
+    /* GTK2 sends the accel key to the target console - ignore this until */
+    vc->s->ignore_keys = true;
+#endif
 }
 
 static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque)