From 73469d3ba2150ae8b0408840e080ad3163891fbe Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 20 Nov 2019 12:36:42 +1300 Subject: [PATCH 1/2] display: Replace GtkStack child names with widget references The child names are easier to break if widgets are changed - this can't be detected by the compiler. --- panels/display/cc-display-panel.c | 12 ++++++---- panels/display/cc-display-panel.ui | 15 ++---------- panels/display/cc-night-light-page.c | 30 ++++++++++++++++------- panels/display/cc-night-light-page.ui | 34 --------------------------- 4 files changed, 31 insertions(+), 60 deletions(-) diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c index 7f64a31a13..5247930707 100644 --- a/panels/display/cc-display-panel.c +++ b/panels/display/cc-display-panel.c @@ -105,9 +105,11 @@ struct _CcDisplayPanel GtkWidget *config_type_switcher_frame; GtkLabel *current_output_label; GtkWidget *display_settings_frame; + GtkBox *multi_selection_box; GtkSwitch *output_enabled_switch; GtkComboBox *output_selection_combo; GtkStack *output_selection_stack; + GtkButtonBox *output_selection_two_buttonbox; GtkButtonBox *output_selection_two_first; GtkButtonBox *output_selection_two_second; HdyComboRow *primary_display_row; @@ -653,10 +655,12 @@ cc_display_panel_class_init (CcDisplayPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, config_type_single); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, current_output_label); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_frame); + gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, multi_selection_box); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, night_light_page); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_enabled_switch); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_combo); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_stack); + gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_two_buttonbox); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_two_first); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_two_second); gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, primary_display_row); @@ -825,9 +829,9 @@ rebuild_ui (CcDisplayPanel *panel) /* We need a switcher except in CLONE mode */ if (type == CC_DISPLAY_CONFIG_CLONE) - gtk_stack_set_visible_child_name (panel->output_selection_stack, "no-selection"); + gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET (panel->current_output_label)); else - gtk_stack_set_visible_child_name (panel->output_selection_stack, "two-selection"); + gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET (panel->output_selection_two_buttonbox)); } else if (n_usable_outputs > 1) { @@ -841,7 +845,7 @@ rebuild_ui (CcDisplayPanel *panel) if (type == CC_DISPLAY_CONFIG_CLONE || type > CC_DISPLAY_CONFIG_LAST_VALID) type = CC_DISPLAY_CONFIG_JOIN; - gtk_stack_set_visible_child_name (panel->output_selection_stack, "multi-selection"); + gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET (panel->multi_selection_box)); } else { @@ -853,7 +857,7 @@ rebuild_ui (CcDisplayPanel *panel) gtk_widget_set_visible (panel->config_type_switcher_frame, FALSE); gtk_widget_set_visible (panel->arrangement_frame, FALSE); - gtk_stack_set_visible_child_name (panel->output_selection_stack, "no-selection"); + gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET (panel->current_output_label)); } cc_panel_set_selected_type (panel, type); diff --git a/panels/display/cc-display-panel.ui b/panels/display/cc-display-panel.ui index ed5a414d27..9728bbf9e4 100644 --- a/panels/display/cc-display-panel.ui +++ b/panels/display/cc-display-panel.ui @@ -286,12 +286,9 @@ - - no-selection - - + True False expand @@ -326,13 +323,9 @@ - - two-selection - 1 - - + True False @@ -364,10 +357,6 @@ - - multi-selection - 2 - diff --git a/panels/display/cc-night-light-page.c b/panels/display/cc-night-light-page.c index a6bfd73b9c..0fe03f36fc 100644 --- a/panels/display/cc-night-light-page.c +++ b/panels/display/cc-night-light-page.c @@ -34,6 +34,10 @@ struct _CcNightLightPage { GtkBin parent; GtkWidget *box_manual; + GtkButton *button_from_am; + GtkButton *button_from_pm; + GtkButton *button_to_am; + GtkButton *button_to_pm; GtkWidget *infobar_disabled; GtkListBox *listbox; GtkWidget *scale_color_temperature; @@ -74,7 +78,9 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self, gdouble value, GtkAdjustment *adj_hours, GtkAdjustment *adj_mins, - GtkStack *stack) + GtkStack *stack, + GtkButton *button_am, + GtkButton *button_pm) { gdouble hours; gdouble mins = 0.f; @@ -109,10 +115,8 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self, gtk_adjustment_set_value (GTK_ADJUSTMENT (adj_mins), mins); self->ignore_value_changed = FALSE; - if (is_24h) - gtk_stack_set_visible_child_name (stack, "blank"); - else - gtk_stack_set_visible_child_name (stack, is_pm ? "pm" : "am"); + gtk_widget_set_visible (GTK_WIDGET (stack), !is_24h); + gtk_stack_set_visible_child (stack, is_pm ? GTK_WIDGET (button_pm) : GTK_WIDGET (button_am)); } static void @@ -165,7 +169,9 @@ dialog_update_state (CcNightLightPage *self) dialog_adjustments_set_frac_hours (self, value, self->adjustment_from_hours, self->adjustment_from_minutes, - self->stack_from); + self->stack_from, + self->button_from_am, + self->button_from_pm); /* set to */ if (automatic && self->proxy_color != NULL) @@ -190,7 +196,9 @@ dialog_update_state (CcNightLightPage *self) dialog_adjustments_set_frac_hours (self, value, self->adjustment_to_hours, self->adjustment_to_minutes, - self->stack_to); + self->stack_to, + self->button_to_am, + self->button_to_pm); self->ignore_value_changed = TRUE; value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature"); @@ -464,7 +472,7 @@ dialog_update_adjustments (CcNightLightPage *self) else { if (gtk_adjustment_get_value (self->adjustment_from_hours) > 12) - gtk_stack_set_visible_child_name (self->stack_from, "pm"); + gtk_stack_set_visible_child (self->stack_from, GTK_WIDGET (self->button_from_pm)); gtk_adjustment_set_lower (self->adjustment_from_hours, 1); gtk_adjustment_set_upper (self->adjustment_from_hours, 12); @@ -479,7 +487,7 @@ dialog_update_adjustments (CcNightLightPage *self) else { if (gtk_adjustment_get_value (self->adjustment_to_hours) > 12) - gtk_stack_set_visible_child_name (self->stack_to, "pm"); + gtk_stack_set_visible_child (self->stack_to, GTK_WIDGET (self->button_to_pm)); gtk_adjustment_set_lower (self->adjustment_to_hours, 1); gtk_adjustment_set_upper (self->adjustment_to_hours, 12); @@ -583,6 +591,10 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass) gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_minutes); gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_color_temperature); gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_manual); + gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_am); + gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_pm); + gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am); + gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm); gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled); gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox); gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch); diff --git a/panels/display/cc-night-light-page.ui b/panels/display/cc-night-light-page.ui index b79a642b22..9d66b67bb1 100644 --- a/panels/display/cc-night-light-page.ui +++ b/panels/display/cc-night-light-page.ui @@ -241,9 +241,6 @@ - - am - @@ -257,20 +254,6 @@ - - pm - 1 - - - - - True - False - - - blank - 2 - @@ -361,9 +344,6 @@ - - am - @@ -377,20 +357,6 @@ - - pm - 1 - - - - - True - False - - - blank - 2 - -- GitLab From f00a5e20cb78ec7a6749666baf2d25d04d6eb03c Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 20 Nov 2019 12:42:25 +1300 Subject: [PATCH 2/2] display: Fix wrong widget type used --- panels/display/cc-display-panel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c index 5247930707..1b8184dcc1 100644 --- a/panels/display/cc-display-panel.c +++ b/panels/display/cc-display-panel.c @@ -110,8 +110,8 @@ struct _CcDisplayPanel GtkComboBox *output_selection_combo; GtkStack *output_selection_stack; GtkButtonBox *output_selection_two_buttonbox; - GtkButtonBox *output_selection_two_first; - GtkButtonBox *output_selection_two_second; + GtkRadioButton *output_selection_two_first; + GtkRadioButton *output_selection_two_second; HdyComboRow *primary_display_row; GtkWidget *stack_switcher; }; -- GitLab