[eog] EogWindow: Fix keyboard controls in the popover menu



commit 277309100cb94526c3f439ac0d6eb9aa4076688d
Author: Felix Riemann <friemann gnome org>
Date:   Sun Feb 12 19:10:12 2017 +0100

    EogWindow: Fix keyboard controls in the popover menu
    
    This imports and adapts a workaround from gedit that keeps the keyboard
    controls working in the popover menu and other widgets in the headerbar.
    We lose some inofficial keyboard shortcuts in the process, but as their
    names say, they were "inofficial". Maybe we can find a way to make them
    work again in the future.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754985

 src/eog-application.c |    4 ++--
 src/eog-window.c      |   45 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/src/eog-application.c b/src/eog-application.c
index 3ab86d2..3967390 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -213,8 +213,8 @@ eog_application_init_accelerators (GtkApplication *application)
                "win.set-wallpaper",    "<Ctrl>F8", NULL,
                "win.manual",           "F1", NULL,
 
-               "win.go-previous",      "Left", "BackSpace", NULL,
-               "win.go-next",          "Right", NULL,
+               "win.go-previous",      "BackSpace", NULL,
+               /* "win.go-next",       NULL,*/
                "win.go-first",         "<Alt>Home", "Home", NULL,
                "win.go-last",          "<Alt>End", "End", NULL,
                "win.go-random",        "<Ctrl>m", NULL,
diff --git a/src/eog-window.c b/src/eog-window.c
index a104eef..ae9d7ca 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -4781,16 +4781,56 @@ eog_window_delete (GtkWidget *widget, GdkEventAny *event)
        return TRUE;
 }
 
+/*
+ * Imported from gedit-window.c:
+ * GtkWindow catches keybindings for the menu items _before_ passing them to
+ * the focused widget. This is unfortunate and means that trying to use
+ * Return to activate a menu entry will instead skip to the next image.
+ * 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 gint
 eog_window_key_press (GtkWidget *widget, GdkEventKey *event)
 {
+       static gpointer grand_parent_class = NULL;
+
        gint result = FALSE;
        gboolean handle_selection = FALSE;
        GdkModifierType modifiers;
 
+       if (grand_parent_class == NULL)
+       {
+               grand_parent_class = g_type_class_peek_parent (eog_window_parent_class);
+       }
+
+       /* handle focus widget key events */
+       if (!handle_selection) {
+               handle_selection = gtk_window_propagate_key_event (GTK_WINDOW (widget), event);
+       }
+
+       /* handle mnemonics and accelerators */
+       if (!handle_selection) {
+               handle_selection = gtk_window_activate_key (GTK_WINDOW (widget), event);
+       }
+
+       /* This part is disabled for now as it overrides the arrow key handlers
+        * below which are still needed in RTL scenarios */
+#if 0
+       /* Chain up, invokes binding set on window */
+       if (!handle_selection) {
+               handle_selection = GTK_WIDGET_CLASS (grand_parent_class)->key_press_event (widget, event);
+       }
+#endif
+
+       /* If the workaround already handled the key event return early */
+       if(handle_selection)
+               return TRUE;
+
        modifiers = gtk_accelerator_get_default_mod_mask ();
 
        switch (event->keyval) {
+#if 0
        case GDK_KEY_space:
                if ((event->state & modifiers) == GDK_CONTROL_MASK) {
                        handle_selection = TRUE;
@@ -4810,6 +4850,7 @@ eog_window_key_press (GtkWidget *widget, GdkEventKey *event)
                }
                result = TRUE;
                break;
+#endif
        case GDK_KEY_Escape:
                if (EOG_WINDOW (widget)->priv->mode == EOG_WINDOW_MODE_FULLSCREEN) {
                        eog_window_stop_fullscreen (EOG_WINDOW (widget), FALSE);
@@ -4821,7 +4862,7 @@ eog_window_key_press (GtkWidget *widget, GdkEventKey *event)
                }
                break;
        case GDK_KEY_Left:
-       case GDK_KEY_Up:
+       /* case GDK_KEY_Up: */
                if ((event->state & modifiers) == 0) {
                        /* Left and Up move to previous image */
                        if (is_rtl) { /* move to next in RTL mode */
@@ -4833,7 +4874,7 @@ eog_window_key_press (GtkWidget *widget, GdkEventKey *event)
                }
                break;
        case GDK_KEY_Right:
-       case GDK_KEY_Down:
+       /* case GDK_KEY_Down: */
                if ((event->state & modifiers) == 0) {
                        /* Right and Down move to next image */
                        if (is_rtl) { /* move to previous in RTL mode */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]