From patchwork Mon Feb 25 14:56:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 222927 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 EB70B2C029B for ; Tue, 26 Feb 2013 01:56:31 +1100 (EST) Received: from localhost ([::1]:42035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9zTi-00045s-7p for incoming@patchwork.ozlabs.org; Mon, 25 Feb 2013 09:56:30 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9zTW-000453-Tf for qemu-devel@nongnu.org; Mon, 25 Feb 2013 09:56:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9zTR-0008Iv-Sa for qemu-devel@nongnu.org; Mon, 25 Feb 2013 09:56:18 -0500 Received: from goliath.siemens.de ([192.35.17.28]:16586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9zTR-0008Ic-Is for qemu-devel@nongnu.org; Mon, 25 Feb 2013 09:56:13 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id r1PEuBPr002043; Mon, 25 Feb 2013 15:56:12 +0100 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id r1PEuB0V009209; Mon, 25 Feb 2013 15:56:11 +0100 Message-ID: <512B7B8B.1000402@siemens.com> Date: Mon, 25 Feb 2013 15:56:11 +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 References: <1361367806-4599-1-git-send-email-aliguori@us.ibm.com> <1361367806-4599-10-git-send-email-aliguori@us.ibm.com> <5127B788.40701@siemens.com> <5127BBC1.5070607@siemens.com> In-Reply-To: <5127BBC1.5070607@siemens.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 192.35.17.28 Cc: Kevin Wolf , "qemu-devel@nongnu.org" Subject: [Qemu-devel] [PATCH v2] gtk: Fix accelerator filtering 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 This is in fact very simply: When the input in grabbed, everything should be exclusively passed to the guest - except it has our magic CTRL-ALT modifier set. Then let GTK filter out those accels that are in use. When checking the modifier state, we just need to filter out NUM and CAPS lock. Signed-off-by: Jan Kiszka --- Changes in v2 (yeah, almost "very simple"): - ignore set NUM or CAPS when testing for hot-key modifiers ui/gtk.c | 40 +++++++++++++++++++--------------------- 1 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index e38ed0d..5682a93 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -74,6 +74,10 @@ #define MAX_VCS 10 +#define HOTKEY_MODIFIERS (GDK_CONTROL_MASK | GDK_MOD1_MASK) +#define IGNORE_MODIFIER_MASK \ + (GDK_MODIFIER_MASK & ~(GDK_LOCK_MASK | GDK_MOD2_MASK)) + typedef struct VirtualConsole { GtkWidget *menu_item; @@ -322,22 +326,10 @@ static void gd_mouse_mode_change(Notifier *notify, void *data) static gboolean gd_window_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) { GtkDisplayState *s = opaque; - GtkAccelGroupEntry *entries; - guint n_entries = 0; - gboolean propagate_accel = TRUE; gboolean handled = FALSE; - entries = gtk_accel_group_query(s->accel_group, key->keyval, - key->state, &n_entries); - if (n_entries) { - const char *quark = g_quark_to_string(entries[0].accel_path_quark); - - if (gd_is_grab_active(s) && strstart(quark, "/File/", NULL)) { - propagate_accel = FALSE; - } - } - - if (!handled && propagate_accel) { + if (!gd_is_grab_active(s) || + (key->state & IGNORE_MODIFIER_MASK) == HOTKEY_MODIFIERS) { handled = gtk_window_activate_key(GTK_WINDOW(widget), key); } @@ -925,7 +917,7 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, label); group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item)); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc->menu_item), path); - gtk_accel_map_add_entry(path, GDK_KEY_2 + index, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry(path, GDK_KEY_2 + index, HOTKEY_MODIFIERS); vc->terminal = vte_terminal_new(); @@ -1075,7 +1067,8 @@ static void gd_create_menus(GtkDisplayState *s) gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN, NULL); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->full_screen_item), "/View/Full Screen"); - gtk_accel_map_add_entry("/View/Full Screen", GDK_KEY_f, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry("/View/Full Screen", GDK_KEY_f, + HOTKEY_MODIFIERS); gtk_menu_append(GTK_MENU(s->view_menu), s->full_screen_item); separator = gtk_separator_menu_item_new(); @@ -1084,19 +1077,22 @@ static void gd_create_menus(GtkDisplayState *s) s->zoom_in_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item), "/View/Zoom In"); - gtk_accel_map_add_entry("/View/Zoom In", GDK_KEY_plus, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry("/View/Zoom In", GDK_KEY_plus, + HOTKEY_MODIFIERS); gtk_menu_append(GTK_MENU(s->view_menu), s->zoom_in_item); s->zoom_out_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item), "/View/Zoom Out"); - gtk_accel_map_add_entry("/View/Zoom Out", GDK_KEY_minus, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry("/View/Zoom Out", GDK_KEY_minus, + HOTKEY_MODIFIERS); gtk_menu_append(GTK_MENU(s->view_menu), s->zoom_out_item); s->zoom_fixed_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item), "/View/Zoom Fixed"); - gtk_accel_map_add_entry("/View/Zoom Fixed", GDK_KEY_0, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry("/View/Zoom Fixed", GDK_KEY_0, + HOTKEY_MODIFIERS); gtk_menu_append(GTK_MENU(s->view_menu), s->zoom_fixed_item); s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit")); @@ -1111,7 +1107,8 @@ static void gd_create_menus(GtkDisplayState *s) s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input")); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item), "/View/Grab Input"); - gtk_accel_map_add_entry("/View/Grab Input", GDK_KEY_g, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry("/View/Grab Input", GDK_KEY_g, + HOTKEY_MODIFIERS); gtk_menu_append(GTK_MENU(s->view_menu), s->grab_item); separator = gtk_separator_menu_item_new(); @@ -1121,7 +1118,8 @@ static void gd_create_menus(GtkDisplayState *s) group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(s->vga_item)); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->vga_item), "/View/VGA"); - gtk_accel_map_add_entry("/View/VGA", GDK_KEY_1, GDK_CONTROL_MASK | GDK_MOD1_MASK); + gtk_accel_map_add_entry("/View/VGA", GDK_KEY_1, + HOTKEY_MODIFIERS); gtk_menu_append(GTK_MENU(s->view_menu), s->vga_item); for (i = 0; i < nb_vcs; i++) {