[gnome-control-center] display: Use ComboBox when folded
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] display: Use ComboBox when folded
- Date: Sat, 25 Sep 2021 20:33:47 +0000 (UTC)
commit 8868510e3316d21d6adc91c3e7522367080a5b64
Author: Guido Günther <agx sigxcpu org>
Date: Tue Aug 24 18:25:05 2021 +0200
display: Use ComboBox when folded
On small window sizes the ButtonBox can overflow the panel. This is
especially true in single display mode when no other elemnts prevent
shrinking to e.g. 360px width on phones. Use the ComboBox introduced in
632cb3c907922d4449e5758d218612ad5d8735c6 in these cases.
For that we introduce cc_display_settings_refresh_layout() to refresh
the layout when the folded state changes. This can later on be used for
more tweaks to shrink to smaller sizes.
panels/display/cc-display-panel.c | 19 +++++++-
panels/display/cc-display-settings.c | 84 +++++++++++++++++++-----------------
panels/display/cc-display-settings.h | 2 +
3 files changed, 65 insertions(+), 40 deletions(-)
---
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index f9d4ae044..91b3f3387 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -457,6 +457,7 @@ static void
cc_display_panel_dispose (GObject *object)
{
CcDisplayPanel *self = CC_DISPLAY_PANEL (object);
+ GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self)));
reset_titlebar (CC_DISPLAY_PANEL (object));
@@ -474,6 +475,8 @@ cc_display_panel_dispose (GObject *object)
g_clear_pointer ((GtkWidget **) &self->night_light_dialog, gtk_widget_destroy);
+ g_signal_handlers_disconnect_by_data (toplevel, self);
+
G_OBJECT_CLASS (cc_display_panel_parent_class)->dispose (object);
}
@@ -645,12 +648,26 @@ on_primary_display_selected_index_changed_cb (CcDisplayPanel *panel)
update_apply_button (panel);
}
+static void
+on_toplevel_folded (CcDisplayPanel *panel, GParamSpec *pspec, GtkWidget *toplevel)
+{
+ gboolean folded;
+
+ g_object_get (toplevel, "folded", &folded, NULL);
+ cc_display_settings_refresh_layout (panel->settings, folded);
+}
+
static void
cc_display_panel_constructed (GObject *object)
{
+ GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (object)));
+
g_signal_connect_object (cc_panel_get_shell (CC_PANEL (object)), "notify::active-panel",
G_CALLBACK (active_panel_changed), object, G_CONNECT_SWAPPED);
+ g_signal_connect_swapped (toplevel, "notify::folded", G_CALLBACK (on_toplevel_folded), object);
+ on_toplevel_folded (CC_DISPLAY_PANEL (object), NULL, toplevel);
+
G_OBJECT_CLASS (cc_display_panel_parent_class)->constructed (object);
}
@@ -928,7 +945,7 @@ reset_current_config (CcDisplayPanel *panel)
if (!current)
return;
-
+
cc_display_config_set_minimum_size (current, MINIMUM_WIDTH, MINIMUM_HEIGHT);
panel->current_config = current;
diff --git a/panels/display/cc-display-settings.c b/panels/display/cc-display-settings.c
index a4f914ecd..efda19473 100644
--- a/panels/display/cc-display-settings.c
+++ b/panels/display/cc-display-settings.c
@@ -35,6 +35,8 @@ struct _CcDisplaySettings
GtkDrawingArea object;
gboolean updating;
+ gboolean num_scales;
+ gboolean folded;
guint idle_udpate_id;
gboolean has_accelerometer;
@@ -393,57 +395,49 @@ cc_display_settings_rebuild_ui (CcDisplaySettings *self)
/* Scale row is usually shown. */
gtk_container_foreach (GTK_CONTAINER (self->scale_bbox), (GtkCallback) gtk_widget_destroy, NULL);
g_list_store_remove_all (self->scale_list);
- gtk_widget_set_visible (self->scale_buttons_row, FALSE);
- gtk_widget_set_visible (self->scale_combo_row, FALSE);
scales = cc_display_mode_get_supported_scales (current_mode);
+ self->num_scales = scales->len;
for (i = 0; i < scales->len; i++)
{
g_autofree gchar *scale_str = NULL;
+ g_autoptr(HdyValueObject) value_object = NULL;
double scale = g_array_index (scales, double, i);
+ GtkWidget *scale_btn;
gboolean is_selected;
+ /* ComboRow */
scale_str = make_scale_string (scale);
is_selected = G_APPROX_VALUE (cc_display_monitor_get_scale (self->selected_output),
scale, DBL_EPSILON);
- if (scales->len > MAX_SCALE_BUTTONS)
- {
- g_autoptr(HdyValueObject) value_object = NULL;
-
- value_object = hdy_value_object_new_collect (G_TYPE_STRING, scale_str);
- g_list_store_append (self->scale_list, value_object);
- g_object_set_data_full (G_OBJECT (value_object), "scale",
- g_memdup2 (&scale, sizeof (double)), g_free);
- if (is_selected)
- hdy_combo_row_set_selected_index (HDY_COMBO_ROW (self->scale_combo_row),
- g_list_model_get_n_items (G_LIST_MODEL (self->scale_list)) -
1);
- }
- else
- {
- GtkWidget *scale_btn = gtk_radio_button_new_with_label_from_widget (group, scale_str);
- g_object_set_data_full (G_OBJECT (scale_btn), "scale",
- g_memdup2 (&scale, sizeof (double)), g_free);
-
- if (!group)
- group = GTK_RADIO_BUTTON (scale_btn);
- gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (scale_btn), FALSE);
- gtk_widget_show (scale_btn);
- gtk_container_add (GTK_CONTAINER (self->scale_bbox), scale_btn);
- /* Set active before connecting the signal */
- if (is_selected)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scale_btn), TRUE);
-
- g_signal_connect_object (scale_btn,
- "notify::active",
- G_CALLBACK (on_scale_btn_active_changed_cb),
- self, 0);
- }
+ value_object = hdy_value_object_new_collect (G_TYPE_STRING, scale_str);
+ g_list_store_append (self->scale_list, value_object);
+ g_object_set_data_full (G_OBJECT (value_object), "scale",
+ g_memdup2 (&scale, sizeof (double)), g_free);
+ if (is_selected)
+ hdy_combo_row_set_selected_index (HDY_COMBO_ROW (self->scale_combo_row),
+ g_list_model_get_n_items (G_LIST_MODEL (self->scale_list)) - 1);
+
+ /* ButtonBox */
+ scale_btn = gtk_radio_button_new_with_label_from_widget (group, scale_str);
+ g_object_set_data_full (G_OBJECT (scale_btn), "scale",
+ g_memdup2 (&scale, sizeof (double)), g_free);
+
+ if (!group)
+ group = GTK_RADIO_BUTTON (scale_btn);
+ gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (scale_btn), FALSE);
+ gtk_widget_show (scale_btn);
+ gtk_container_add (GTK_CONTAINER (self->scale_bbox), scale_btn);
+ /* Set active before connecting the signal */
+ if (is_selected)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scale_btn), TRUE);
+
+ g_signal_connect_object (scale_btn,
+ "notify::active",
+ G_CALLBACK (on_scale_btn_active_changed_cb),
+ self, 0);
}
-
- if (scales->len > MAX_SCALE_BUTTONS)
- gtk_widget_set_visible (self->scale_combo_row, TRUE);
- else
- gtk_widget_set_visible (self->scale_buttons_row, scales->len > 1);
+ cc_display_settings_refresh_layout (self, self->folded);
gtk_widget_set_visible (self->underscanning_row,
cc_display_monitor_supports_underscanning (self->selected_output) &&
@@ -843,3 +837,15 @@ cc_display_settings_set_selected_output (CcDisplaySettings *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SELECTED_OUTPUT]);
}
+void
+cc_display_settings_refresh_layout (CcDisplaySettings *self,
+ gboolean folded)
+{
+ gboolean use_combo;
+
+ self->folded = folded;
+ use_combo = self->num_scales > MAX_SCALE_BUTTONS || (self->num_scales > 2 && folded);
+
+ gtk_widget_set_visible (self->scale_combo_row, use_combo);
+ gtk_widget_set_visible (self->scale_buttons_row, self->num_scales > 1 && !use_combo);
+}
diff --git a/panels/display/cc-display-settings.h b/panels/display/cc-display-settings.h
index 58709ddf7..de3c88d48 100644
--- a/panels/display/cc-display-settings.h
+++ b/panels/display/cc-display-settings.h
@@ -39,6 +39,8 @@ void cc_display_settings_set_config (CcDisplaySettings
CcDisplayMonitor* cc_display_settings_get_selected_output (CcDisplaySettings *settings);
void cc_display_settings_set_selected_output (CcDisplaySettings *settings,
CcDisplayMonitor *output);
+void cc_display_settings_refresh_layout (CcDisplaySettings *settings,
+ gboolean folded);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]