[epiphany] window: fix alt-left/right keyboard shortcuts
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] window: fix alt-left/right keyboard shortcuts
- Date: Sun, 18 Dec 2016 17:09:24 +0000 (UTC)
commit 02ff0be0c513a35d53bda604cfddf258a9360812
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Dec 18 11:01:39 2016 -0600
window: fix alt-left/right keyboard shortcuts
The call to gdk_keymap_translate_keyboard_state doesn't seem to really
do much here, except change the way we have to test for Ctrl+Shift+T by
consuming GDK_SHIFT_MASK. In particular, the keyval returned is already
the keyval in the key event, so that's not really doing anything for us.
But this is what the GDK documentation tells us to do, so why not. The
important change here, as shown in the GDK documentation, is to mask out
all the modifiers except Ctrl/Shift/Mod1 so that we ignore virtual
modifiers like Meta that we really don't want to see.
This mostly but not completely fixes the bug where the alt-left/right
shortcuts for back/forward stop working. It fixes the regression where
these shortcuts stopped working after I introduced key event filtering.
It *does not* fix the issue that was originally reported, which is that
the shortcuts mysteriously stop working sometimes; it cannot fix that
original bug, because the key event filtering was not added until a
month after that bug was reported. Hence, I am not closing the issue
here. Something seems to be wrong in either GTK+ or in mutter, as
sometimes GTK+ apps stop receiving any input at all; it might or might
not be related.
https://bugzilla.gnome.org/show_bug.cgi?id=772437
src/ephy-window.c | 66 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 44 insertions(+), 22 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0f88bb9..e23bda7 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -496,28 +496,50 @@ ephy_window_unfullscreen (EphyWindow *window)
}
static gboolean
-should_web_view_receive_key_press_event (GdkEventKey *event)
-{
- if ((event->state & GDK_MODIFIER_MASK) == GDK_CONTROL_MASK)
- return event->keyval != GDK_KEY_n &&
- event->keyval != GDK_KEY_q &&
- event->keyval != GDK_KEY_t &&
- event->keyval != GDK_KEY_w &&
- event->keyval != GDK_KEY_Page_Up &&
- event->keyval != GDK_KEY_KP_9 &&
- event->keyval != GDK_KEY_Page_Down &&
- event->keyval != GDK_KEY_KP_3;
-
- if ((event->state & GDK_MODIFIER_MASK) == (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
- return event->keyval != GDK_KEY_T &&
- event->keyval != GDK_KEY_Page_Up &&
- event->keyval != GDK_KEY_KP_9 &&
- event->keyval != GDK_KEY_Page_Down &&
- event->keyval != GDK_KEY_KP_3;
-
- if ((event->state & GDK_MODIFIER_MASK) == GDK_MOD1_MASK)
- return event->keyval != GDK_KEY_Left &&
- event->keyval != GDK_KEY_Right;
+ephy_window_should_view_receive_key_press_event (EphyWindow *window,
+ GdkEventKey *event)
+{
+ GdkDisplay *display;
+ GdkKeymap *keymap;
+ guint keyval;
+ GdkModifierType consumed;
+ GdkModifierType state_mask = GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK;
+
+ display = gtk_widget_get_display (GTK_WIDGET (window));
+ keymap = gdk_keymap_get_for_display (display);
+
+ gdk_keymap_translate_keyboard_state (keymap,
+ event->hardware_keycode,
+ event->state,
+ event->group,
+ &keyval,
+ NULL,
+ NULL,
+ &consumed);
+ state_mask &= ~consumed;
+
+ /* Websites are allowed to override most Epiphany accelerators, but not
+ * window or tab management accelerators. */
+ if ((event->state & state_mask) == GDK_CONTROL_MASK)
+ return keyval != GDK_KEY_n && /* New Window */
+ keyval != GDK_KEY_q && /* Quit */
+ keyval != GDK_KEY_T && /* Reopen Closed Tab */
+ keyval != GDK_KEY_t && /* New Tab */
+ keyval != GDK_KEY_w && /* Close Tab */
+ keyval != GDK_KEY_Page_Up && /* Previous Tab */
+ keyval != GDK_KEY_KP_9 && /* Previous Tab */
+ keyval != GDK_KEY_Page_Down && /* Next Tab */
+ keyval != GDK_KEY_KP_3; /* Next Tab */
+
+ if ((event->state & state_mask) == (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
+ return keyval != GDK_KEY_Page_Up && /* Move Tab Left */
+ keyval != GDK_KEY_KP_9 && /* Move Tab Left */
+ keyval != GDK_KEY_Page_Down && /* Move Tab Right */
+ keyval != GDK_KEY_KP_3; /* Move Tab Right */
+
+ if ((event->state & state_mask) == GDK_MOD1_MASK)
+ return keyval != GDK_KEY_Left && /* Back */
+ keyval != GDK_KEY_Right; /* Forward */
return TRUE;
}
@@ -542,7 +564,7 @@ ephy_window_key_press_event (GtkWidget *widget,
* short-circuit the event propagation if it's a special keybinding
* that is reserved for Epiphany not allowed to be seen by webpages.
*/
- if (!should_web_view_receive_key_press_event (event) ||
+ if (!ephy_window_should_view_receive_key_press_event (EPHY_WINDOW (widget), event) ||
!gtk_window_propagate_key_event (GTK_WINDOW (widget), event))
gtk_window_activate_key (GTK_WINDOW (widget), event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]