[gthumb] attempt to fix the focus chain



commit b50e339959321e7764a4e20c37f3356d41fa5c4e
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jul 4 15:41:08 2017 +0200

    attempt to fix the focus chain
    
    * unset CAN_FOCUS for container widgets;
    * capture the key events only in GthBrowser and then send the event
      to the right function based on the visibile page.

 extensions/file_tools/callbacks.c               |    6 ---
 extensions/file_viewer/gth-file-viewer-page.c   |   13 -------
 extensions/image_viewer/gth-image-viewer-page.c |   13 -------
 gthumb/gth-browser.c                            |   42 +++++++++++++++++-----
 gthumb/gth-empty-list.c                         |   13 +------
 gthumb/gth-file-list.c                          |   26 +++++++++-----
 gthumb/gth-file-list.h                          |    2 +-
 gthumb/gth-grid-view.c                          |   25 +-------------
 gthumb/gth-location-bar.c                       |    2 +
 gthumb/gth-location-chooser.c                   |   12 +------
 10 files changed, 54 insertions(+), 100 deletions(-)
---
diff --git a/extensions/file_tools/callbacks.c b/extensions/file_tools/callbacks.c
index cbad8e9..f8a98bf 100644
--- a/extensions/file_tools/callbacks.c
+++ b/extensions/file_tools/callbacks.c
@@ -60,12 +60,6 @@ file_tools__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
        if (! GTH_IS_IMAGE_VIEWER_PAGE (page))
                return NULL;
 
-       if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_VIEWER
-           && ! gtk_widget_has_focus (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (page))))
-       {
-               return NULL;
-       }
-
        switch (event->keyval) {
        case GDK_KEY_a:
                tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), 
GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST);
diff --git a/extensions/file_viewer/gth-file-viewer-page.c b/extensions/file_viewer/gth-file-viewer-page.c
index c1b20b9..81f353e 100644
--- a/extensions/file_viewer/gth-file-viewer-page.c
+++ b/extensions/file_viewer/gth-file-viewer-page.c
@@ -55,15 +55,6 @@ viewer_scroll_event_cb (GtkWidget         *widget,
 
 
 static gboolean
-viewer_key_press_cb (GtkWidget         *widget,
-                    GdkEventKey       *event,
-                    GthFileViewerPage *self)
-{
-       return gth_browser_viewer_key_press_cb (self->priv->browser, event);
-}
-
-
-static gboolean
 viewer_button_press_cb (GtkWidget         *widget,
                        GdkEventButton    *event,
                        GthFileViewerPage *self)
@@ -128,10 +119,6 @@ gth_file_viewer_page_real_activate (GthViewerPage *base,
                          "popup-menu",
                          G_CALLBACK (viewer_popup_menu_cb),
                          self);
-       g_signal_connect (G_OBJECT (self->priv->label),
-                         "key_press_event",
-                         G_CALLBACK (viewer_key_press_cb),
-                         self);
 
        gth_browser_set_viewer_widget (browser, self->priv->viewer);
 }
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 61796b8..33b62ca 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -698,15 +698,6 @@ viewer_image_map_event_cb (GtkWidget          *widget,
 }
 
 
-static gboolean
-viewer_key_press_cb (GtkWidget          *widget,
-                    GdkEventKey        *event,
-                    GthImageViewerPage *self)
-{
-       return gth_browser_viewer_key_press_cb (self->priv->browser, event);
-}
-
-
 static void
 clipboard_targets_received_cb (GtkClipboard *clipboard,
                               GdkAtom      *atoms,
@@ -1143,10 +1134,6 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
                                G_CALLBACK (viewer_image_map_event_cb),
                                self);
        g_signal_connect (G_OBJECT (self->priv->viewer),
-                         "key_press_event",
-                         G_CALLBACK (viewer_key_press_cb),
-                         self);
-       g_signal_connect (G_OBJECT (self->priv->viewer),
                          "realize",
                          G_CALLBACK (viewer_realize_cb),
                          self);
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 77a3d58..7b7f85f 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -1503,7 +1503,7 @@ load_data_continue (LoadData *load_data,
                g_object_unref (filter);
 
                if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER)
