From 1e3569e2f6c2c418b84ea3aa6ce5f84166ec48a7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 31 Mar 2021 11:06:44 +0200 Subject: [PATCH 01/33] power: Fix possible assertion on startup When opening the Power panel, and if power-profiles-daemon isn't already started, we'll be autostarting it, making it send signals about all the changed properties, including "PerformanceInhibited" even if we don't have a Performance row. Ignore the property change if we don't have a row for it rather than asserting. #0 0x00007f73916bc292 in raise () from /lib64/libc.so.6 #1 0x00007f73916a58a4 in abort () from /lib64/libc.so.6 #2 0x00007f7393203ccc in g_assertion_message.cold () from /lib64/libglib-2.0.so.0 #3 0x00007f739325f22f in g_assertion_message_expr () from /lib64/libglib-2.0.so.0 #4 0x000055a4099e28ae in performance_profile_set_inhibited (self=0x55a40b37e320, self=0x55a40b37e320, performance_inhibited=) at ../panels/power/cc-power-panel.c:1366 #5 power_profiles_properties_changed_cb (self=0x55a40b37e320, changed_properties=, invalidated_properties=, proxy=) at ../panels/power/cc-power-panel.c:1425 #6 0x00007f7393332c2f in g_closure_invoke () from /lib64/libgobject-2.0.so.0 #7 0x00007f739334eea6 in signal_emit_unlocked_R () from /lib64/libgobject-2.0.so.0 1362 { 1363 CcPowerProfileRow *row; 1364 1365 row = self->power_profiles_row[CC_POWER_PROFILE_PERFORMANCE]; 1366 g_assert (row != NULL); 1367 cc_power_profile_row_set_performance_inhibited (row, performance_inhibited); 1368 } --- panels/power/cc-power-panel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index c9c4705da..0b8226a29 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -1363,7 +1363,8 @@ performance_profile_set_inhibited (CcPowerPanel *self, CcPowerProfileRow *row; row = self->power_profiles_row[CC_POWER_PROFILE_PERFORMANCE]; - g_assert (row != NULL); + if (!row) + return; cc_power_profile_row_set_performance_inhibited (row, performance_inhibited); } -- 2.32.0 From da2248d43f519f13b57e89cdc80bbbfe346ad463 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Thu, 7 Jan 2021 14:00:15 +0100 Subject: [PATCH 02/33] power: Simplifies keyboard navigation This drops the ability to loop through the page but significantly simplifies the code. I think this is a good tradeoff as looping is a rather unexpected behavior. --- panels/power/cc-power-panel.c | 70 ++--------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 0b8226a29..1d31a8a83 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -122,9 +122,6 @@ struct _CcPowerPanel gboolean has_batteries; char *chassis_type; - GList *boxes; - GList *boxes_reverse; - GDBusProxy *bt_rfkill; GDBusProxy *bt_properties; @@ -169,8 +166,6 @@ cc_power_panel_dispose (GObject *object) #ifdef HAVE_NETWORK_MANAGER g_clear_object (&self->nm_client); #endif - g_clear_pointer (&self->boxes, g_list_free); - g_clear_pointer (&self->boxes_reverse, g_list_free); if (self->iio_proxy_watch_id != 0) g_bus_unwatch_name (self->iio_proxy_watch_id); self->iio_proxy_watch_id = 0; @@ -869,60 +864,12 @@ nm_client_ready_cb (GObject *source_object, static gboolean keynav_failed_cb (CcPowerPanel *self, GtkDirectionType direction, GtkWidget *list) { - GtkWidget *next_list = NULL; - GList *item, *boxes_list; - gdouble value, lower, upper, page; - - /* Find the list in the list of GtkListBoxes */ - if (direction == GTK_DIR_DOWN) - boxes_list = self->boxes; - else - boxes_list = self->boxes_reverse; - - item = g_list_find (boxes_list, list); - g_assert (item); - item = item->next; - while (1) - { - if (item == NULL) - item = boxes_list; - - /* Avoid looping */ - if (item->data == list) - break; - - if (gtk_widget_is_visible (item->data)) - { - next_list = item->data; - break; - } - - item = item->next; - } - - if (next_list) - { - gtk_widget_child_focus (next_list, direction); - return TRUE; - } - - value = gtk_adjustment_get_value (self->focus_adjustment); - lower = gtk_adjustment_get_lower (self->focus_adjustment); - upper = gtk_adjustment_get_upper (self->focus_adjustment); - page = gtk_adjustment_get_page_size (self->focus_adjustment); + if (direction != GTK_DIR_UP && direction != GTK_DIR_DOWN) + return FALSE; - if (direction == GTK_DIR_UP && value > lower) - { - gtk_adjustment_set_value (self->focus_adjustment, lower); - return TRUE; - } - else if (direction == GTK_DIR_DOWN && value < upper - page) - { - gtk_adjustment_set_value (self->focus_adjustment, upper - page); - return TRUE; - } + direction == GTK_DIR_UP ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD; - return FALSE; + return gtk_widget_child_focus (GTK_WIDGET (self), direction); } static void @@ -1559,8 +1506,6 @@ setup_power_profiles (CcPowerPanel *self) gtk_widget_show (GTK_WIDGET (self->power_profile_section)); - self->boxes_reverse = g_list_prepend (self->boxes_reverse, self->power_profile_listbox); - props = g_variant_get_child_value (variant, 0); performance_inhibited = variant_lookup_string (props, "PerformanceInhibited"); active_profile = variant_lookup_string (props, "ActiveProfile"); @@ -1780,7 +1725,6 @@ cc_power_panel_init (CcPowerPanel *self) battery_label = g_markup_printf_escaped ("%s", _("Battery")); gtk_label_set_markup (self->battery_heading, battery_label); - self->boxes_reverse = g_list_prepend (self->boxes_reverse, self->battery_listbox); gtk_list_box_set_header_func (self->battery_listbox, cc_list_box_update_header_func, NULL, NULL); @@ -1790,7 +1734,6 @@ cc_power_panel_init (CcPowerPanel *self) device_label = g_markup_printf_escaped ("%s", _("Devices")); gtk_label_set_markup (self->device_heading, device_label); - self->boxes_reverse = g_list_prepend (self->boxes_reverse, self->device_listbox); gtk_list_box_set_header_func (self->device_listbox, cc_list_box_update_header_func, NULL, NULL); @@ -1809,7 +1752,6 @@ cc_power_panel_init (CcPowerPanel *self) power_saving_label = g_strdup_printf ("%s", _("Power Saving")); gtk_label_set_markup (self->power_saving_heading, power_saving_label); - self->boxes_reverse = g_list_prepend (self->boxes_reverse, self->power_saving_listbox); gtk_list_box_set_header_func (self->power_saving_listbox, cc_list_box_update_header_func, NULL, NULL); @@ -1817,15 +1759,11 @@ cc_power_panel_init (CcPowerPanel *self) general_label = g_markup_printf_escaped ("%s", _("Suspend & Power Button")); gtk_label_set_markup (self->general_heading, general_label); - self->boxes_reverse = g_list_prepend (self->boxes_reverse, self->general_listbox); gtk_list_box_set_header_func (self->general_listbox, cc_list_box_update_header_func, NULL, NULL); setup_general_section (self); - self->boxes = g_list_copy (self->boxes_reverse); - self->boxes = g_list_reverse (self->boxes); - /* populate batteries */ g_signal_connect_object (self->up_client, "device-added", G_CALLBACK (up_client_device_added), self, G_CONNECT_SWAPPED); g_signal_connect_object (self->up_client, "device-removed", G_CALLBACK (up_client_device_removed), self, G_CONNECT_SWAPPED); -- 2.32.0 From 25027f6c3c6928eeedb440fe2ca84412dae49ab2 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 8 Jan 2021 16:00:25 +0100 Subject: [PATCH 03/33] power: Don't set the vadjustment This is useless as GtkScrolledwindow already does it on the viewport it creates. --- panels/power/cc-power-panel.c | 9 --------- panels/power/cc-power-panel.ui | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 1d31a8a83..1a8cfa969 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -91,8 +91,6 @@ struct _CcPowerPanel GtkListBoxRow *kbd_brightness_row; CcBrightnessScale *kbd_brightness_scale; GtkSizeGroup *level_sizegroup; - GtkScrolledWindow *main_scroll; - HdyClamp *main_box; GtkListBoxRow *mobile_row; GtkSwitch *mobile_switch; GtkComboBox *power_button_combo; @@ -136,8 +134,6 @@ struct _CcPowerPanel #ifdef HAVE_NETWORK_MANAGER NMClient *nm_client; #endif - - GtkAdjustment *focus_adjustment; }; CC_PANEL_REGISTER (CcPowerPanel, cc_power_panel) @@ -1661,8 +1657,6 @@ cc_power_panel_class_init (CcPowerPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, kbd_brightness_row); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, kbd_brightness_scale); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, level_sizegroup); - gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, main_scroll); - gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, main_box); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, mobile_row); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, mobile_switch); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_button_combo); @@ -1775,7 +1769,4 @@ cc_power_panel_init (CcPowerPanel *self) G_CALLBACK (up_client_changed), self, G_CONNECT_SWAPPED); } up_client_changed (self); - - self->focus_adjustment = gtk_scrolled_window_get_vadjustment (self->main_scroll); - gtk_container_set_focus_vadjustment (GTK_CONTAINER (self->main_box), self->focus_adjustment); } diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui index ea3cf9322..d3e200d93 100644 --- a/panels/power/cc-power-panel.ui +++ b/panels/power/cc-power-panel.ui @@ -113,12 +113,12 @@ True False - + True False never - + True 32 32 -- 2.32.0 From caf3d70a7004552e0bb382a1a1220cdac9c0c1f0 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 8 Jan 2021 16:12:56 +0100 Subject: [PATCH 04/33] power: Use HdyComboRow for the Blank Screen row This simplifies the code a bit and modernizes the UI. --- panels/power/cc-power-panel.c | 110 ++++++++++++++++++++++++++------- panels/power/cc-power-panel.ui | 88 ++------------------------ 2 files changed, 92 insertions(+), 106 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 1a8cfa969..b046b2589 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -73,7 +73,7 @@ struct _CcPowerPanel GtkSizeGroup *battery_row_sizegroup; GtkBox *battery_section; GtkSizeGroup *battery_sizegroup; - GtkListBoxRow *blank_screen_row; + HdyComboRow *blank_screen_row; GtkListBoxRow *brightness_row; CcBrightnessScale *brightness_scale; GtkListBoxRow *bt_row; @@ -87,7 +87,6 @@ struct _CcPowerPanel GtkLabel *general_heading; GtkListBox *general_listbox; GtkBox *general_section; - GtkComboBox *idle_delay_combo; GtkListBoxRow *kbd_brightness_row; CcBrightnessScale *kbd_brightness_scale; GtkSizeGroup *level_sizegroup; @@ -577,6 +576,49 @@ set_value_for_combo (GtkComboBox *combo_box, gint value) gtk_combo_box_set_active_iter (combo_box, &new); } +static void +set_value_for_combo_row (HdyComboRow *combo_row, gint value) +{ + gboolean insert = FALSE; + guint insert_before = 0; + guint i; + HdyValueObject *new; + GListModel *model; + gint value_last = 0; + g_autofree gchar *text = NULL; + + /* try to make the UI match the setting */ + model = hdy_combo_row_get_model (combo_row); + for (i = 0; i < g_list_model_get_n_items (model); i++) + { + HdyValueObject *value_object = g_list_model_get_item (model, i); + gint value_tmp = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (value_object), "value")); + if (value_tmp == value) + { + hdy_combo_row_set_selected_index (combo_row, i); + return; + } + + /* Insert before if the next value is larger or the value is lower + * again (i.e. "Never" is zero and last). */ + if (!insert && (value_tmp > value || value_last > value_tmp)) + { + insert = TRUE; + insert_before = i; + } + + value_last = value_tmp; + } + + /* The value is not listed, so add it at the best point (or the end). */ + text = cc_util_time_to_string_text (value * 1000); + new = hdy_value_object_new_string (text); + g_object_set_data (G_OBJECT (new), "value", + GUINT_TO_POINTER (value)); + g_list_store_insert (G_LIST_STORE (model), insert_before, new); + hdy_combo_row_set_selected_index (combo_row, insert_before); +} + static void set_ac_battery_ui_mode (CcPowerPanel *self) { @@ -869,25 +911,18 @@ keynav_failed_cb (CcPowerPanel *self, GtkDirectionType direction, GtkWidget *lis } static void -idle_delay_combo_changed_cb (CcPowerPanel *self) +blank_screen_row_changed_cb (CcPowerPanel *self) { - GtkTreeIter iter; - GtkTreeModel *model; + GListModel *model; + gint selected_index; + HdyValueObject *value_object; gint value; - gboolean ret; - /* no selection */ - ret = gtk_combo_box_get_active_iter (self->idle_delay_combo, &iter); - if (!ret) - return; + model = hdy_combo_row_get_model (self->blank_screen_row); + selected_index = hdy_combo_row_get_selected_index (self->blank_screen_row); + value_object = g_list_model_get_item (model, selected_index); + value = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (value_object), "value")); - /* get entry */ - model = gtk_combo_box_get_model (self->idle_delay_combo); - gtk_tree_model_get (model, &iter, - 1, &value, - -1); - - /* set both keys */ g_settings_set_uint (self->session_settings, "idle-delay", value); } @@ -1171,6 +1206,37 @@ has_kbd_brightness_cb (CcPowerPanel *self, gtk_widget_set_visible (GTK_WIDGET (self->kbd_brightness_row), has_brightness); } +static void +populate_blank_screen_row (HdyComboRow *combo_row) +{ + g_autoptr (GListStore) list_store = g_list_store_new (HDY_TYPE_VALUE_OBJECT); + gint minutes[] = { 1, 2, 3, 4, 5, 8, 10, 12, 15 }; + guint i; + g_autoptr (HdyValueObject) never_value_object = NULL; + + for (i = 0; i < G_N_ELEMENTS (minutes); i++) + { + gchar *text = NULL; + g_autoptr (HdyValueObject) value_object = NULL; + + /* Translators: Option for "Blank Screen" in "Power" panel */ + text = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d minute", "%d minutes", minutes[i]), minutes[i]); + value_object = hdy_value_object_new_take_string (text); + + g_object_set_data (G_OBJECT (value_object), "value", GUINT_TO_POINTER (minutes[i] * 60)); + g_list_store_append (list_store, value_object); + } + + never_value_object = hdy_value_object_new_string (C_("Idle time", "Never")); + g_object_set_data (G_OBJECT (never_value_object), "value", GUINT_TO_POINTER (0)); + g_list_store_append (list_store, never_value_object); + + hdy_combo_row_bind_name_model (combo_row, + G_LIST_MODEL (list_store), + (HdyComboRowGetNameFunc) hdy_value_object_dup_string, + NULL, NULL); +} + static void setup_power_saving (CcPowerPanel *self) { @@ -1191,10 +1257,11 @@ setup_power_saving (CcPowerPanel *self) self->dim_screen_switch, "active", G_SETTINGS_BIND_DEFAULT); + g_signal_handlers_block_by_func (self->blank_screen_row, blank_screen_row_changed_cb, self); + populate_blank_screen_row (self->blank_screen_row); value = g_settings_get_uint (self->session_settings, "idle-delay"); - g_signal_handlers_block_by_func (self->idle_delay_combo, idle_delay_combo_changed_cb, self); - set_value_for_combo (self->idle_delay_combo, value); - g_signal_handlers_unblock_by_func (self->idle_delay_combo, idle_delay_combo_changed_cb, self); + set_value_for_combo_row (self->blank_screen_row, value); + g_signal_handlers_unblock_by_func (self->blank_screen_row, blank_screen_row_changed_cb, self); /* The default values for these settings are unfortunate for us; * timeout == 0, action == suspend means 'do nothing' - just @@ -1653,7 +1720,6 @@ cc_power_panel_class_init (CcPowerPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, general_heading); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, general_listbox); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, general_section); - gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, idle_delay_combo); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, kbd_brightness_row); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, kbd_brightness_scale); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, level_sizegroup); @@ -1683,7 +1749,7 @@ cc_power_panel_class_init (CcPowerPanelClass *klass) gtk_widget_class_bind_template_callback (widget_class, bt_switch_changed_cb); gtk_widget_class_bind_template_callback (widget_class, has_brightness_cb); gtk_widget_class_bind_template_callback (widget_class, has_kbd_brightness_cb); - gtk_widget_class_bind_template_callback (widget_class, idle_delay_combo_changed_cb); + gtk_widget_class_bind_template_callback (widget_class, blank_screen_row_changed_cb); gtk_widget_class_bind_template_callback (widget_class, keynav_failed_cb); gtk_widget_class_bind_template_callback (widget_class, mobile_switch_changed_cb); gtk_widget_class_bind_template_callback (widget_class, power_button_combo_changed_cb); diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui index d3e200d93..a9bb39b77 100644 --- a/panels/power/cc-power-panel.ui +++ b/panels/power/cc-power-panel.ui @@ -51,56 +51,6 @@ - - - - - - - - - - 1 minute - 60 - - - 2 minutes - 120 - - - 3 minutes - 180 - - - 4 minutes - 240 - - - 5 minutes - 300 - - - 8 minutes - 480 - - - 10 minutes - 600 - - - 12 minutes - 720 - - - 15 minutes - 900 - - - Never - 0 - - - @@ -447,41 +397,11 @@ - + True - False - False - - - True - 12 - 12 - 12 - - - True - True - True - end - _Blank Screen - 6 - 6 - True - 0 - idle_delay_combo - - - - - True - center - 0 - idle_time_liststore - - - - - + _Blank Screen + True + -- 2.32.0 From 7dbe681401f3f487f1e752a0569cf3d743a74187 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 8 Jan 2021 16:17:42 +0100 Subject: [PATCH 05/33] power: Use HdyComboRow for the Power Button Behavior row This simplifies the code a bit and modernizes the UI. --- panels/power/cc-power-panel.c | 71 ++++++++++++++++++---------------- panels/power/cc-power-panel.ui | 46 ++-------------------- 2 files changed, 42 insertions(+), 75 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index b046b2589..ea979cfc7 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -92,9 +92,7 @@ struct _CcPowerPanel GtkSizeGroup *level_sizegroup; GtkListBoxRow *mobile_row; GtkSwitch *mobile_switch; - GtkComboBox *power_button_combo; - GtkListStore *power_button_liststore; - GtkListBoxRow *power_button_row; + HdyComboRow *power_button_row; GtkLabel *power_profile_heading; GtkListBox *power_profile_listbox; GtkBox *power_profile_section; @@ -927,25 +925,18 @@ blank_screen_row_changed_cb (CcPowerPanel *self) } static void -power_button_combo_changed_cb (CcPowerPanel *self) +power_button_row_changed_cb (CcPowerPanel *self) { - GtkTreeIter iter; - GtkTreeModel *model; + GListModel *model; + gint selected_index; + HdyValueObject *value_object; gint value; - gboolean ret; - /* no selection */ - ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->power_button_combo), &iter); - if (!ret) - return; - - /* get entry */ - model = gtk_combo_box_get_model (GTK_COMBO_BOX (self->power_button_combo)); - gtk_tree_model_get (model, &iter, - 1, &value, - -1); + model = hdy_combo_row_get_model (self->power_button_row); + selected_index = hdy_combo_row_get_selected_index (self->power_button_row); + value_object = g_list_model_get_item (model, selected_index); + value = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (value_object), "value")); - /* set both keys */ g_settings_set_enum (self->gsd_settings, "power-button-action", value); } @@ -1048,10 +1039,11 @@ set_sleep_type (const GValue *value, } static void -populate_power_button_model (GtkTreeModel *model, - gboolean can_suspend, - gboolean can_hibernate) +populate_power_button_row (HdyComboRow *combo_row, + gboolean can_suspend, + gboolean can_hibernate) { + g_autoptr (GListStore) list_store = NULL; struct { char *name; GsdPowerButtonActionType value; @@ -1063,20 +1055,28 @@ populate_power_button_model (GtkTreeModel *model, }; guint i; + list_store = g_list_store_new (HDY_TYPE_VALUE_OBJECT); for (i = 0; i < G_N_ELEMENTS (actions); i++) { + g_autoptr (HdyValueObject) value_object = NULL; + if (!can_suspend && actions[i].value == GSD_POWER_BUTTON_ACTION_SUSPEND) continue; if (!can_hibernate && actions[i].value == GSD_POWER_BUTTON_ACTION_HIBERNATE) continue; - gtk_list_store_insert_with_values (GTK_LIST_STORE (model), - NULL, -1, - 0, _(actions[i].name), - 1, actions[i].value, - -1); + value_object = hdy_value_object_new_string (actions[i].name); + g_object_set_data (G_OBJECT (value_object), + "value", + GUINT_TO_POINTER (actions[i].value)); + g_list_store_append (list_store, value_object); } + + hdy_combo_row_bind_name_model (combo_row, + G_LIST_MODEL (list_store), + (HdyComboRowGetNameFunc) hdy_value_object_dup_string, + NULL, NULL); } #define NEVER 0 @@ -1635,10 +1635,17 @@ setup_general_section (CcPowerPanel *self) { gtk_widget_show (GTK_WIDGET (self->power_button_row)); - populate_power_button_model (GTK_TREE_MODEL (self->power_button_liststore), can_suspend, can_hibernate); - g_signal_handlers_block_by_func (self->power_button_combo, power_button_combo_changed_cb, self); - set_value_for_combo (self->power_button_combo, g_settings_get_enum (self->gsd_settings, "power-button-action")); - g_signal_handlers_unblock_by_func (self->power_button_combo, power_button_combo_changed_cb, self); + g_signal_handlers_block_by_func (self->power_button_row, + power_button_row_changed_cb, + self); + populate_power_button_row (self->power_button_row, + can_suspend, + can_hibernate); + set_value_for_combo_row (self->power_button_row, + g_settings_get_enum (self->gsd_settings, "power-button-action")); + g_signal_handlers_unblock_by_func (self->power_button_row, + power_button_row_changed_cb, + self); show_section = TRUE; } @@ -1725,8 +1732,6 @@ cc_power_panel_class_init (CcPowerPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, level_sizegroup); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, mobile_row); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, mobile_switch); - gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_button_combo); - gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_button_liststore); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_button_row); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_heading); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_listbox); @@ -1752,7 +1757,7 @@ cc_power_panel_class_init (CcPowerPanelClass *klass) gtk_widget_class_bind_template_callback (widget_class, blank_screen_row_changed_cb); gtk_widget_class_bind_template_callback (widget_class, keynav_failed_cb); gtk_widget_class_bind_template_callback (widget_class, mobile_switch_changed_cb); - gtk_widget_class_bind_template_callback (widget_class, power_button_combo_changed_cb); + gtk_widget_class_bind_template_callback (widget_class, power_button_row_changed_cb); gtk_widget_class_bind_template_callback (widget_class, power_profiles_row_activated_cb); gtk_widget_class_bind_template_callback (widget_class, power_saving_listbox_row_activated_cb); gtk_widget_class_bind_template_callback (widget_class, wifi_switch_changed_cb); diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui index a9bb39b77..18fc0a8ac 100644 --- a/panels/power/cc-power-panel.ui +++ b/panels/power/cc-power-panel.ui @@ -51,14 +51,6 @@ - - - - - - - - -- 2.32.0 From 58480754efd5fdc66db0940ce5c19abfbd2158b6 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Thu, 7 Jan 2021 14:37:56 +0100 Subject: [PATCH 08/33] power: Fix the indentation The indentation was purposefully left incorrect in the previous commits to ease the review of the actual changes, this fixes it. --- panels/power/cc-power-panel.ui | 426 ++++++++++++++++----------------- 1 file changed, 213 insertions(+), 213 deletions(-) diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui index 26d6ffddc..8e999c6d5 100644 --- a/panels/power/cc-power-panel.ui +++ b/panels/power/cc-power-panel.ui @@ -57,238 +57,238 @@ True + + + True + Battery + + + + + + True + none + + + + + + + + + + + + True + Devices + + + + + + True + none + + + + + + + + + + + + False + Power Mode + Affects system performance and power usage. + + + + + + True + none + + + + + + + + + + + + + True + Power Saving + + + True + _Screen Brightness + True - + True - Battery - - - - - - True - none - - - - - - - + center + True + screen + + + + + + True + Automatic Brightness - + True - Devices - - - - - - True - none - - - - - - - + center + + + + + + True + _Keyboard Brightness + True - - False - Power Mode - Affects system performance and power usage. - - - - - - True - none - - - - - - - - + + True + center + True + kbd + + + + + + True + Dim Screen When Inactive + dim_screen_switch - + True - Power Saving - - - True - _Screen Brightness - True - - - True - center - True - screen - - - - - - - - True - Automatic Brightness - - - True - center - - - - - - - - True - _Keyboard Brightness - True - - - True - center - True - kbd - - - - - - - - True - Dim Screen When Inactive - dim_screen_switch - - - True - center - - - - - - - True - _Blank Screen - True - - - - - - False - _Automatic Suspend - True - True - - - - True - end - - - - - - - - False - _Wi-Fi - Wi-Fi can be turned off to save power. - True - wifi_switch - - - True - center - - - - - - - - False - _Mobile Broadband - Mobile broadband (LTE, 4G, 3G, etc.) can be turned off to save power. - True - mobile_switch - - - True - center - - - - - - - - False - _Bluetooth - Bluetooth can be turned off to save power. - True - bt_switch - - - True - center - - - - - + center + + + + + True + _Blank Screen + True + + + + + + False + _Automatic Suspend + True + True + + + + True + end + + + + + + + + False + _Wi-Fi + Wi-Fi can be turned off to save power. + True + wifi_switch + + + True + center + + + + + + + + False + _Mobile Broadband + Mobile broadband (LTE, 4G, 3G, etc.) can be turned off to save power. + True + mobile_switch + + + True + center + + + + + + + + False + _Bluetooth + Bluetooth can be turned off to save power. + True + bt_switch - + True - Suspend & Power Button - - - False - Po_wer Button Behavior - True - - - - - - False - Show Battery _Percentage - True - battery_percentage_switch - - - True - center - - - - + center + + + + + + + + True + Suspend & Power Button + + + False + Po_wer Button Behavior + True + + + + + + False + Show Battery _Percentage + True + battery_percentage_switch + + + True + center + + + + + + -- 2.32.0 From 036545ebc5b3deba1d4bb4ac82dc102413804e83 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 8 Jan 2021 16:29:18 +0100 Subject: [PATCH 09/33] power: Hide the icon of the battery row when unused This gives more room to the label. --- panels/power/cc-battery-row.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/panels/power/cc-battery-row.c b/panels/power/cc-battery-row.c index 55d7584d7..f6faca0c1 100644 --- a/panels/power/cc-battery-row.c +++ b/panels/power/cc-battery-row.c @@ -275,7 +275,12 @@ cc_battery_row_new (UpDevice *device, /* Icon */ if (is_kind_battery && icon_name != NULL && icon_name[0] != '\0') - gtk_image_set_from_icon_name (self->icon, icon_name, GTK_ICON_SIZE_BUTTON); + { + gtk_image_set_from_icon_name (self->icon, icon_name, GTK_ICON_SIZE_BUTTON); + gtk_widget_show (GTK_WIDGET (self->icon)); + } + else + gtk_widget_hide (GTK_WIDGET (self->icon)); /* Percentage label */ if (battery_level == UP_DEVICE_LEVEL_NONE) @@ -347,4 +352,4 @@ UpDeviceKind cc_battery_row_get_kind (CcBatteryRow *self) { return self->kind; -} \ No newline at end of file +} -- 2.32.0 From c4849778de730f37618120dbdd37f30515ecc77a Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 8 Jan 2021 16:30:12 +0100 Subject: [PATCH 10/33] power: Ellipsize the labels of the battery row This helps the window fit any size, including the narrow one of phones. --- panels/power/cc-battery-row.ui | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/panels/power/cc-battery-row.ui b/panels/power/cc-battery-row.ui index 932e5d39f..dec97a9fe 100644 --- a/panels/power/cc-battery-row.ui +++ b/panels/power/cc-battery-row.ui @@ -28,6 +28,8 @@ True + end + 0 @@ -79,6 +81,8 @@ True + end + 0 -- 2.32.0 From 33d672d634a9e1d8a2cfa74dc4d503fb6f170ea1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 15 Jul 2021 13:08:05 +0200 Subject: [PATCH 11/33] power: Fix keynav not working MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gnome-control-center/panels/power/cc-power-panel.c: In function ‘keynav_failed_cb’: gnome-control-center/panels/power/cc-power-panel.c:892:50: warning: statement with no effect [-Wunused-value] 892 | direction == GTK_DIR_UP ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ --- panels/power/cc-power-panel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 96558c778..d31d16d22 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -888,7 +888,7 @@ keynav_failed_cb (CcPowerPanel *self, GtkDirectionType direction, GtkWidget *lis if (direction != GTK_DIR_UP && direction != GTK_DIR_DOWN) return FALSE; - direction == GTK_DIR_UP ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD; + direction = GTK_DIR_UP ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD; return gtk_widget_child_focus (GTK_WIDGET (self), direction); } -- 2.32.0 From 35b621ce5191461b16eefcb5e677496c0c48638c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 15 Jul 2021 13:46:19 +0200 Subject: [PATCH 12/33] power: Simplify emptying listbox We do that in a few places. --- panels/power/cc-power-panel.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index d31d16d22..5d57afe59 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -242,25 +242,29 @@ add_device (CcPowerPanel *self, UpDevice *device) } static void -up_client_changed (CcPowerPanel *self) +empty_listbox (GtkListBox *listbox) { - g_autoptr(GList) battery_children = NULL; - g_autoptr(GList) device_children = NULL; + g_autoptr(GList) children = NULL; GList *l; + + children = gtk_container_get_children (GTK_CONTAINER (listbox)); + for (l = children; l != NULL; l = l->next) + gtk_container_remove (GTK_CONTAINER (listbox), l->data); +} + +static void +up_client_changed (CcPowerPanel *self) +{ gint i; UpDeviceKind kind; guint n_batteries; gboolean on_ups; g_autoptr(UpDevice) composite = NULL; - battery_children = gtk_container_get_children (GTK_CONTAINER (self->battery_listbox)); - for (l = battery_children; l != NULL; l = l->next) - gtk_container_remove (GTK_CONTAINER (self->battery_listbox), l->data); + empty_listbox (self->battery_listbox); gtk_widget_hide (GTK_WIDGET (self->battery_section)); - device_children = gtk_container_get_children (GTK_CONTAINER (self->device_listbox)); - for (l = device_children; l != NULL; l = l->next) - gtk_container_remove (GTK_CONTAINER (self->device_listbox), l->data); + empty_listbox (self->device_listbox); gtk_widget_hide (GTK_WIDGET (self->device_section)); #ifdef TEST_FAKE_DEVICES -- 2.32.0 From 7915830b4d8b691f4def35c83c06a658f5b14ac1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 15 Jul 2021 14:39:58 +0200 Subject: [PATCH 13/33] power: Add new power profile info row widget --- panels/power/cc-power-panel.c | 1 + panels/power/cc-power-profile-info-row.c | 67 ++++++++++ panels/power/cc-power-profile-info-row.h | 36 ++++++ panels/power/cc-power-profile-info-row.ui | 44 +++++++ panels/power/icons/info-symbolic.svg | 150 ++++++++++++++++++++++ panels/power/icons/meson.build | 5 + panels/power/meson.build | 1 + panels/power/power.gresource.xml | 1 + 8 files changed, 305 insertions(+) create mode 100644 panels/power/cc-power-profile-info-row.c create mode 100644 panels/power/cc-power-profile-info-row.h create mode 100644 panels/power/cc-power-profile-info-row.ui create mode 100644 panels/power/icons/info-symbolic.svg diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 5d57afe59..8acf62dee 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -35,6 +35,7 @@ #include "cc-battery-row.h" #include "cc-brightness-scale.h" #include "cc-power-profile-row.h" +#include "cc-power-profile-info-row.h" #include "cc-power-panel.h" #include "cc-power-resources.h" #include "cc-util.h" diff --git a/panels/power/cc-power-profile-info-row.c b/panels/power/cc-power-profile-info-row.c new file mode 100644 index 000000000..92bb78834 --- /dev/null +++ b/panels/power/cc-power-profile-info-row.c @@ -0,0 +1,67 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* cc-list-row.c + * + * Copyright 2020 Red Hat Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Author(s): + * Bastien Nocera + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "cc-power-profile-info-row" + +#include + +#include +#include "cc-power-profile-info-row.h" + +struct _CcPowerProfileInfoRow +{ + GtkListBoxRow parent_instance; + + GtkLabel *title_label; +}; + +G_DEFINE_TYPE (CcPowerProfileInfoRow, cc_power_profile_info_row, GTK_TYPE_LIST_BOX_ROW) + +static void +cc_power_profile_info_row_class_init (CcPowerProfileInfoRowClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/power/cc-power-profile-info-row.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcPowerProfileInfoRow, title_label); +} + +static void +cc_power_profile_info_row_init (CcPowerProfileInfoRow *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +CcPowerProfileInfoRow * +cc_power_profile_info_row_new (const char *text) +{ + CcPowerProfileInfoRow *self; + + self = g_object_new (CC_TYPE_POWER_PROFILE_INFO_ROW, NULL); + gtk_label_set_markup (self->title_label, text); + + return self; +} diff --git a/panels/power/cc-power-profile-info-row.h b/panels/power/cc-power-profile-info-row.h new file mode 100644 index 000000000..52d055ab2 --- /dev/null +++ b/panels/power/cc-power-profile-info-row.h @@ -0,0 +1,36 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* cc-list-row.h + * + * Copyright 2020 Red Hat Inc + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Author(s): + * Bastien Nocera + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define CC_TYPE_POWER_PROFILE_INFO_ROW (cc_power_profile_info_row_get_type()) +G_DECLARE_FINAL_TYPE (CcPowerProfileInfoRow, cc_power_profile_info_row, CC, POWER_PROFILE_INFO_ROW, GtkListBoxRow) + +CcPowerProfileInfoRow *cc_power_profile_info_row_new (const char *text); + +G_END_DECLS diff --git a/panels/power/cc-power-profile-info-row.ui b/panels/power/cc-power-profile-info-row.ui new file mode 100644 index 000000000..d9291ff16 --- /dev/null +++ b/panels/power/cc-power-profile-info-row.ui @@ -0,0 +1,44 @@ + + + + + diff --git a/panels/power/icons/info-symbolic.svg b/panels/power/icons/info-symbolic.svg new file mode 100644 index 000000000..502a98a50 --- /dev/null +++ b/panels/power/icons/info-symbolic.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/power/icons/meson.build b/panels/power/icons/meson.build index 8165371ea..c56bc65b7 100644 --- a/panels/power/icons/meson.build +++ b/panels/power/icons/meson.build @@ -13,3 +13,8 @@ foreach icon_size: icon_sizes install_dir: join_paths(control_center_icondir, 'hicolor', icon_size, 'apps') ) endforeach + +install_data( + 'info-symbolic.svg', + install_dir: join_paths(control_center_icondir, 'hicolor', 'scalable', 'status') +) diff --git a/panels/power/meson.build b/panels/power/meson.build index 625059dd2..af04b98ed 100644 --- a/panels/power/meson.build +++ b/panels/power/meson.build @@ -22,6 +22,7 @@ sources = files( 'cc-brightness-scale.c', 'cc-power-panel.c', 'cc-power-profile-row.c', + 'cc-power-profile-info-row.c' ) sources += gnome.mkenums_simple( diff --git a/panels/power/power.gresource.xml b/panels/power/power.gresource.xml index 31e92b415..5a33c8e60 100644 --- a/panels/power/power.gresource.xml +++ b/panels/power/power.gresource.xml @@ -4,6 +4,7 @@ cc-battery-row.ui cc-power-panel.ui cc-power-profile-row.ui + cc-power-profile-info-row.ui battery-levels.css power-profiles.css -- 2.32.0 From 1a80fda8cdbd2226a5663f0fa572dd72210722a6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 2 Apr 2021 13:10:19 +0200 Subject: [PATCH 14/33] power: Handle new power-profiles-daemon API Handle the new PerformanceDegraded property to replace PerformanceInhibited. --- panels/power/cc-power-panel.c | 53 +++++++++++++++++++++++++++++++--- panels/power/cc-power-panel.ui | 11 +++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 8acf62dee..51196a8c4 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -89,6 +89,7 @@ struct _CcPowerPanel GtkSwitch *mobile_switch; HdyComboRow *power_button_row; GtkListBox *power_profile_listbox; + GtkListBox *power_profile_info_listbox; HdyPreferencesGroup *power_profile_section; GtkSizeGroup *row_sizegroup; GtkComboBox *suspend_on_battery_delay_combo; @@ -119,6 +120,7 @@ struct _CcPowerPanel guint power_profiles_prop_id; CcPowerProfileRow *power_profiles_row[NUM_CC_POWER_PROFILES]; gboolean power_profiles_in_update; + gboolean has_performance_degraded; #ifdef HAVE_NETWORK_MANAGER NMClient *nm_client; @@ -1365,6 +1367,37 @@ performance_profile_set_inhibited (CcPowerPanel *self, cc_power_profile_row_set_performance_inhibited (row, performance_inhibited); } +static void +performance_profile_set_degraded (CcPowerPanel *self) +{ + g_autoptr(GVariant) variant = NULL; + const char *degraded, *text; + CcPowerProfileInfoRow *row; + + empty_listbox (self->power_profile_info_listbox); + gtk_widget_hide (GTK_WIDGET (self->power_profile_info_listbox)); + + variant = g_dbus_proxy_get_cached_property (self->power_profiles_proxy, "PerformanceDegraded"); + if (!variant) + return; + degraded = g_variant_get_string (variant, NULL); + if (*degraded == '\0') + return; + + gtk_widget_show (GTK_WIDGET (self->power_profile_info_listbox)); + + if (g_str_equal (degraded, "high-operating-temperature")) + text = _("Performance mode temporarily disabled due to high operating temperature."); + else if (g_str_equal (degraded, "lap-detected")) + text = _("Lap detected: performance mode temporarily disabled. Move the device to a stable surface to restore."); + else + text = _("Performance mode temporarily disabled."); + + row = cc_power_profile_info_row_new (text); + gtk_widget_show (GTK_WIDGET (row)); + gtk_container_add (GTK_CONTAINER (self->power_profile_info_listbox), GTK_WIDGET (row)); +} + static void power_profiles_row_activated_cb (GtkListBox *box, GtkListBoxRow *box_row, @@ -1420,8 +1453,13 @@ power_profiles_properties_changed_cb (CcPowerPanel *self, { if (g_strcmp0 (key, "PerformanceInhibited") == 0) { - performance_profile_set_inhibited (self, - g_variant_get_string (value, NULL)); + if (!self->has_performance_degraded) + performance_profile_set_inhibited (self, + g_variant_get_string (value, NULL)); + } + else if (g_strcmp0 (key, "PerformanceDegraded") == 0) + { + performance_profile_set_degraded (self); } else if (g_strcmp0 (key, "ActiveProfile") == 0) { @@ -1504,7 +1542,8 @@ setup_power_profiles (CcPowerPanel *self) g_autoptr(GVariant) props = NULL; guint i, num_children; g_autoptr(GError) error = NULL; - const char *performance_inhibited; + const char *performance_inhibited = NULL; + const char *performance_degraded; const char *active_profile; g_autoptr(GVariant) profiles = NULL; GtkRadioButton *last_button; @@ -1557,7 +1596,12 @@ setup_power_profiles (CcPowerPanel *self) gtk_widget_show (GTK_WIDGET (self->power_profile_section)); props = g_variant_get_child_value (variant, 0); - performance_inhibited = variant_lookup_string (props, "PerformanceInhibited"); + performance_degraded = variant_lookup_string (props, "PerformanceDegraded"); + self->has_performance_degraded = performance_degraded != NULL; + if (performance_degraded == NULL) + performance_inhibited = variant_lookup_string (props, "PerformanceInhibited"); + else + performance_profile_set_degraded (self); active_profile = variant_lookup_string (props, "ActiveProfile"); last_button = NULL; @@ -1715,6 +1759,7 @@ cc_power_panel_class_init (CcPowerPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, mobile_switch); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_button_row); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_listbox); + gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_info_listbox); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_section); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, row_sizegroup); gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, suspend_on_battery_delay_combo); diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui index 8e999c6d5..d8283c556 100644 --- a/panels/power/cc-power-panel.ui +++ b/panels/power/cc-power-panel.ui @@ -123,6 +123,17 @@ + + + False + none + 12 + + + + -- 2.32.0 From 7254da88faa5cebd43db735746eb20b2b548a462 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 16 Jul 2021 10:00:12 +0200 Subject: [PATCH 15/33] power: Prepare for adding more power profile info boxes Rename and re-indent the code that adds the power profile info boxes to prepare for adding more info boxes when needed. --- panels/power/cc-power-panel.c | 46 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 51196a8c4..1869be065 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -1368,34 +1368,35 @@ performance_profile_set_inhibited (CcPowerPanel *self, } static void -performance_profile_set_degraded (CcPowerPanel *self) +power_profile_update_info_boxes (CcPowerPanel *self) { - g_autoptr(GVariant) variant = NULL; - const char *degraded, *text; + g_autoptr(GVariant) degraded_variant = NULL; + const char *degraded = NULL; CcPowerProfileInfoRow *row; empty_listbox (self->power_profile_info_listbox); gtk_widget_hide (GTK_WIDGET (self->power_profile_info_listbox)); - variant = g_dbus_proxy_get_cached_property (self->power_profiles_proxy, "PerformanceDegraded"); - if (!variant) - return; - degraded = g_variant_get_string (variant, NULL); - if (*degraded == '\0') - return; + degraded_variant = g_dbus_proxy_get_cached_property (self->power_profiles_proxy, "PerformanceDegraded"); + if (degraded_variant) + degraded = g_variant_get_string (degraded_variant, NULL); + if (degraded && *degraded != '\0') + { + const char *text; - gtk_widget_show (GTK_WIDGET (self->power_profile_info_listbox)); + gtk_widget_show (GTK_WIDGET (self->power_profile_info_listbox)); - if (g_str_equal (degraded, "high-operating-temperature")) - text = _("Performance mode temporarily disabled due to high operating temperature."); - else if (g_str_equal (degraded, "lap-detected")) - text = _("Lap detected: performance mode temporarily disabled. Move the device to a stable surface to restore."); - else - text = _("Performance mode temporarily disabled."); + if (g_str_equal (degraded, "high-operating-temperature")) + text = _("Performance mode temporarily disabled due to high operating temperature."); + else if (g_str_equal (degraded, "lap-detected")) + text = _("Lap detected: performance mode temporarily disabled. Move the device to a stable surface to restore."); + else + text = _("Performance mode temporarily disabled."); - row = cc_power_profile_info_row_new (text); - gtk_widget_show (GTK_WIDGET (row)); - gtk_container_add (GTK_CONTAINER (self->power_profile_info_listbox), GTK_WIDGET (row)); + row = cc_power_profile_info_row_new (text); + gtk_widget_show (GTK_WIDGET (row)); + gtk_container_add (GTK_CONTAINER (self->power_profile_info_listbox), GTK_WIDGET (row)); + } } static void @@ -1459,7 +1460,7 @@ power_profiles_properties_changed_cb (CcPowerPanel *self, } else if (g_strcmp0 (key, "PerformanceDegraded") == 0) { - performance_profile_set_degraded (self); + power_profile_update_info_boxes (self); } else if (g_strcmp0 (key, "ActiveProfile") == 0) { @@ -1600,8 +1601,6 @@ setup_power_profiles (CcPowerPanel *self) self->has_performance_degraded = performance_degraded != NULL; if (performance_degraded == NULL) performance_inhibited = variant_lookup_string (props, "PerformanceInhibited"); - else - performance_profile_set_degraded (self); active_profile = variant_lookup_string (props, "ActiveProfile"); last_button = NULL; @@ -1649,6 +1648,9 @@ setup_power_profiles (CcPowerPanel *self) self->power_profiles_prop_id = g_signal_connect_object (G_OBJECT (self->power_profiles_proxy), "g-properties-changed", G_CALLBACK (power_profiles_properties_changed_cb), self, G_CONNECT_SWAPPED); + + if (self->has_performance_degraded) + power_profile_update_info_boxes (self); } static void -- 2.32.0 From 173904b7eeea145c38065939a1dd8a408745f3c9 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 16 Jul 2021 10:07:28 +0200 Subject: [PATCH 16/33] power: Move variant_lookup_string() helper function --- panels/power/cc-power-panel.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 1869be065..4633627c2 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -1343,6 +1343,18 @@ setup_power_saving (CcPowerPanel *self) #endif } +static const char * +variant_lookup_string (GVariant *dict, + const char *key) +{ + GVariant *variant; + + variant = g_variant_lookup_value (dict, key, G_VARIANT_TYPE_STRING); + if (!variant) + return NULL; + return g_variant_get_string (variant, NULL); +} + static void performance_profile_set_active (CcPowerPanel *self, const char *profile_str) @@ -1427,18 +1439,6 @@ perf_profile_list_box_sort (GtkListBoxRow *row1, return 0; } -static const char * -variant_lookup_string (GVariant *dict, - const char *key) -{ - GVariant *variant; - - variant = g_variant_lookup_value (dict, key, G_VARIANT_TYPE_STRING); - if (!variant) - return NULL; - return g_variant_get_string (variant, NULL); -} - static void power_profiles_properties_changed_cb (CcPowerPanel *self, GVariant *changed_properties, -- 2.32.0 From f49c47787de81fa39f100f3903d2d886905cd4c7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 16 Jul 2021 11:01:52 +0200 Subject: [PATCH 17/33] power: Show power profile info boxes for profile holds Applications can request that power-profiles-daemon "hold" a particular power profile for the duration of a task or event, such as launching a taxing application, or saving power because of low battery. Show those holds in the same type of info boxes we already use to show "degraded" performance. See https://gitlab.freedesktop.org/hadess/power-profiles-daemon/-/merge_requests/46 --- panels/power/cc-power-panel.c | 77 ++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index 4633627c2..4f1989cdf 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #ifdef HAVE_NETWORK_MANAGER @@ -1383,12 +1384,25 @@ static void power_profile_update_info_boxes (CcPowerPanel *self) { g_autoptr(GVariant) degraded_variant = NULL; + g_autoptr(GVariant) holds_variant = NULL; + g_autoptr(GVariant) profile_variant = NULL; + guint i, num_children; const char *degraded = NULL; + const char *profile; CcPowerProfileInfoRow *row; + int next_insert = 0; empty_listbox (self->power_profile_info_listbox); gtk_widget_hide (GTK_WIDGET (self->power_profile_info_listbox)); + profile_variant = g_dbus_proxy_get_cached_property (self->power_profiles_proxy, "ActiveProfile"); + if (!profile_variant) + { + g_warning ("No 'ActiveProfile' property on power-profiles-daemon service"); + return; + } + profile = g_variant_get_string (profile_variant, NULL); + degraded_variant = g_dbus_proxy_get_cached_property (self->power_profiles_proxy, "PerformanceDegraded"); if (degraded_variant) degraded = g_variant_get_string (degraded_variant, NULL); @@ -1408,6 +1422,66 @@ power_profile_update_info_boxes (CcPowerPanel *self) row = cc_power_profile_info_row_new (text); gtk_widget_show (GTK_WIDGET (row)); gtk_container_add (GTK_CONTAINER (self->power_profile_info_listbox), GTK_WIDGET (row)); + if (g_str_equal (profile, "performance")) + next_insert = 1; + } + + holds_variant = g_dbus_proxy_get_cached_property (self->power_profiles_proxy, "ActiveProfileHolds"); + if (!holds_variant) + { + g_warning ("No 'ActiveProfileHolds' property on power-profiles-daemon service"); + return; + } + + num_children = g_variant_n_children (holds_variant); + for (i = 0; i < num_children; i++) + { + g_autoptr(GDesktopAppInfo) app_info = NULL; + g_autoptr(GVariant) hold_variant = NULL; + g_autofree char *text = NULL; + const char *app_id, *held_profile, *reason, *name; + + hold_variant = g_variant_get_child_value (holds_variant, i); + if (!hold_variant || !g_variant_is_of_type (hold_variant, G_VARIANT_TYPE ("a{sv}"))) + continue; + + app_id = variant_lookup_string (hold_variant, "ApplicationId"); + if (!app_id) + continue; + app_info = g_desktop_app_info_new (app_id); + name = app_info ? g_app_info_get_name (G_APP_INFO (app_info)) : app_id; + held_profile = variant_lookup_string (hold_variant, "Profile"); + reason = variant_lookup_string (hold_variant, "Reason"); + g_debug ("Adding info row for %s hold by %s: %s", held_profile, app_id, reason); + + if (g_strcmp0 (held_profile, "power-saver") == 0 && + g_strcmp0 (app_id, "org.gnome.SettingsDaemon.Power") == 0) + { + text = g_strdup (_("Low battery: power saver enabled. Previous mode will be restored when battery is sufficiently charged.")); + } + else + { + switch (cc_power_profile_from_str (held_profile)) + { + case CC_POWER_PROFILE_POWER_SAVER: + /* translators: "%s" is an application name */ + text = g_strdup_printf (_("Power Saver mode activated by “%s”."), name); + break; + case CC_POWER_PROFILE_PERFORMANCE: + /* translators: "%s" is an application name */ + text = g_strdup_printf (_("Performance mode activated by “%s”."), name); + break; + default: + g_assert_not_reached (); + } + } + + row = cc_power_profile_info_row_new (text); + gtk_widget_show (GTK_WIDGET (row)); + if (g_strcmp0 (held_profile, profile) != 0) + gtk_list_box_insert (GTK_LIST_BOX (self->power_profile_info_listbox), GTK_WIDGET (row), -1); + else + gtk_list_box_insert (GTK_LIST_BOX (self->power_profile_info_listbox), GTK_WIDGET (row), next_insert); } } @@ -1458,7 +1532,8 @@ power_profiles_properties_changed_cb (CcPowerPanel *self, performance_profile_set_inhibited (self, g_variant_get_string (value, NULL)); } - else if (g_strcmp0 (key, "PerformanceDegraded") == 0) + else if (g_strcmp0 (key, "PerformanceDegraded") == 0 || + g_strcmp0 (key, "ActiveProfileHolds") == 0) { power_profile_update_info_boxes (self); } -- 2.32.0 From d7cabb849c425fd84e85a981bcd56a6df1d87868 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 16 Jul 2021 11:32:37 +0200 Subject: [PATCH 18/33] power: Tweak power profile info boxes horizontal spacing A bit too much whitespace around the info icon. --- panels/power/cc-power-profile-info-row.ui | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/panels/power/cc-power-profile-info-row.ui b/panels/power/cc-power-profile-info-row.ui index d9291ff16..bc49a24ac 100644 --- a/panels/power/cc-power-profile-info-row.ui +++ b/panels/power/cc-power-profile-info-row.ui @@ -8,16 +8,16 @@ True horizontal - 12 - 12 + 8 + 8 8 8 - 12 + 8 True 6 - 18 + 6 info-symbolic 5 -- 2.32.0 From 254a9bfa8ac8be8403d0258742f0c3f8c8db9633 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 4 Aug 2021 11:26:33 +0200 Subject: [PATCH 30/33] power: Remove icons from power profiles They were originally included was to educate users about what the icons mean, for when they appeared in the top bar. However, since we no longer plan on showing the status icon in the top bar, it's not so important that people learn the meaning of the icons. See https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1421 --- panels/power/cc-power-profile-row.c | 13 +------------ panels/power/cc-power-profile-row.ui | 15 +-------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/panels/power/cc-power-profile-row.c b/panels/power/cc-power-profile-row.c index ee66bdfd0..a8458c366 100644 --- a/panels/power/cc-power-profile-row.c +++ b/panels/power/cc-power-profile-row.c @@ -35,7 +35,6 @@ struct _CcPowerProfileRow GtkListBoxRow parent_instance; GtkRadioButton *button; - GtkImage *icon_image; GtkLabel *subtitle_label; GtkLabel *title_label; @@ -106,7 +105,6 @@ cc_power_profile_row_class_init (CcPowerProfileRowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/power/cc-power-profile-row.ui"); gtk_widget_class_bind_template_child (widget_class, CcPowerProfileRow, button); - gtk_widget_class_bind_template_child (widget_class, CcPowerProfileRow, icon_image); gtk_widget_class_bind_template_child (widget_class, CcPowerProfileRow, subtitle_label); gtk_widget_class_bind_template_child (widget_class, CcPowerProfileRow, title_label); @@ -175,7 +173,7 @@ CcPowerProfileRow * cc_power_profile_row_new (CcPowerProfile power_profile) { CcPowerProfileRow *self; - const char *text, *subtext, *icon_name, *class_name; + const char *text, *subtext; self = g_object_new (CC_TYPE_POWER_PROFILE_ROW, NULL); @@ -185,20 +183,14 @@ cc_power_profile_row_new (CcPowerProfile power_profile) case CC_POWER_PROFILE_PERFORMANCE: text = _("Performance"); subtext = _("High performance and power usage."); - icon_name = "power-profile-performance-symbolic"; - class_name = "performance"; break; case CC_POWER_PROFILE_BALANCED: text = _("Balanced Power"); subtext = _("Standard performance and power usage."); - icon_name = "power-profile-balanced-symbolic"; - class_name = NULL; break; case CC_POWER_PROFILE_POWER_SAVER: text = _("Power Saver"); subtext = _("Reduced performance and power usage."); - icon_name = "power-profile-power-saver-symbolic"; - class_name = "low-power"; break; default: g_assert_not_reached (); @@ -206,9 +198,6 @@ cc_power_profile_row_new (CcPowerProfile power_profile) gtk_label_set_markup (self->title_label, text); gtk_label_set_markup (self->subtitle_label, subtext); - gtk_image_set_from_icon_name (self->icon_image, icon_name, GTK_ICON_SIZE_MENU); - if (class_name != NULL) - gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->icon_image)), class_name); return self; } diff --git a/panels/power/cc-power-profile-row.ui b/panels/power/cc-power-profile-row.ui index 64516edf3..1391093ba 100644 --- a/panels/power/cc-power-profile-row.ui +++ b/panels/power/cc-power-profile-row.ui @@ -28,19 +28,6 @@ 2 - - - True - 6 - - - - 1 - 0 - - True @@ -53,7 +40,7 @@ 6 - 2 + 1 0 -- 2.32.0 From 96efcd2835a46b8009b5f6524a2d37089f40dd44 Mon Sep 17 00:00:00 2001 From: Allan Day Date: Wed, 4 Aug 2021 11:28:14 +0200 Subject: [PATCH 31/33] power: Align power profile info boxes with profiles text See https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1421 --- panels/power/cc-power-profile-info-row.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panels/power/cc-power-profile-info-row.ui b/panels/power/cc-power-profile-info-row.ui index 6f411c688..34807c38c 100644 --- a/panels/power/cc-power-profile-info-row.ui +++ b/panels/power/cc-power-profile-info-row.ui @@ -8,11 +8,11 @@ True horizontal - 8 + 4 8 8 8 - 8 + 4 True -- 2.32.0 From 618e269230a71ae3ac84a35daaf15ad3db38f459 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 5 Aug 2021 15:24:58 +0200 Subject: [PATCH 32/33] power: Change "Balanced" power profile label https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4530#note_1241985 --- panels/power/cc-power-profile-row.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panels/power/cc-power-profile-row.c b/panels/power/cc-power-profile-row.c index a8458c366..9d7f1fe6b 100644 --- a/panels/power/cc-power-profile-row.c +++ b/panels/power/cc-power-profile-row.c @@ -185,7 +185,7 @@ cc_power_profile_row_new (CcPowerProfile power_profile) subtext = _("High performance and power usage."); break; case CC_POWER_PROFILE_BALANCED: - text = _("Balanced Power"); + text = _("Balanced"); subtext = _("Standard performance and power usage."); break; case CC_POWER_PROFILE_POWER_SAVER: -- 2.32.0 From 98ed744dcefd8c4d8398b1489d0c583a4d5787d9 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 5 Aug 2021 15:24:58 +0200 Subject: [PATCH 33/33] power: Update power profile labels Use "Balanced" instead of "Balanced Power", and make sure to add a context for all the profiles for translators. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4530#note_1243075 --- panels/power/cc-power-profile-row.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/panels/power/cc-power-profile-row.c b/panels/power/cc-power-profile-row.c index 9d7f1fe6b..f290caa10 100644 --- a/panels/power/cc-power-profile-row.c +++ b/panels/power/cc-power-profile-row.c @@ -181,15 +181,15 @@ cc_power_profile_row_new (CcPowerProfile power_profile) switch (self->power_profile) { case CC_POWER_PROFILE_PERFORMANCE: - text = _("Performance"); + text = C_("Power profile", "Performance"); subtext = _("High performance and power usage."); break; case CC_POWER_PROFILE_BALANCED: - text = _("Balanced"); + text = C_("Power profile", "Balanced"); subtext = _("Standard performance and power usage."); break; case CC_POWER_PROFILE_POWER_SAVER: - text = _("Power Saver"); + text = C_("Power profile", "Power Saver"); subtext = _("Reduced performance and power usage."); break; default: -- 2.32.0