[nautilus] view: handle zoom X11 events



commit 84faf7473b6c375188cd24746a3569872def8f13
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Aug 16 15:58:01 2015 -0300

    view: handle zoom X11 events
    
    All X11 custom keys are currently handled by NautilusWindow,
    which performs a search on it's own action group as well as
    the view's one to perform the corresponding action.
    
    Since we're isolating NautilusView from other classes, the
    search on the view's action group is undesired.
    
    Fix that by making the view handle zoom-in and zoom-out actions,
    instead of the window itself.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753695

 src/nautilus-view.c   |   45 +++++++++++++++++++++++++++++++++++++++++++++
 src/nautilus-window.c |   18 +-----------------
 2 files changed, 46 insertions(+), 17 deletions(-)
---
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 56638c4..2c1b0d5 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -44,6 +44,10 @@
 #include "nautilus-empty-view.h"
 #endif
 
+#ifdef HAVE_X11_XF86KEYSYM_H
+#include <X11/XF86keysym.h>
+#endif
+
 #include <gdk/gdkx.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
@@ -300,6 +304,18 @@ static void     check_empty_states                             (NautilusView *vi
 
 G_DEFINE_TYPE (NautilusView, nautilus_view, GTK_TYPE_OVERLAY);
 
+static const struct {
+       unsigned int keyval;
+       const char *action;
+} extra_view_keybindings [] = {
+#ifdef HAVE_X11_XF86KEYSYM_H
+       /* View actions */
+       { XF86XK_ZoomIn,        "zoom-in" },
+       { XF86XK_ZoomOut,       "zoom-out" },
+
+#endif
+};
+
 static void
 check_empty_states (NautilusView *view)
 {
@@ -7755,6 +7771,34 @@ nautilus_view_parent_set (GtkWidget *widget,
        }
 }
 
+static gboolean
+nautilus_view_key_press_event (GtkWidget   *widget,
+                               GdkEventKey *event)
+{
+        NautilusView *view;
+        gint i;
+
+        view = NAUTILUS_VIEW (widget);
+
+        for (i = 0; i < G_N_ELEMENTS (extra_view_keybindings); i++) {
+                if (extra_view_keybindings[i].keyval == event->keyval) {
+                        GAction *action;
+
+                        action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
+                                                             extra_view_keybindings[i].action);
+
+                        if (g_action_get_enabled (action)) {
+                                g_action_activate (action, NULL);
+                                return GDK_EVENT_STOP;
+                        }
+
+                        break;
+                }
+        }
+
+        return GDK_EVENT_PROPAGATE;
+}
+
 static void
 nautilus_view_class_init (NautilusViewClass *klass)
 {
@@ -7769,6 +7813,7 @@ nautilus_view_class_init (NautilusViewClass *klass)
        oclass->set_property = nautilus_view_set_property;
 
        widget_class->destroy = nautilus_view_destroy;
+        widget_class->key_press_event = nautilus_view_key_press_event;
        widget_class->scroll_event = nautilus_view_scroll_event;
        widget_class->parent_set = nautilus_view_parent_set;
         widget_class->grab_focus = nautilus_view_grab_focus;
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 99667d1..4ccc96d 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -41,7 +41,6 @@
 #include "nautilus-toolbar.h"
 #include "nautilus-window-slot.h"
 #include "nautilus-list-view.h"
-#include "nautilus-view.h"
 
 #include <eel/eel-debug.h>
 #include <eel/eel-gtk-extensions.h>
@@ -176,10 +175,6 @@ static const struct {
        { XF86XK_Stop,          "stop" },
        { XF86XK_Back,          "back" },
        { XF86XK_Forward,       "forward" },
-       /* View actions */
-       { XF86XK_ZoomIn,        "zoom-in" },
-       { XF86XK_ZoomOut,       "zoom-out" },
-
 #endif
 };
 
@@ -2297,19 +2292,13 @@ nautilus_window_key_press_event (GtkWidget *widget,
                                 GdkEventKey *event)
 {
        NautilusWindow *window;
-       NautilusWindowSlot *active_slot;
-       NautilusView *view;
        GtkWidget *focus_widget;
        int i;
 
        window = NAUTILUS_WINDOW (widget);
 
-       active_slot = nautilus_window_get_active_slot (window);
-       view =  nautilus_window_slot_get_view (active_slot);
-
        focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
-       if (view != NULL && focus_widget != NULL &&
-           GTK_IS_EDITABLE (focus_widget)) {
+        if (focus_widget != NULL && GTK_IS_EDITABLE (focus_widget)) {
                /* if we have input focus on a GtkEditable (e.g. a GtkEntry), forward
                 * the event to it before activating accelerator bindings too.
                 */
@@ -2320,14 +2309,9 @@ nautilus_window_key_press_event (GtkWidget *widget,
 
        for (i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++) {
                if (extra_window_keybindings[i].keyval == event->keyval) {
-                       const GActionGroup *action_group;
                        GAction *action;
 
                        action = g_action_map_lookup_action (G_ACTION_MAP (window), 
extra_window_keybindings[i].action);
-                       if (action == NULL) {
-                               action_group = nautilus_view_get_action_group (view);
-                               action = g_action_map_lookup_action (G_ACTION_MAP (action_group), 
extra_window_keybindings[i].action);
-                       }
 
                        g_assert (action != NULL);
                        if (g_action_get_enabled (action)) {


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