[gnome-control-center/gbsneto/panel-headerbar-cleanup: 11/19] display: Rework titlebar handling entirely
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gbsneto/panel-headerbar-cleanup: 11/19] display: Rework titlebar handling entirely
- Date: Thu, 20 Jan 2022 02:23:43 +0000 (UTC)
commit b756f1e07a9153de46e109d3d80a49ecb9f7e6af
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jan 19 19:19:56 2022 -0300
display: Rework titlebar handling entirely
Move all titlebars to the panel itself. Add an overlay with
the apply titlebar, which shows the apply / cancel titlebar
above whatever current titlebar is visible.
Add titlebars to the Night Light, and display settings pages.
panels/display/cc-display-panel.c | 95 +++-------
panels/display/cc-display-panel.ui | 349 ++++++++++++++++++++++++-------------
2 files changed, 255 insertions(+), 189 deletions(-)
---
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index c9015d16f..79605cd76 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -82,23 +82,22 @@ struct _CcDisplayPanel
GDBusProxy *shell_proxy;
- gchar *main_title;
- GtkWidget *apply_titlebar;
- GtkWidget *apply_titlebar_apply;
- GtkWidget *apply_titlebar_cancel;
- GtkWidget *apply_titlebar_warning;
+ GtkWidget *apply_titlebar;
+ GtkWidget *apply_button;
+ GtkWidget *cancel_button;
+ AdwWindowTitle *apply_titlebar_title_widget;
GListStore *primary_display_list;
GList *monitor_rows;
GtkWidget *arrangement_group;
AdwBin *arrangement_bin;
- GtkWidget *back_button;
GtkToggleButton *config_type_join;
GtkToggleButton *config_type_mirror;
GtkWidget *config_type_switcher_row;
AdwBin *display_settings_bin;
GtkWidget *display_settings_group;
+ AdwWindowTitle *display_settings_title_widget;
AdwLeaflet *leaflet;
AdwComboRow *primary_display_row;
AdwPreferencesGroup *single_display_settings_group;
@@ -123,6 +122,8 @@ static void
set_current_output (CcDisplayPanel *panel,
CcDisplayMonitor *output,
gboolean force);
+static void
+on_screen_changed (CcDisplayPanel *panel);
static CcDisplayConfigType
@@ -392,17 +393,9 @@ dialog_toplevel_focus_changed (CcDisplayPanel *self)
static void
reset_titlebar (CcDisplayPanel *self)
{
- CcShell *shell = cc_panel_get_shell (CC_PANEL (self));
-
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (self->toplevel_shortcuts),
GTK_PHASE_NONE);
-
- cc_shell_set_custom_titlebar (shell, NULL);
-
- g_clear_object (&self->apply_titlebar);
- g_clear_object (&self->apply_titlebar_apply);
- g_clear_object (&self->apply_titlebar_cancel);
- g_clear_object (&self->apply_titlebar_warning);
+ gtk_widget_hide (self->apply_titlebar);
}
static void
@@ -544,16 +537,6 @@ on_primary_display_selected_index_changed_cb (CcDisplayPanel *panel)
update_apply_button (panel);
}
-static void
-on_stack_visible_child_name_changed_cb (GtkStack *stack,
- GParamSpec *pspec,
- CcDisplayPanel *self)
-{
- const gchar *visible_child_name = adw_leaflet_get_visible_child_name (self->leaflet);
-
- gtk_widget_set_visible (self->back_button, g_strcmp0 (visible_child_name, "displays") != 0);
-}
-
static void
on_toplevel_folded (CcDisplayPanel *panel, GParamSpec *pspec, GtkWidget *toplevel)
{
@@ -568,9 +551,9 @@ on_toplevel_escape_pressed_cb (GtkWidget *widget,
GVariant *args,
CcDisplayPanel *self)
{
- if (self->apply_titlebar_cancel)
+ if (gtk_widget_get_visible (self->apply_titlebar))
{
- g_signal_emit_by_name (self->apply_titlebar_cancel, "activate");
+ gtk_widget_activate (self->cancel_button);
return GDK_EVENT_STOP;
}
@@ -614,14 +597,18 @@ cc_display_panel_class_init (CcDisplayPanelClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/display/cc-display-panel.ui");
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, apply_button);
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, apply_titlebar);
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, apply_titlebar_title_widget);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, arrangement_group);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, arrangement_bin);
- gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, back_button);
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, cancel_button);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, config_type_switcher_row);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, config_type_join);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, config_type_mirror);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_bin);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_group);
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_title_widget);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, escape_shortcut);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, leaflet);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, night_light_page);
@@ -630,12 +617,13 @@ cc_display_panel_class_init (CcDisplayPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, single_display_settings_group);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, toplevel_shortcuts);
+ gtk_widget_class_bind_template_callback (widget_class, apply_current_configuration);
gtk_widget_class_bind_template_callback (widget_class, on_back_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, on_config_type_toggled_cb);
gtk_widget_class_bind_template_callback (widget_class, on_night_light_list_box_row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, on_night_light_row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, on_primary_display_selected_index_changed_cb);
- gtk_widget_class_bind_template_callback (widget_class, on_stack_visible_child_name_changed_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_screen_changed);
gtk_widget_class_bind_template_callback (widget_class, on_toplevel_escape_pressed_cb);
}
@@ -674,6 +662,9 @@ on_monitor_row_activated_cb (GtkListBoxRow *row,
monitor = g_object_get_data (G_OBJECT (row), "monitor");
set_current_output (self, monitor, FALSE);
+ adw_window_title_set_title (self->display_settings_title_widget,
+ cc_display_monitor_get_ui_name (monitor));
+
adw_leaflet_set_visible_child_name (self->leaflet, "display-settings");
}
@@ -932,51 +923,21 @@ on_screen_changed (CcDisplayPanel *panel)
static void
show_apply_titlebar (CcDisplayPanel *panel, gboolean is_applicable)
{
- GtkWidget *title;
-
- if (!panel->apply_titlebar)
- {
- g_autoptr(GtkSizeGroup) size_group = NULL;
- GtkWidget *header, *button;
- CcShell *shell;
-
- shell = cc_panel_get_shell (CC_PANEL (panel));
-
- panel->apply_titlebar = header = gtk_header_bar_new ();
- gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
-
- size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
-
- panel->apply_titlebar_cancel = button = gtk_button_new_with_mnemonic (_("_Cancel"));
- gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
- gtk_size_group_add_widget (size_group, button);
- g_signal_connect_object (button, "clicked", G_CALLBACK (on_screen_changed),
- panel, G_CONNECT_SWAPPED);
-
- panel->apply_titlebar_apply = button = gtk_button_new_with_mnemonic (_("_Apply"));
- gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
- gtk_size_group_add_widget (size_group, button);
- g_signal_connect_object (button, "clicked", G_CALLBACK (apply_current_configuration),
- panel, G_CONNECT_SWAPPED);
- gtk_widget_add_css_class (button, "suggested-action");
-
- cc_shell_set_custom_titlebar (shell, panel->apply_titlebar);
- g_object_ref (panel->apply_titlebar);
- g_object_ref (panel->apply_titlebar_apply);
- g_object_ref (panel->apply_titlebar_cancel);
- }
+ gtk_widget_show (panel->apply_titlebar);
+ gtk_widget_set_sensitive (panel->apply_button, is_applicable);
if (is_applicable)
{
- title = adw_window_title_new (_("Apply Changes?"), NULL);
+ adw_window_title_set_title (panel->apply_titlebar_title_widget,
+ _("Apply Changes?"));
}
else
{
- title = adw_window_title_new (_("Changes Cannot be Applied"),
- _("This could be due to hardware limitations."));
+ adw_window_title_set_title (panel->apply_titlebar_title_widget,
+ _("Changes Cannot be Applied"));
+ adw_window_title_set_subtitle (panel->apply_titlebar_title_widget,
+ _("This could be due to hardware limitations."));
}
- gtk_header_bar_set_title_widget (GTK_HEADER_BAR (panel->apply_titlebar), title);
- gtk_widget_set_sensitive (panel->apply_titlebar_apply, is_applicable);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (panel->toplevel_shortcuts),
GTK_PHASE_BUBBLE);
diff --git a/panels/display/cc-display-panel.ui b/panels/display/cc-display-panel.ui
index 22350b271..4de2fb2fb 100644
--- a/panels/display/cc-display-panel.ui
+++ b/panels/display/cc-display-panel.ui
@@ -15,173 +15,278 @@
</object>
</child>
- <child type="titlebar-start">
- <object class="GtkButton" id="back_button">
- <property name="visible">False</property>
- <property name="icon-name">go-previous-symbolic</property>
- <signal name="clicked" handler="on_back_button_clicked_cb" object="CcDisplayPanel" swapped="no" />
- </object>
- </child>
+ <child>
+ <object class="GtkOverlay">
+
+ <child type="overlay">
+ <object class="AdwHeaderBar" id="apply_titlebar">
+ <property name="visible">False</property>
+ <property name="valign">start</property>
+ <property name="show-start-title-buttons">False</property>
+ <property name="show-end-title-buttons">False</property>
+
+ <child type="start">
+ <object class="GtkButton" id="cancel_button">
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_Cancel</property>
+ <signal name="clicked" handler="on_screen_changed" object="CcDisplayPanel" swapped="yes" />
+ </object>
+ </child>
- <child type="content">
- <object class="AdwLeaflet" id="leaflet">
- <property name="can-unfold">False</property>
- <signal name="notify::visible-child-name" handler="on_stack_visible_child_name_changed_cb"
object="CcDisplayPanel" swapped="no" />
+ <property name="title-widget">
+ <object class="AdwWindowTitle" id="apply_titlebar_title_widget" />
+ </property>
+
+ <child type="end">
+ <object class="GtkButton" id="apply_button">
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_Apply</property>
+ <signal name="clicked" handler="apply_current_configuration" object="CcDisplayPanel"
swapped="yes" />
+ <style>
+ <class name="suggested-action" />
+ </style>
+ </object>
+ </child>
+
+ </object>
+ </child>
- <!-- Displays page -->
<child>
- <object class="AdwLeafletPage">
- <property name="name">displays</property>
- <property name="child">
- <object class="GtkScrolledWindow">
- <property name="hscrollbar_policy">never</property>
- <child>
- <object class="GtkViewport">
+ <object class="AdwLeaflet" id="leaflet">
+ <property name="can-unfold">False</property>
+
+ <!-- Displays page -->
+ <child>
+ <object class="AdwLeafletPage">
+ <property name="name">displays</property>
+ <property name="child">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+
+ <!-- Displays page titlebar -->
<child>
- <object class="AdwClamp">
- <property name="valign">start</property>
- <property name="margin_top">32</property>
- <property name="margin_bottom">32</property>
- <property name="margin_start">12</property>
- <property name="margin_end">12</property>
- <child>
- <object class="GtkBox">
- <property name="hexpand">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">32</property>
+ <object class="AdwHeaderBar" id="displays_titlebar">
+ <property name="show-end-title-buttons">True</property>
+ <property name="show-start-title-buttons" bind-source="CcDisplayPanel"
bind-property="folded" bind-flags="default|sync-create" />
+ <child type="start">
+ <object class="GtkButton">
+ <property name="visible" bind-source="CcDisplayPanel" bind-property="folded"
bind-flags="default|sync-create" />
+ <property name="icon-name">go-previous-symbolic</property>
+ </object>
+ </child>
+ <property name="title-widget">
+ <object class="AdwWindowTitle">
+ <property name="title" bind-source="CcDisplayPanel" bind-property="title"
bind-flags="default|sync-create" />
+ </object>
+ </property>
+ </object>
+ </child>
+
+ <child>
+ <object class="AdwPreferencesPage">
+ <child>
+ <object class="AdwPreferencesGroup" id="arrangement_group">
<child>
- <object class="AdwPreferencesGroup" id="arrangement_group">
- <child>
- <object class="AdwBin" id="arrangement_bin">
- <style>
- <class name="card"/>
- </style>
- </object>
- </child>
- <accessibility>
- <property name="label" translatable="yes">Display Arrangement</property>
- </accessibility>
+ <object class="AdwBin" id="arrangement_bin">
+ <style>
+ <class name="card"/>
+ </style>
</object>
</child>
+ <accessibility>
+ <property name="label" translatable="yes">Display Arrangement</property>
+ </accessibility>
+ </object>
+ </child>
+
+ <child>
+ <object class="AdwPreferencesGroup" id="display_settings_group">
+ <!-- Config Type -->
<child>
- <object class="AdwPreferencesGroup" id="display_settings_group">
-
- <!-- Config Type -->
- <child>
- <object class="AdwActionRow" id="config_type_switcher_row">
- <property name="title" translatable="yes">Multiple Displays</property>
- <child type="suffix">
- <object class="GtkBox">
- <property name="valign">center</property>
- <style>
- <class name="linked" />
- </style>
- <child>
- <object class="GtkToggleButton" id="config_type_join">
- <property name="label" translatable="yes" comments="'Join' as in
'Join displays'">Join</property>
- <property name="active">True</property>
- <signal name="toggled" handler="on_config_type_toggled_cb"
swapped="yes"/>
- </object>
- </child>
- <child>
- <object class="GtkToggleButton" id="config_type_mirror">
- <property name="label" translatable="yes">Mirror</property>
- <property name="group">config_type_join</property>
- <signal name="toggled" handler="on_config_type_toggled_cb"
swapped="yes"/>
- </object>
- </child>
+ <object class="AdwActionRow" id="config_type_switcher_row">
+ <property name="title" translatable="yes">Multiple Displays</property>
+ <child type="suffix">
+ <object class="GtkBox">
+ <property name="valign">center</property>
+ <style>
+ <class name="linked" />
+ </style>
+ <child>
+ <object class="GtkToggleButton" id="config_type_join">
+ <property name="label" translatable="yes" comments="'Join' as in
'Join displays'">Join</property>
+ <property name="active">True</property>
+ <signal name="toggled" handler="on_config_type_toggled_cb"
swapped="yes"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="config_type_mirror">
+ <property name="label" translatable="yes">Mirror</property>
+ <property name="group">config_type_join</property>
+ <signal name="toggled" handler="on_config_type_toggled_cb"
swapped="yes"/>
</object>
</child>
- </object>
- </child>
-
- <!-- Primary Display -->
- <child>
- <object class="AdwComboRow" id="primary_display_row">
- <property name="subtitle" translatable="yes">Contains top bar and
Activities</property>
- <property name="title" translatable="yes">Primary Display</property>
- <signal name="notify::selected-index"
handler="on_primary_display_selected_index_changed_cb" swapped="yes"/>
</object>
</child>
</object>
-
</child>
- <!-- Single Display Settings -->
+ <!-- Primary Display -->
<child>
- <object class="AdwPreferencesGroup" id="single_display_settings_group">
- <property name="visible">False</property>
+ <object class="AdwComboRow" id="primary_display_row">
+ <property name="subtitle" translatable="yes">Contains top bar and
Activities</property>
+ <property name="title" translatable="yes">Primary Display</property>
+ <signal name="notify::selected-index"
handler="on_primary_display_selected_index_changed_cb" swapped="yes"/>
</object>
</child>
+ </object>
+
+ </child>
- <!-- Night Light -->
+ <!-- Single Display Settings -->
+ <child>
+ <object class="AdwPreferencesGroup" id="single_display_settings_group">
+ <property name="visible">False</property>
+ </object>
+ </child>
+
+ <!-- Night Light -->
+ <child>
+ <object class="AdwPreferencesGroup">
<child>
- <object class="AdwPreferencesGroup">
- <child>
- <object class="AdwActionRow">
- <property name="activatable">True</property>
- <property name="title" translatable="yes" comments="This is the redshift
functionality where we suppress blue light when the sun has gone down">Night Light</property>
- <signal name="activated" handler="on_night_light_row_activated_cb"
object="CcDisplayPanel" swapped="no" />
-
- <child type="suffix">
- <object class="GtkLabel" id="night_light_state_label">
- <property name="label">On</property>
- </object>
- </child>
+ <object class="AdwActionRow">
+ <property name="activatable">True</property>
+ <property name="title" translatable="yes" comments="This is the redshift
functionality where we suppress blue light when the sun has gone down">Night Light</property>
+ <signal name="activated" handler="on_night_light_row_activated_cb"
object="CcDisplayPanel" swapped="no" />
- <child type="suffix">
- <object class="GtkImage">
- <property name="icon-name">go-next-symbolic</property>
- </object>
- </child>
+ <child type="suffix">
+ <object class="GtkLabel" id="night_light_state_label">
+ <property name="label">On</property>
+ </object>
+ </child>
+ <child type="suffix">
+ <object class="GtkImage">
+ <property name="icon-name">go-next-symbolic</property>
</object>
</child>
+
</object>
</child>
+ </object>
+ </child>
+
+ </object>
+ </child>
+ </object>
+ </property>
+ </object>
+ </child>
+
+ <!-- Night Light page -->
+ <child>
+ <object class="AdwLeafletPage">
+ <property name="name">night-light</property>
+ <property name="child">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <!-- Night Light titlebar -->
+ <child>
+ <object class="AdwHeaderBar" id="night_light_titlebar">
+ <property name="show-start-title-buttons">True</property>
+ <property name="show-end-title-buttons">True</property>
+ <child type="start">
+ <object class="GtkButton">
+ <property name="icon-name">go-previous-symbolic</property>
+ <signal name="clicked" handler="on_back_button_clicked_cb"
object="CcDisplayPanel" swapped="no" />
</object>
</child>
+ <property name="title-widget">
+ <object class="AdwWindowTitle">
+ <property name="title" translatable="yes">Night Light</property>
+ </object>
+ </property>
</object>
</child>
+
+ <!-- Night Light -->
+ <child>
+ <object class="CcNightLightPage" id="night_light_page" />
+ </child>
+
</object>
- </child>
+ </property>
</object>
- </property>
- </object>
- </child>
+ </child>
- <!-- Night Light page -->
- <child>
- <object class="AdwLeafletPage">
- <property name="name">night-light</property>
- <property name="child">
- <object class="CcNightLightPage" id="night_light_page" />
- </property>
- </object>
- </child>
+ <!-- Display Settings page -->
+ <child>
+ <object class="AdwLeafletPage">
+ <property name="name">display-settings</property>
+ <property name="child"><object class="GtkBox">
+ <property name="orientation">vertical</property>
- <!-- Display Settings page -->
- <child>
- <object class="AdwLeafletPage">
- <property name="name">display-settings</property>
- <property name="child">
- <object class="AdwPreferencesPage">
- <child>
- <object class="AdwPreferencesGroup">
+ <!-- Display Settings titlebar -->
<child>
- <object class="AdwBin" id="display_settings_bin" />
+ <object class="AdwHeaderBar" id="display_settings_titlebar">
+ <property name="show-start-title-buttons">True</property>
+ <property name="show-end-title-buttons">True</property>
+ <child type="start">
+ <object class="GtkButton">
+ <property name="icon-name">go-previous-symbolic</property>
+ <signal name="clicked" handler="on_back_button_clicked_cb"
object="CcDisplayPanel" swapped="no" />
+ </object>
+ </child>
+ <property name="title-widget">
+ <object class="AdwWindowTitle" id="display_settings_title_widget" />
+ </property>
+ </object>
</child>
+
+ <!-- Display Settings -->
+ <child>
+ <object class="AdwPreferencesPage">
+ <child>
+ <object class="AdwPreferencesGroup">
+ <child>
+ <object class="AdwBin" id="display_settings_bin" />
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
</object>
- </child>
+ </property>
</object>
- </property>
+ </child>
+
</object>
</child>
</object>
</child>
+
</template>
+
+ <object class="GtkSizeGroup">
+ <property name="mode">horizontal</property>
+ <widgets>
+ <widget name="apply_button" />
+ <widget name="cancel_button" />
+ </widgets>
+ </object>
+
+ <object class="GtkSizeGroup">
+ <property name="mode">vertical</property>
+ <widgets>
+ <widget name="apply_titlebar" />
+ <widget name="displays_titlebar" />
+ <widget name="display_settings_titlebar" />
+ <widget name="night_light_titlebar" />
+ </widgets>
+ </object>
+
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]