[balsa] Various: Connect to "focus-{in,out}" signals



commit 7923d3bc3ebc2e912f015f7a86063d76bab9f170
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jun 1 18:11:57 2020 -0400

    Various: Connect to "focus-{in,out}" signals
    
    Connect to the "focus-{in,out}" signals of a GtkEventControllerKey
    instead of the "focus-{in,out}-event" widget signals.
    
    This is preparation for GTK4, but will still need to be changed
    to use GtkEventControllerFocus in that distant future.
    
            * src/balsa-message.c (bm_header_tl_buttons), (balsa_message_init):
            * src/balsa-mime-widget-message.c (bm_header_widget_new):
            * src/balsa-mime-widget.c (balsa_mime_widget_new):
            * src/balsa-mime-widget-callbacks.c
              (balsa_mime_widget_limit_focus),
              (balsa_mime_widget_unlimit_focus): new signature;
            * src/balsa-mime-widget-callbacks.h: ditto.

 ChangeLog                         | 17 +++++++++++++++++
 src/balsa-message.c               | 23 +++++++++++------------
 src/balsa-mime-widget-callbacks.c | 21 +++++++++------------
 src/balsa-mime-widget-callbacks.h |  6 ++++--
 src/balsa-mime-widget-message.c   |  7 +++----
 src/balsa-mime-widget.c           |  6 ++++--
 6 files changed, 48 insertions(+), 32 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 759ed47ff..939776d6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2020-06-01  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Various: Connect to the "focus-{in,out}" signals of a
+       GtkEventControllerKey instead of the "focus-{in,out}-event" widget
+       signals.
+
+       This is preparation for GTK4, but will still need to be changed
+       to use GtkEventControllerFocus in that distant future.
+
+       * src/balsa-message.c (bm_header_tl_buttons), (balsa_message_init):
+       * src/balsa-mime-widget-message.c (bm_header_widget_new):
+       * src/balsa-mime-widget.c (balsa_mime_widget_new):
+       * src/balsa-mime-widget-callbacks.c
+         (balsa_mime_widget_limit_focus),
+         (balsa_mime_widget_unlimit_focus): new signature;
+       * src/balsa-mime-widget-callbacks.h: ditto.
+
 2020-06-01  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Various: Connect to the "key-pressed" signal of a
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 82c1ae49f..4e9a27a9b 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -261,12 +261,12 @@ bm_header_tl_buttons(BalsaMessage * balsa_message)
                                       GTK_ICON_SIZE_BUTTON);
     gtk_widget_set_tooltip_text(button,
                                _("Select message part to display"));
-    g_signal_connect(button, "focus_in_event",
-                    G_CALLBACK(balsa_mime_widget_limit_focus),
-                    (gpointer) balsa_message);
-    g_signal_connect(button, "focus_out_event",
-                    G_CALLBACK(balsa_mime_widget_unlimit_focus),
-                    (gpointer) balsa_message);
+
+    key_controller = gtk_event_controller_key_new(button);
+    g_signal_connect(key_controller, "focus-in",
+                    G_CALLBACK(balsa_mime_widget_limit_focus), balsa_message);
+    g_signal_connect(key_controller, "focus-out",
+                    G_CALLBACK(balsa_mime_widget_unlimit_focus), balsa_message);
     gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
     g_signal_connect(button, "clicked",
                     G_CALLBACK(balsa_headers_attachments_popup), balsa_message);
@@ -680,12 +680,11 @@ balsa_message_init(BalsaMessage * balsa_message)
     g_free(buttons);
 
     /* Widget to hold message */
