summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2017-11-21 22:08:28 +0100
committerraveit65 <[email protected]>2017-11-22 17:51:12 +0100
commit471b87793bff4e81c5f6f47efd8dcc69349e4758 (patch)
treee8fd401a6b9569ceccf1ed52ea2fd6fdbdef70a2
parent072541b9457cdb0ca41fa5948803b1b7d8d17a11 (diff)
downloadatril-471b87793bff4e81c5f6f47efd8dcc69349e4758.tar.bz2
atril-471b87793bff4e81c5f6f47efd8dcc69349e4758.tar.xz
shell: forward accels to the focused widget
GtkWindow catches keybindings for the menu items _before_ passing them to the focused widget. This is unfortunate and means that pressing ctrl+Left arrow, Ctrl+Right arrow on the search bar ends up turning the EvView instead of moving around the text. Here we override GtkWindow's handler to do the same things that it does, but in the opposite order and then we chain up to the grand parent handler, skipping gtk_window_key_press_event. See https://bugzilla.gnome.org/show_bug.cgi?id=676040 inspired from https://git.gnome.org/browse/evince/commit/?id=70a2c0780b1b44acfa18f4762a3400b89eb123b5 fix rhbz https://bugzilla.redhat.com/show_bug.cgi?id=1513826
-rw-r--r--shell/ev-window.c60
1 files changed, 24 insertions, 36 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 0b0ffc7c..b415234f 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -6225,49 +6225,37 @@ menubar_deactivate_cb (GtkWidget *menubar,
update_chrome_visibility (window);
}
+
+/*
+ * GtkWindow catches keybindings for the menu items _before_ passing them to
+ * the focused widget. This is unfortunate and means that pressing Ctrl+a,
+ * Ctrl+left or Ctrl+right in the search bar ends up selecting text in the EvView
+ * or rotating it.
+ * Here we override GtkWindow's handler to do the same things that it
+ * does, but in the opposite order and then we chain up to the grand
+ * parent handler, skipping gtk_window_key_press_event.
+ */
+
static gboolean
ev_window_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
- EvWindow *ev_window = EV_WINDOW (widget);
- EvWindowPrivate *priv = ev_window->priv;
- gboolean handled = FALSE;
+ static gpointer grand_parent_class = NULL;
+ GtkWindow *window = GTK_WINDOW (widget);
- /* Propagate the event to the view first
- * It's needed to be able to type in
- * annot popups windows
- */
- if ( priv->view) {
- g_object_ref (priv->view);
- if (gtk_widget_is_sensitive (priv->view))
- handled = gtk_widget_event (priv->view, (GdkEvent*) event);
- g_object_unref (priv->view);
- }
-
- if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
- guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
-
- if (priv->menubar_accel_keyval != 0 &&
- event->keyval == priv->menubar_accel_keyval &&
- modifier == priv->menubar_accel_modifier) {
- if (!gtk_widget_get_visible (priv->menubar)) {
- g_signal_connect (priv->menubar, "deactivate",
- G_CALLBACK (menubar_deactivate_cb),
- ev_window);
-
- gtk_widget_show (priv->menubar);
- gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menubar),
- FALSE);
-
- handled = TRUE;
- }
- }
- }
+ if (grand_parent_class == NULL)
+ grand_parent_class = g_type_class_peek_parent (ev_window_parent_class);
- if (!handled)
- handled = GTK_WIDGET_CLASS (ev_window_parent_class)->key_press_event (widget, event);
+ /* Handle focus widget key events */
+ if (gtk_window_propagate_key_event (window, event))
+ return TRUE;
+
+ /* Handle mnemonics and accelerators */
+ if (gtk_window_activate_key (window, event))
+ return TRUE;
- return handled;
+ /* Chain up, invokes binding set on window */
+ return GTK_WIDGET_CLASS (grand_parent_class)->key_press_event (widget, event);
}
static gboolean