[gnome-control-center/signal-connect-object: 11/16] display: Connect signals with g_signal_connect_object in swapped form



commit 16d1b111fa79cb229929d5e40c035a22823ece07
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Nov 22 12:17:13 2019 +1300

    display: Connect signals with g_signal_connect_object in swapped form

 panels/display/cc-display-panel.c    | 40 ++++++++++++++----------------------
 panels/display/cc-night-light-page.c | 27 +++++++++---------------
 2 files changed, 25 insertions(+), 42 deletions(-)
---
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index 843116d34..de49e5cce 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -388,12 +388,12 @@ reset_titlebar (CcDisplayPanel *self)
 }
 
 static void
-active_panel_changed (CcShell    *shell,
-                      GParamSpec *pspec,
-                      CcPanel    *self)
+active_panel_changed (CcPanel *self)
 {
+  CcShell *shell;
   g_autoptr(CcPanel) panel = NULL;
 
+  shell = cc_panel_get_shell (CC_PANEL (self));
   g_object_get (shell, "active-panel", &panel, NULL);
   if (panel != self)
     reset_titlebar (CC_DISPLAY_PANEL (self));
@@ -403,8 +403,6 @@ static void
 cc_display_panel_dispose (GObject *object)
 {
   CcDisplayPanel *self = CC_DISPLAY_PANEL (object);
-  CcShell *shell;
-  GtkWidget *toplevel;
 
   reset_titlebar (CC_DISPLAY_PANEL (object));
 
@@ -418,11 +416,6 @@ cc_display_panel_dispose (GObject *object)
 
   if (self->focus_id)
     {
-      shell = cc_panel_get_shell (CC_PANEL (object));
-      toplevel = cc_shell_get_toplevel (shell);
-      if (toplevel != NULL)
-        g_signal_handler_disconnect (G_OBJECT (toplevel),
-                                     self->focus_id);
       self->focus_id = 0;
       monitor_labeler_hide (CC_DISPLAY_PANEL (object));
     }
@@ -612,7 +605,7 @@ static void
 cc_display_panel_constructed (GObject *object)
 {
   g_signal_connect_object (cc_panel_get_shell (CC_PANEL (object)), "notify::active-panel",
-                           G_CALLBACK (active_panel_changed), object, 0);
+                           G_CALLBACK (active_panel_changed), object, G_CONNECT_SWAPPED);
 
   G_OBJECT_CLASS (cc_display_panel_parent_class)->constructed (object);
 }
@@ -1036,18 +1029,16 @@ mapped_cb (CcDisplayPanel *panel)
   shell = cc_panel_get_shell (CC_PANEL (panel));
   toplevel = cc_shell_get_toplevel (shell);
   if (toplevel && !panel->focus_id)
-    panel->focus_id = g_signal_connect_swapped (toplevel, "notify::has-toplevel-focus",
-                                               G_CALLBACK (dialog_toplevel_focus_changed), panel);
+    panel->focus_id = g_signal_connect_object (toplevel, "notify::has-toplevel-focus",
+                                               G_CALLBACK (dialog_toplevel_focus_changed), panel, 
G_CONNECT_SWAPPED);
 }
 
 static void
