[epiphany/gnome-3-18] window: fix alt-left/right keyboard shortcuts
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-3-18] window: fix alt-left/right keyboard shortcuts
- Date: Sun, 18 Dec 2016 17:27:23 +0000 (UTC)
commit 162fd89e99f7a00fa88a536d33924d3e22245ec5
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Dec 18 10:56:07 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 | 72 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0b6e833..ff9b308 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -786,7 +786,6 @@ static gboolean
ephy_window_bound_accels (GtkWidget *widget,
GdkEventKey *event)
{
-<<<<<<< HEAD
EphyWindow *window = EPHY_WINDOW (widget);
EphyWindowPrivate *priv = window->priv;
guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
@@ -837,34 +836,53 @@ ephy_window_bound_accels (GtkWidget *widget,
}
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_N &&
- 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;
-
- return TRUE;
+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 */
}
-static gboolean
+static gboolean
ephy_window_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
@@ -885,7 +903,7 @@ ephy_window_key_press_event (GtkWidget *widget,
* first propagate the event to the web view. Next, try
* accelerators only if the web view did not handle the event.
*/
- 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)) {
if (!gtk_window_activate_key (GTK_WINDOW (widget), event))
ephy_window_bound_accels (widget, event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]