-                       gtk_widget_grab_focus (browser->priv->file_list);
+                       gth_file_list_focus (GTH_FILE_LIST (browser->priv->file_list));
 
                if (load_data->file_to_select != NULL)
                        gth_file_list_make_file_visible (GTH_FILE_LIST (browser->priv->file_list), 
load_data->file_to_select);
@@ -2520,7 +2520,7 @@ _gth_browser_real_set_current_page (GthWindow *window,
        /* set the focus */
 
        if (page == GTH_BROWSER_PAGE_BROWSER)
-               gtk_widget_grab_focus (browser->priv->file_list);
+               gth_file_list_focus (GTH_FILE_LIST (browser->priv->file_list));
        else if (page == GTH_BROWSER_PAGE_VIEWER)
                _gth_browser_make_file_visible (browser, browser->priv->current_file);
 
@@ -3838,11 +3838,9 @@ gth_file_view_file_activated_cb (GthFileView *file_view,
 
 
 static gboolean
-gth_file_list_key_press_cb (GtkWidget   *widget,
-                           GdkEventKey *event,
-                           gpointer     user_data)
+gth_browser_file_list_key_press_cb (GthBrowser  *browser,
+                                   GdkEventKey *event)
 {
-       GthBrowser *browser = user_data;
        gboolean    result = FALSE;
        guint       modifiers;
 
@@ -4251,6 +4249,29 @@ _gth_browser_register_fixed_viewer_control (GthBrowser *browser,
 }
 
 
+static gboolean
+browser_key_press_cb (GthBrowser  *browser,
+                     GdkEventKey *event)
+{
+       GtkWidget *focus_widget;
+
+       switch (gth_window_get_current_page (GTH_WINDOW (browser))) {
+       case GTH_BROWSER_PAGE_VIEWER:
+               if (! _gth_browser_file_tool_is_active (browser))
+                       return gth_browser_viewer_key_press_cb (browser, event);
+               break;
+       case GTH_BROWSER_PAGE_BROWSER:
+               focus_widget = gtk_window_get_focus (GTK_WINDOW (browser));
+               if (! GTK_IS_ENTRY (focus_widget) && ! GTK_IS_TREE_VIEW (focus_widget))
+                       return gth_browser_file_list_key_press_cb (browser, event);
+               break;
+       default:
+               break;
+       }
+       return FALSE;
+}
+
+
 static void
 gth_browser_init (GthBrowser *browser)
 {
@@ -4378,6 +4399,11 @@ gth_browser_init (GthBrowser *browser)
        g_signal_connect (browser, "unrealize", G_CALLBACK (_gth_browser_unrealize), NULL);
        gtk_widget_realize (GTK_WIDGET (browser));
 
+       g_signal_connect (browser,
+                         "key-press-event",
+                         G_CALLBACK (browser_key_press_cb),
+                         browser);
+
        /* ui actions */
 
        g_action_map_add_action_entries (G_ACTION_MAP (browser),
@@ -4868,10 +4894,6 @@ gth_browser_init (GthBrowser *browser)
                          "file-activated",
                          G_CALLBACK (gth_file_view_file_activated_cb),
                          browser);
-       g_signal_connect (browser->priv->file_list,
-                         "key-press-event",
-                         G_CALLBACK (gth_file_list_key_press_cb),
-                         browser);
 
        /* the filter bar */
 
diff --git a/gthumb/gth-empty-list.c b/gthumb/gth-empty-list.c
index 6d7e31b..6918f5b 100644
--- a/gthumb/gth-empty-list.c
+++ b/gthumb/gth-empty-list.c
@@ -247,16 +247,6 @@ gth_empty_list_draw (GtkWidget *widget,
 }
 
 
-static gboolean
-gth_empty_list_button_press (GtkWidget      *widget,
-                            GdkEventButton *event)
-{
-       if (! gtk_widget_has_focus (widget))
-               gtk_widget_grab_focus (widget);
-       return TRUE;
-}
-
-
 static void
 gth_empty_list_class_init (GthEmptyListClass *klass)
 {
@@ -277,7 +267,6 @@ gth_empty_list_class_init (GthEmptyListClass *klass)
        widget_class->unmap = gth_empty_list_unmap;
        widget_class->size_allocate = gth_empty_list_size_allocate;
        widget_class->draw = gth_empty_list_draw;
-       widget_class->button_press_event = gth_empty_list_button_press;
 
        /* properties */
 
@@ -297,7 +286,7 @@ gth_empty_list_init (GthEmptyList *self)
        GtkStyleContext *style_context;
 
        gtk_widget_set_has_window (GTK_WIDGET (self), TRUE);
-       gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
+       gtk_widget_set_can_focus (GTK_WIDGET (self), FALSE);
 
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_EMPTY_LIST, GthEmptyListPrivate);
        self->priv->layout = NULL;
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index f516dd1..3b3dc50 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -357,15 +357,6 @@ gth_file_list_get_preferred_height (GtkWidget *widget,
 
 
 static void
-gth_file_list_grab_focus (GtkWidget *widget)
-{
-       GthFileList *file_list = GTH_FILE_LIST (widget);
-
-       gtk_widget_grab_focus (file_list->priv->notebook);
-}
-
-
-static void
 gth_file_list_class_init (GthFileListClass *class)
 {
        GObjectClass   *object_class;
@@ -378,7 +369,6 @@ gth_file_list_class_init (GthFileListClass *class)
        widget_class->get_request_mode = gth_file_list_get_request_mode;
        widget_class->get_preferred_width = gth_file_list_get_preferred_width;
        widget_class->get_preferred_height = gth_file_list_get_preferred_height;
-       widget_class->grab_focus = gth_file_list_grab_focus;
 }
 
 
@@ -422,6 +412,8 @@ thumb_data_unref (ThumbData *data)
 static void
 gth_file_list_init (GthFileList *file_list)
 {
+       gtk_widget_set_can_focus (GTK_WIDGET (file_list), FALSE);
+
        file_list->priv = g_new0 (GthFileListPrivateData, 1);
        file_list->priv->settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
        file_list->priv->thumb_data = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, 
g_object_unref, (GDestroyNotify) thumb_data_unref);
@@ -625,6 +617,7 @@ gth_file_list_construct (GthFileList     *file_list,
        /* the main notebook */
 
        file_list->priv->notebook = gtk_stack_new ();
+       gtk_widget_set_can_focus (file_list->priv->notebook, FALSE);
 
        /* the message pane */
 
@@ -633,6 +626,7 @@ gth_file_list_construct (GthFileList     *file_list,
        /* the file view */
 
        file_list->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+       gtk_widget_set_can_focus (file_list->priv->scrolled_window, FALSE);
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (file_list->priv->scrolled_window), 
GTK_SHADOW_ETCHED_IN);
 
        file_list->priv->vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(file_list->priv->scrolled_window));
@@ -2161,3 +2155,15 @@ gth_file_list_unset_drag_source (GthFileList *file_list)
 {
        gth_file_view_unset_drag_source (GTH_FILE_VIEW (file_list->priv->view));
 }
+
+
+void
+gth_file_list_focus (GthFileList *file_list)
+{
+       GtkWidget *child;
+
+       child = gtk_stack_get_visible_child (GTK_STACK (file_list->priv->notebook));
+       if (GTK_IS_BIN (child))
+               child = gtk_bin_get_child (GTK_BIN (child));
+       gtk_widget_grab_focus ((child != NULL) ? child : GTK_WIDGET (file_list));
+}
diff --git a/gthumb/gth-file-list.h b/gthumb/gth-file-list.h
index 02962de..779f4a2 100644
--- a/gthumb/gth-file-list.h
+++ b/gthumb/gth-file-list.h
@@ -131,7 +131,7 @@ int               gth_file_list_prev_file         (GthFileList          *file_li
 void              gth_file_list_enable_drag_source (GthFileList         *file_list,
                                                    GdkDragAction        actions);
 void              gth_file_list_unset_drag_source  (GthFileList         *file_list);
-
+void              gth_file_list_focus              (GthFileList         *file_list);
 
 G_END_DECLS
 
diff --git a/gthumb/gth-grid-view.c b/gthumb/gth-grid-view.c
index 15e0c08..2b0d9b2 100644
--- a/gthumb/gth-grid-view.c
+++ b/gthumb/gth-grid-view.c
@@ -448,7 +448,7 @@ gth_grid_view_finalize (GObject *object)
 }
 
 
-static gboolean
+static void
 adjustment_value_changed (GtkAdjustment *adj,
                          GthGridView   *self)
 {
@@ -456,8 +456,6 @@ adjustment_value_changed (GtkAdjustment *adj,
                gdk_window_move (self->priv->bin_window,
                                 (int) - gtk_adjustment_get_value (self->priv->hadjustment),
                                 (int) - gtk_adjustment_get_value (self->priv->vadjustment));
-
-       return FALSE;
 }
 
 
@@ -1802,25 +1800,6 @@ gth_grid_view_draw (GtkWidget *widget,
 
 
 static gboolean
-gth_grid_view_focus_in (GtkWidget     *widget,
-                       GdkEventFocus *event)
-{
-       gtk_widget_queue_draw (widget);
-       return TRUE;
-}
-
-
-static gboolean
-gth_grid_view_focus_out (GtkWidget     *widget,
-                        GdkEventFocus *event)
-{
-       gtk_widget_queue_draw (widget);
-
-       return TRUE;
-}
-
-
-static gboolean
 gth_grid_view_key_press (GtkWidget   *widget,
                          GdkEventKey *event)
 {
@@ -3759,8 +3738,6 @@ gth_grid_view_class_init (GthGridViewClass *grid_view_class)
        widget_class->get_preferred_height = gth_grid_view_get_preferred_height;
        widget_class->size_allocate = gth_grid_view_size_allocate;
        widget_class->draw = gth_grid_view_draw;
-       widget_class->focus_in_event = gth_grid_view_focus_in;
-       widget_class->focus_out_event = gth_grid_view_focus_out;
        widget_class->key_press_event = gth_grid_view_key_press;
        widget_class->key_release_event = gth_grid_view_key_release;
        widget_class->button_press_event = gth_grid_view_button_press;
diff --git a/gthumb/gth-location-bar.c b/gthumb/gth-location-bar.c
index 04fe163..32e6cbf 100644
--- a/gthumb/gth-location-bar.c
+++ b/gthumb/gth-location-bar.c
@@ -50,6 +50,8 @@ gth_location_bar_init (GthLocationBar *self)
 {
        GtkWidget *box;
 
+       gtk_widget_set_can_focus (GTK_WIDGET (self), FALSE);
+
        self->priv = gth_location_bar_get_instance_private (self);
 
        gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
diff --git a/gthumb/gth-location-chooser.c b/gthumb/gth-location-chooser.c
index bde3f08..96a7e0c 100644
--- a/gthumb/gth-location-chooser.c
+++ b/gthumb/gth-location-chooser.c
@@ -157,15 +157,6 @@ gth_location_chooser_finalize (GObject *object)
 }
 
 
-static void
-gth_location_chooser_grab_focus (GtkWidget *widget)
-{
-       GthLocationChooser *self = GTH_LOCATION_CHOOSER (widget);
-
-       gtk_widget_grab_focus (self->priv->combo);
-}
-
-
 static gboolean
 get_nth_separator_pos (GthLocationChooser *self,
                       int                 pos,
@@ -509,7 +500,6 @@ gth_location_chooser_class_init (GthLocationChooserClass *klass)
        object_class->finalize = gth_location_chooser_finalize;
 
        widget_class = (GtkWidgetClass *) klass;
-       widget_class->grab_focus = gth_location_chooser_grab_focus;
        widget_class->realize = gth_location_chooser_realize;
 
        /* properties */
@@ -560,7 +550,7 @@ gth_location_chooser_init (GthLocationChooser *self)
 {
        GtkCellRenderer *renderer;
 
-       gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
+       gtk_widget_set_can_focus (GTK_WIDGET (self), FALSE);
        gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
 
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_LOCATION_CHOOSER, GthLocationChooserPrivate);


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