-    g_signal_connect(GTK_WIDGET(balsa_message->bm_widget), "focus_in_event",
-                     G_CALLBACK(balsa_mime_widget_limit_focus),
-                     (gpointer) balsa_message);
-    g_signal_connect(GTK_WIDGET(balsa_message->bm_widget), "focus_out_event",
-                     G_CALLBACK(balsa_mime_widget_unlimit_focus),
-                    (gpointer) balsa_message);
+    key_controller = gtk_event_controller_key_new(GTK_WIDGET(balsa_message->bm_widget));
+    g_signal_connect(key_controller, "focus-in",
+                     G_CALLBACK(balsa_mime_widget_limit_focus), balsa_message);
+    g_signal_connect(key_controller, "focus-out",
+                     G_CALLBACK(balsa_mime_widget_unlimit_focus), balsa_message);
 
     /* If we do not add the widget to a viewport, GtkContainer would
      * provide one, but it would also set it up to scroll on grab-focus,
diff --git a/src/balsa-mime-widget-callbacks.c b/src/balsa-mime-widget-callbacks.c
index 0bc2c1aec..895e5a844 100644
--- a/src/balsa-mime-widget-callbacks.c
+++ b/src/balsa-mime-widget-callbacks.c
@@ -275,11 +275,12 @@ bmw_set_can_focus(GtkWidget *widget,
 }
 
 
-gint
-balsa_mime_widget_limit_focus(GtkWidget     *widget,
-                              GdkEventFocus *event,
-                              BalsaMessage  *bm)
+void
+balsa_mime_widget_limit_focus(GtkEventControllerKey *key_controller,
+                              gpointer               user_data)
 {
+    GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(key_controller));
+    BalsaMessage *bm = user_data;
     GtkWidget *container = balsa_mime_widget_get_container(balsa_message_get_bm_widget(bm));
 
     /* Disable can_focus on other message parts so that TAB does not
@@ -289,16 +290,14 @@ balsa_mime_widget_limit_focus(GtkWidget     *widget,
 
     if (balsa_message_get_focus_state(bm) == BALSA_MESSAGE_FOCUS_STATE_NO)
         balsa_message_set_focus_state(bm, BALSA_MESSAGE_FOCUS_STATE_YES);
-
-    return FALSE;
 }
 
 
-gint
-balsa_mime_widget_unlimit_focus(GtkWidget     *widget,
-                                GdkEventFocus *event,
-                                BalsaMessage  *bm)
+void
+balsa_mime_widget_unlimit_focus(GtkEventControllerKey *key_controller,
+                                gpointer               user_data)
 {
+    BalsaMessage *bm = user_data;
     GtkWidget *container = balsa_mime_widget_get_container(balsa_message_get_bm_widget(bm));
 
     bmw_set_can_focus(container, GINT_TO_POINTER(TRUE));
@@ -312,6 +311,4 @@ balsa_mime_widget_unlimit_focus(GtkWidget     *widget,
         } else
             balsa_message_set_focus_state(bm, BALSA_MESSAGE_FOCUS_STATE_NO);
     }
-
-    return FALSE;
 }
diff --git a/src/balsa-mime-widget-callbacks.h b/src/balsa-mime-widget-callbacks.h
index db97ac619..c819aa4e4 100644
--- a/src/balsa-mime-widget-callbacks.h
+++ b/src/balsa-mime-widget-callbacks.h
@@ -35,8 +35,10 @@ gboolean balsa_mime_widget_key_pressed(GtkEventControllerKey *controller,
                                        guint                  keycode,
                                        GdkModifierType        state,
                                        gpointer               user_data);
-gint balsa_mime_widget_limit_focus(GtkWidget * widget, GdkEventFocus * event, BalsaMessage * bm);
-gint balsa_mime_widget_unlimit_focus(GtkWidget * widget, GdkEventFocus * event, BalsaMessage * bm);
+void balsa_mime_widget_limit_focus(GtkEventControllerKey *key_controller,
+                                   gpointer               user_data);
+void balsa_mime_widget_unlimit_focus(GtkEventControllerKey *key_controller,
+                                     gpointer               user_data);
 
 
 G_END_DECLS
diff --git a/src/balsa-mime-widget-message.c b/src/balsa-mime-widget-message.c
index bfc8c2fc4..79812591e 100644
--- a/src/balsa-mime-widget-message.c
+++ b/src/balsa-mime-widget-message.c
@@ -487,12 +487,11 @@ bm_header_widget_new(BalsaMessage * bm, GtkWidget * const * buttons)
     gtk_grid_set_column_spacing(GTK_GRID(grid), 12);
     gtk_widget_show(grid);
 
-    g_signal_connect(grid, "focus_in_event",
+    key_controller = gtk_event_controller_key_new(grid);
+    g_signal_connect(key_controller, "focus-in",
                     G_CALLBACK(balsa_mime_widget_limit_focus), bm);
-    g_signal_connect(grid, "focus_out_event",
+    g_signal_connect(key_controller, "focus-out",
                     G_CALLBACK(balsa_mime_widget_unlimit_focus), bm);
-
-    key_controller = gtk_event_controller_key_new(grid);
     g_signal_connect(key_controller, "key-pressed",
                     G_CALLBACK(balsa_mime_widget_key_pressed), bm);
 
diff --git a/src/balsa-mime-widget.c b/src/balsa-mime-widget.c
index be38f46d0..65ea90d6f 100644
--- a/src/balsa-mime-widget.c
+++ b/src/balsa-mime-widget.c
@@ -108,6 +108,7 @@ balsa_mime_widget_new(BalsaMessage * bm, LibBalsaMessageBody * mime_body, gpoint
     BalsaMimeWidget *mw = NULL;
     gchar *content_type;
     mime_delegate_t *delegate;
+    GtkEventController *key_controller;
 
     g_return_val_if_fail(bm != NULL, NULL);
     g_return_val_if_fail(mime_body != NULL, NULL);
@@ -128,9 +129,10 @@ balsa_mime_widget_new(BalsaMessage * bm, LibBalsaMessageBody * mime_body, gpoint
     if (mw == NULL)
        mw = balsa_mime_widget_new_unknown(bm, mime_body, content_type);
 
-    g_signal_connect(mw, "focus_in_event",
+    key_controller = gtk_event_controller_key_new(GTK_WIDGET(mw));
+    g_signal_connect(key_controller, "focus-in",
                      G_CALLBACK(balsa_mime_widget_limit_focus), bm);
-    g_signal_connect(mw, "focus_out_event",
+    g_signal_connect(key_controller, "focus-out",
                      G_CALLBACK(balsa_mime_widget_unlimit_focus), bm);
     if (mime_body->sig_info != NULL &&
         strcmp("application/pgp-signature", content_type) != 0 &&


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