-cc_display_panel_up_client_changed (UpClient       *client,
-                                    GParamSpec     *pspec,
-                                    CcDisplayPanel *self)
+cc_display_panel_up_client_changed (CcDisplayPanel *self)
 {
   gboolean lid_is_closed;
 
-  lid_is_closed = up_client_get_lid_is_closed (client);
+  lid_is_closed = up_client_get_lid_is_closed (self->up_client);
 
   if (lid_is_closed != self->lid_is_closed)
     {
@@ -1107,10 +1098,9 @@ update_has_accel (CcDisplayPanel *self)
 }
 
 static void
-sensor_proxy_properties_changed_cb (GDBusProxy     *proxy,
+sensor_proxy_properties_changed_cb (CcDisplayPanel *self,
                                     GVariant       *changed_properties,
-                                    GStrv           invalidated_properties,
-                                    CcDisplayPanel *self)
+                                    GStrv           invalidated_properties)
 {
   GVariantDict dict;
 
@@ -1140,8 +1130,8 @@ sensor_proxy_appeared_cb (GDBusConnection *connection,
                                                         NULL);
   g_return_if_fail (self->iio_sensor_proxy);
 
-  g_signal_connect (self->iio_sensor_proxy, "g-properties-changed",
-                    G_CALLBACK (sensor_proxy_properties_changed_cb), self);
+  g_signal_connect_object (self->iio_sensor_proxy, "g-properties-changed",
+                           G_CALLBACK (sensor_proxy_properties_changed_cb), self, G_CONNECT_SWAPPED);
   update_has_accel (self);
 }
 
@@ -1235,9 +1225,9 @@ cc_display_panel_init (CcDisplayPanel *self)
   self->up_client = up_client_new ();
   if (up_client_get_lid_is_present (self->up_client))
     {
-      g_signal_connect (self->up_client, "notify::lid-is-closed",
-                        G_CALLBACK (cc_display_panel_up_client_changed), self);
-      cc_display_panel_up_client_changed (self->up_client, NULL, self);
+      g_signal_connect_object (self->up_client, "notify::lid-is-closed",
+                               G_CALLBACK (cc_display_panel_up_client_changed), self, G_CONNECT_SWAPPED);
+      cc_display_panel_up_client_changed (self);
     }
   else
     g_clear_object (&self->up_client);
diff --git a/panels/display/cc-night-light-page.c b/panels/display/cc-night-light-page.c
index a6bfd73b9..1b49ecea5 100644
--- a/panels/display/cc-night-light-page.c
+++ b/panels/display/cc-night-light-page.c
@@ -372,10 +372,7 @@ dialog_color_temperature_value_changed_cb (GtkAdjustment    *adjustment,
 }
 
 static void
-dialog_color_properties_changed_cb (GDBusProxy       *proxy,
-                                    GVariant         *changed_properties,
-                                    GStrv             invalidated_properties,
-                                    CcNightLightPage *self)
+dialog_color_properties_changed_cb (CcNightLightPage *self)
 {
   dialog_update_state (self);
 }
@@ -400,7 +397,7 @@ dialog_got_proxy_cb (GObject      *source_object,
   self->proxy_color = proxy;
 
   g_signal_connect_object (self->proxy_color, "g-properties-changed",
-                           G_CALLBACK (dialog_color_properties_changed_cb), self, 0);
+                           G_CALLBACK (dialog_color_properties_changed_cb), self, G_CONNECT_SWAPPED);
   dialog_update_state (self);
   self->timer_id = g_timeout_add_seconds (10, dialog_tick_cb, self);
 }
@@ -487,19 +484,15 @@ dialog_update_adjustments (CcNightLightPage *self)
 }
 
 static void
-dialog_settings_changed_cb (GSettings        *settings_display,
-                            gchar            *key,
-                            CcNightLightPage *self)
+dialog_settings_changed_cb (CcNightLightPage *self)
 {
   dialog_update_state (self);
 }
 
 static void
-dialog_clock_settings_changed_cb (GSettings        *settings_display,
-                                  gchar            *key,
-                                  CcNightLightPage *self)
+dialog_clock_settings_changed_cb (CcNightLightPage *self)
 {
-  self->clock_format = g_settings_get_enum (settings_display, CLOCK_FORMAT_KEY);
+  self->clock_format = g_settings_get_enum (self->settings_clock, CLOCK_FORMAT_KEY);
 
   /* uncontionally widen this to avoid truncation */
   gtk_adjustment_set_lower (self->adjustment_from_hours, 0);
@@ -636,7 +629,7 @@ cc_night_light_page_init (CcNightLightPage *self)
   self->cancellable = g_cancellable_new ();
   self->settings_display = g_settings_new (DISPLAY_SCHEMA);
 
-  g_signal_connect (self->settings_display, "changed", G_CALLBACK (dialog_settings_changed_cb), self);
+  g_signal_connect_object (self->settings_display, "changed", G_CALLBACK (dialog_settings_changed_cb), self, 
G_CONNECT_SWAPPED);
 
   build_schedule_combo_row (self);
 
@@ -690,10 +683,10 @@ cc_night_light_page_init (CcNightLightPage *self)
   self->settings_clock = g_settings_new (CLOCK_SCHEMA);
   self->clock_format = g_settings_get_enum (self->settings_clock, CLOCK_FORMAT_KEY);
   dialog_update_adjustments (self);
-  g_signal_connect (self->settings_clock,
-                    "changed::" CLOCK_FORMAT_KEY,
-                    G_CALLBACK (dialog_clock_settings_changed_cb),
-                    self);
+  g_signal_connect_object (self->settings_clock,
+                           "changed::" CLOCK_FORMAT_KEY,
+                           G_CALLBACK (dialog_clock_settings_changed_cb),
+                           self, G_CONNECT_SWAPPED);
 
   dialog_update_state (self);
 }


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