From 2611bc58e22d8f6bfea1c0147428e61ac0ad3c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Correa=20G=C3=B3mez?= Date: Mon, 11 Dec 2023 02:57:32 +0100 Subject: [PATCH] sound: fix compiler warning Fix many warnings of the form: ../panels/sound/cc-output-test-wheel.c: In function 'cc_output_test_wheel_dispose': ../panels/sound/cc-output-test-wheel.c:155:20: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 155 | g_clear_pointer ((GtkWidget**) &self->front_center_speaker_button, gtk_widget_unparent); /usr/include/glib-2.0/glib/gmacros.h:870:47: note: in definition of macro 'G_STATIC_ASSERT' 870 | #define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false") | ^~~~ ../panels/sound/cc-output-test-wheel.c:155:3: note: in expansion of macro 'g_clear_pointer' 155 | g_clear_pointer ((GtkWidget**) &self->front_center_speaker_button, gtk_widget_unparent); | ^~~~~~~~~~~~~~~ --- panels/sound/cc-output-test-wheel.c | 102 +++++++++++++------------- panels/sound/cc-speaker-test-button.c | 8 +- panels/sound/cc-speaker-test-button.h | 8 +- 3 files changed, 60 insertions(+), 58 deletions(-) diff --git a/panels/sound/cc-output-test-wheel.c b/panels/sound/cc-output-test-wheel.c index d5cff1816..7dfdca9c5 100644 --- a/panels/sound/cc-output-test-wheel.c +++ b/panels/sound/cc-output-test-wheel.c @@ -23,22 +23,22 @@ struct _CcOutputTestWheel { - GtkWidget parent_instance; + GtkWidget parent_instance; - GtkWidget *label; - CcSpeakerTestButton *front_center_speaker_button; - CcSpeakerTestButton *front_left_speaker_button; - CcSpeakerTestButton *front_left_of_center_speaker_button; - CcSpeakerTestButton *front_right_of_center_speaker_button; - CcSpeakerTestButton *front_right_speaker_button; - CcSpeakerTestButton *lfe_speaker_button; - CcSpeakerTestButton *rear_center_speaker_button; - CcSpeakerTestButton *rear_left_speaker_button; - CcSpeakerTestButton *rear_right_speaker_button; - CcSpeakerTestButton *side_left_speaker_button; - CcSpeakerTestButton *side_right_speaker_button; + GtkWidget *label; + GtkWidget *front_center_speaker_button; + GtkWidget *front_left_speaker_button; + GtkWidget *front_left_of_center_speaker_button; + GtkWidget *front_right_of_center_speaker_button; + GtkWidget *front_right_speaker_button; + GtkWidget *lfe_speaker_button; + GtkWidget *rear_center_speaker_button; + GtkWidget *rear_left_speaker_button; + GtkWidget *rear_right_speaker_button; + GtkWidget *side_left_speaker_button; + GtkWidget *side_right_speaker_button; - GSoundContext *context; + GSoundContext *context; }; G_DEFINE_TYPE (CcOutputTestWheel, cc_output_test_wheel, GTK_TYPE_WIDGET) @@ -55,25 +55,25 @@ load_custom_css (CcOutputTestWheel *self) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } -static CcSpeakerTestButton* +static GtkWidget* create_speaker_button (CcOutputTestWheel *self, pa_channel_position_t position) { - CcSpeakerTestButton *button; + GtkWidget *button; button = cc_speaker_test_button_new (self->context, position); - gtk_widget_add_css_class (GTK_WIDGET (button), "circular"); - gtk_widget_add_css_class (GTK_WIDGET (button), "opaque"); - gtk_widget_set_parent (GTK_WIDGET (button), GTK_WIDGET (self)); + gtk_widget_add_css_class (button, "circular"); + gtk_widget_add_css_class (button, "opaque"); + gtk_widget_set_parent (button, GTK_WIDGET (self)); return button; } static void -allocate_speaker_button (CcSpeakerTestButton *button, - int width, - int height, - double angle) +allocate_speaker_button (GtkWidget *button, + int width, + int height, + double angle) { double rad, norm_x, norm_y; GtkRequisition nat; @@ -83,14 +83,14 @@ allocate_speaker_button (CcSpeakerTestButton *button, norm_x = -(cos(rad) - 1) / 2; norm_y = -(sin(rad) - 1) / 2; - gtk_widget_get_preferred_size (GTK_WIDGET (button), NULL, &nat); + gtk_widget_get_preferred_size (button, NULL, &nat); allocation.width = nat.width; allocation.height = nat.height; allocation.x = (norm_x * width) - (allocation.width / 2); allocation.y = (norm_y * height) - (allocation.height / 2); - gtk_widget_size_allocate (GTK_WIDGET (button), &allocation, -1); + gtk_widget_size_allocate (button, &allocation, -1); } static void @@ -136,13 +136,13 @@ cc_output_test_wheel_size_allocate (GtkWidget *widget, allocate_speaker_button (self->rear_center_speaker_button, width, height, 270); allocate_speaker_button (self->rear_left_speaker_button, width, height, 315); - gtk_widget_get_preferred_size(GTK_WIDGET (self->lfe_speaker_button), NULL, &natural_size); + gtk_widget_get_preferred_size(self->lfe_speaker_button, NULL, &natural_size); allocation.width = natural_size.width; allocation.height = natural_size.height; allocation.x = (width / 2) - (allocation.width / 2); allocation.y = (height * 0.2) - (allocation.height / 2); - gtk_widget_size_allocate (GTK_WIDGET (self->lfe_speaker_button), &allocation, -1); + gtk_widget_size_allocate (self->lfe_speaker_button, &allocation, -1); } static void @@ -152,17 +152,17 @@ cc_output_test_wheel_dispose (GObject *object) g_clear_pointer (&self->label, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->front_center_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->front_left_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->front_left_of_center_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->front_right_of_center_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->front_right_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->lfe_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->rear_center_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->rear_left_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->rear_right_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->side_left_speaker_button, gtk_widget_unparent); - g_clear_pointer ((GtkWidget**) &self->side_right_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->front_center_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->front_left_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->front_left_of_center_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->front_right_of_center_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->front_right_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->lfe_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->rear_center_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->rear_left_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->rear_right_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->side_left_speaker_button, gtk_widget_unparent); + g_clear_pointer (&self->side_right_speaker_button, gtk_widget_unparent); g_clear_object (&self->context); @@ -229,16 +229,16 @@ cc_output_test_wheel_set_stream (CcOutputTestWheel *self, { const GvcChannelMap *map = gvc_mixer_stream_get_channel_map (stream); - gtk_widget_set_visible (GTK_WIDGET (self->front_left_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_LEFT)); - gtk_widget_set_visible (GTK_WIDGET (self->front_left_of_center_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER)); - gtk_widget_set_visible (GTK_WIDGET (self->front_right_of_center_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER)); - gtk_widget_set_visible (GTK_WIDGET (self->front_right_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_RIGHT)); - gtk_widget_set_visible (GTK_WIDGET (self->lfe_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_LFE)); - gtk_widget_set_visible (GTK_WIDGET (self->rear_center_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_REAR_CENTER)); - gtk_widget_set_visible (GTK_WIDGET (self->rear_left_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_REAR_LEFT)); - gtk_widget_set_visible (GTK_WIDGET (self->rear_right_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_REAR_RIGHT)); - gtk_widget_set_visible (GTK_WIDGET (self->side_left_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_SIDE_LEFT)); - gtk_widget_set_visible (GTK_WIDGET (self->side_right_speaker_button), gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_SIDE_RIGHT)); + gtk_widget_set_visible (self->front_left_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_LEFT)); + gtk_widget_set_visible (self->front_left_of_center_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER)); + gtk_widget_set_visible (self->front_right_of_center_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER)); + gtk_widget_set_visible (self->front_right_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_RIGHT)); + gtk_widget_set_visible (self->lfe_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_LFE)); + gtk_widget_set_visible (self->rear_center_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_REAR_CENTER)); + gtk_widget_set_visible (self->rear_left_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_REAR_LEFT)); + gtk_widget_set_visible (self->rear_right_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_REAR_RIGHT)); + gtk_widget_set_visible (self->side_left_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_SIDE_LEFT)); + gtk_widget_set_visible (self->side_right_speaker_button, gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_SIDE_RIGHT)); /* Replace the center channel with a mono channel */ if (gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_MONO)) @@ -246,12 +246,14 @@ cc_output_test_wheel_set_stream (CcOutputTestWheel *self, if (gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_CENTER)) g_warning ("Testing output with both front center and mono channels - front center is hidden"); - cc_speaker_test_button_set_channel_position (self->front_center_speaker_button, PA_CHANNEL_POSITION_MONO); + cc_speaker_test_button_set_channel_position (CC_SPEAKER_TEST_BUTTON (self->front_center_speaker_button), + PA_CHANNEL_POSITION_MONO); gtk_widget_set_visible (GTK_WIDGET (self->front_center_speaker_button), TRUE); } else if (gvc_channel_map_has_position (map, PA_CHANNEL_POSITION_FRONT_CENTER)) { - cc_speaker_test_button_set_channel_position (self->front_center_speaker_button, PA_CHANNEL_POSITION_FRONT_CENTER); + cc_speaker_test_button_set_channel_position (CC_SPEAKER_TEST_BUTTON (self->front_center_speaker_button), + PA_CHANNEL_POSITION_FRONT_CENTER); gtk_widget_set_visible (GTK_WIDGET (self->front_center_speaker_button), TRUE); } else diff --git a/panels/sound/cc-speaker-test-button.c b/panels/sound/cc-speaker-test-button.c index c47c8dab3..791eba3f2 100644 --- a/panels/sound/cc-speaker-test-button.c +++ b/panels/sound/cc-speaker-test-button.c @@ -202,7 +202,7 @@ cc_speaker_test_button_init (CcSpeakerTestButton *self) g_signal_connect (self, "clicked", G_CALLBACK (clicked_cb), NULL); } -CcSpeakerTestButton * +GtkWidget * cc_speaker_test_button_new (GSoundContext *context, pa_channel_position_t position) { @@ -217,12 +217,12 @@ cc_speaker_test_button_new (GSoundContext *context, -1); - return self; + return GTK_WIDGET (self); } void -cc_speaker_test_button_set_channel_position (CcSpeakerTestButton *self, - pa_channel_position_t position) +cc_speaker_test_button_set_channel_position (CcSpeakerTestButton *self, + pa_channel_position_t position) { g_return_if_fail (CC_IS_SPEAKER_TEST_BUTTON (self)); diff --git a/panels/sound/cc-speaker-test-button.h b/panels/sound/cc-speaker-test-button.h index e91cd3a17..8a2bd636b 100644 --- a/panels/sound/cc-speaker-test-button.h +++ b/panels/sound/cc-speaker-test-button.h @@ -26,10 +26,10 @@ G_BEGIN_DECLS #define CC_TYPE_SPEAKER_TEST_BUTTON (cc_speaker_test_button_get_type ()) G_DECLARE_FINAL_TYPE (CcSpeakerTestButton, cc_speaker_test_button, CC, SPEAKER_TEST_BUTTON, GtkButton) -CcSpeakerTestButton *cc_speaker_test_button_new (GSoundContext *context, - pa_channel_position_t position); +GtkWidget *cc_speaker_test_button_new (GSoundContext *context, + pa_channel_position_t position); -void cc_speaker_test_button_set_channel_position (CcSpeakerTestButton *button, - pa_channel_position_t position); +void cc_speaker_test_button_set_channel_position (CcSpeakerTestButton *button, + pa_channel_position_t position); G_END_DECLS