From patchwork Tue Feb 26 19:45:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 223379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0CFF12C0082 for ; Wed, 27 Feb 2013 06:46:11 +1100 (EST) Received: from localhost ([::1]:49206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAQTZ-0002H0-3x for incoming@patchwork.ozlabs.org; Tue, 26 Feb 2013 14:46:09 -0500 Received: from eggs.gnu.org ([208.118.235.92]:48487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAQTO-0002FM-TR for qemu-devel@nongnu.org; Tue, 26 Feb 2013 14:46:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAQTG-0005lc-LW for qemu-devel@nongnu.org; Tue, 26 Feb 2013 14:45:58 -0500 Received: from mout.web.de ([212.227.15.3]:49844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAQTG-0005kp-7Q for qemu-devel@nongnu.org; Tue, 26 Feb 2013 14:45:50 -0500 Received: from mchn199C.mchp.siemens.de ([95.157.56.37]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0Mbhiv-1UQivx1L41-00J6bX; Tue, 26 Feb 2013 20:45:48 +0100 Message-ID: <512D10EC.6040807@web.de> Date: Tue, 26 Feb 2013 20:45:48 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Anthony Liguori X-Enigmail-Version: 1.5 X-Provags-ID: V02:K0:yXv6TgWPTXc/iw0eJQHI15iFU4xQ9qzceoQDSYoiFPK 8q96fCZjMf/Z+WfBK5UXNbS9llaNmta9+N9c/kDX9+RzdggWdu vfujL+EG9OguebyyhDwQhr0vOLveXO88OJCJjkXqaRVuByPF6Z MUOis2s71+ohGFU4NEhGHwJGxQA7CWMevgul1mCyE40/QlpzUg URzB9C6mtr3IzNFO94E5A== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.15.3 Cc: qemu-devel Subject: [Qemu-devel] [PATCH v2] gtk: Release modifier when graphic console loses keyboard focus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka This solves, e.g., sticky ALT when selecting a GTK menu, switching to a different window or selecting a different virtual console. Signed-off-by: Jan Kiszka Tested-by: Stefan Hajnoczi --- Changes in v2: - fix a style issue - truly switch off line-wrapping before sending (sorry) ui/gtk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 51 insertions(+), 2 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 5682a93..a458641 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -78,6 +78,11 @@ #define IGNORE_MODIFIER_MASK \ (GDK_MODIFIER_MASK & ~(GDK_LOCK_MASK | GDK_MOD2_MASK)) +static const int modifier_keycode[] = { + /* shift, control, alt keys, meta keys, both left & right */ + 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd, +}; + typedef struct VirtualConsole { GtkWidget *menu_item; @@ -137,6 +142,8 @@ typedef struct GtkDisplayState gboolean free_scale; bool external_pause_update; + + bool modifier_pressed[ARRAY_SIZE(modifier_keycode)]; } GtkDisplayState; static GtkDisplayState *global_state; @@ -205,6 +212,26 @@ static void gd_update_caption(GtkDisplayState *s) g_free(title); } +static void gtk_release_modifiers(GtkDisplayState *s) +{ + int i, keycode; + + if (!gd_on_vga(s)) { + return; + } + for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) { + keycode = modifier_keycode[i]; + if (!s->modifier_pressed[i]) { + continue; + } + if (keycode & SCANCODE_GREY) { + kbd_put_keycode(SCANCODE_EMUL0); + } + kbd_put_keycode(keycode | SCANCODE_UP); + s->modifier_pressed[i] = false; + } +} + /** DisplayState Callbacks **/ static void gd_update(DisplayState *ds, int x, int y, int w, int h) @@ -332,8 +359,9 @@ static gboolean gd_window_key_event(GtkWidget *widget, GdkEventKey *key, void *o (key->state & IGNORE_MODIFIER_MASK) == HOTKEY_MODIFIERS) { handled = gtk_window_activate_key(GTK_WINDOW(widget), key); } - - if (!handled) { + if (handled) { + gtk_release_modifiers(s); + } else { handled = gtk_window_propagate_key_event(GTK_WINDOW(widget), key); } @@ -557,8 +585,10 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) { + GtkDisplayState *s = opaque; int gdk_keycode; int qemu_keycode; + int i; gdk_keycode = key->hardware_keycode; @@ -580,6 +610,12 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) gdk_keycode, qemu_keycode, (key->type == GDK_KEY_PRESS) ? "down" : "up"); + for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) { + if (qemu_keycode == modifier_keycode[i]) { + s->modifier_pressed[i] = (key->type == GDK_KEY_PRESS); + } + } + if (qemu_keycode & SCANCODE_GREY) { kbd_put_keycode(SCANCODE_EMUL0); } @@ -635,6 +671,7 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque) } else { int i; + gtk_release_modifiers(s); for (i = 0; i < s->nb_vcs; i++) { if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->vc[i].menu_item))) { gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), i + 1); @@ -844,6 +881,16 @@ static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing, gp return TRUE; } +static gboolean gd_focus_out_event(GtkWidget *widget, + GdkEventCrossing *crossing, gpointer data) +{ + GtkDisplayState *s = data; + + gtk_release_modifiers(s); + + return TRUE; +} + /** Virtual Console Callbacks **/ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len) @@ -1022,6 +1069,8 @@ static void gd_connect_signals(GtkDisplayState *s) G_CALLBACK(gd_enter_event), s); g_signal_connect(s->drawing_area, "leave-notify-event", G_CALLBACK(gd_leave_event), s); + g_signal_connect(s->drawing_area, "focus-out-event", + G_CALLBACK(gd_focus_out_event), s); } static void gd_create_menus(GtkDisplayState *s)