shell: Allow panels set custom titlebars

This will be used by the Display panel to add a different
titlebar when confirming a new display configuration.
This commit is contained in:
Georges Basile Stavracas Neto 2021-11-11 15:30:44 -03:00
parent d00cc3929e
commit 3f322e8553
4 changed files with 80 additions and 30 deletions

View file

@ -173,3 +173,12 @@ cc_shell_embed_widget_in_header (CcShell *shell,
iface->embed_widget_in_header (shell, widget, position);
}
}
void
cc_shell_set_custom_titlebar (CcShell *self,
GtkWidget *titlebar)
{
g_return_if_fail (CC_IS_SHELL (self));
CC_SHELL_GET_IFACE (self)->set_custom_titlebar (self, titlebar);
}

View file

@ -57,6 +57,8 @@ struct _CcShellInterface
void (*embed_widget_in_header) (CcShell *shell,
GtkWidget *widget,
GtkPositionType position);
void (*set_custom_titlebar) (CcShell *self,
GtkWidget *titlebar);
};
GType cc_shell_get_type (void) G_GNUC_CONST;
@ -74,4 +76,7 @@ void cc_shell_embed_widget_in_header (CcShell *shell,
GtkWidget *widget,
GtkPositionType position);
void cc_shell_set_custom_titlebar (CcShell *self,
GtkWidget *titlebar);
G_END_DECLS

View file

@ -58,6 +58,7 @@ struct _CcWindow
AdwHeaderBar *panel_headerbar;
CcPanelList *panel_list;
AdwWindowTitle *panel_title_widget;
GtkStack *panel_titlebar_stack;
GtkButton *previous_button;
GtkSearchBar *search_bar;
GtkToggleButton *search_button;
@ -73,6 +74,7 @@ struct _CcWindow
GQueue *previous_panels;
GPtrArray *custom_widgets;
GtkWidget *custom_titlebar;
CcShellModel *store;
@ -189,6 +191,7 @@ activate_panel (CcWindow *self,
/* clear any custom widgets */
remove_all_custom_widgets (self);
cc_shell_set_custom_titlebar (CC_SHELL (self), NULL);
timer = g_timer_new ();
@ -681,12 +684,36 @@ cc_window_get_toplevel (CcShell *self)
return GTK_WIDGET (self);
}
static void
cc_window_set_custom_titlebar (CcShell *shell,
GtkWidget *titlebar)
{
CcWindow *self = CC_WINDOW (shell);
/* Remove the current custom titlebar */
if (self->custom_titlebar)
{
gtk_stack_set_visible_child (self->panel_titlebar_stack,
GTK_WIDGET (self->panel_headerbar));
gtk_stack_remove (self->panel_titlebar_stack, self->custom_titlebar);
}
g_set_object (&self->custom_titlebar, titlebar);
if (titlebar)
{
gtk_stack_add_named (self->panel_titlebar_stack, titlebar, "custom");
gtk_stack_set_visible_child (self->panel_titlebar_stack, titlebar);
}
}
static void
cc_shell_iface_init (CcShellInterface *iface)
{
iface->set_active_panel_from_id = cc_window_set_active_panel_from_id;
iface->embed_widget_in_header = cc_window_embed_widget_in_header;
iface->get_toplevel = cc_window_get_toplevel;
iface->set_custom_titlebar = cc_window_set_custom_titlebar;
}
/* GtkWidget overrides */
@ -881,6 +908,7 @@ cc_window_class_init (CcWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_headerbar);
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_list);
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_title_widget);
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_titlebar_stack);
gtk_widget_class_bind_template_child (widget_class, CcWindow, previous_button);
gtk_widget_class_bind_template_child (widget_class, CcWindow, search_bar);
gtk_widget_class_bind_template_child (widget_class, CcWindow, search_button);

View file

@ -114,46 +114,54 @@
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<!-- Panel titlebar -->
<child>
<object class="AdwHeaderBar" id="panel_headerbar">
<property name="visible">True</property>
<object class="GtkStack" id="panel_titlebar_stack">
<property name="hexpand">True</property>
<property name="show-start-title-buttons" bind-source="main_leaflet" bind-property="folded" bind-flags="sync-create"/>
<property name="show-end-title-buttons">True</property>
<property name="title-widget">
<object class="AdwWindowTitle" id="panel_title_widget" />
</property>
<child>
<object class="GtkRevealer" id="back_revealer">
<property name="transition-type">crossfade</property>
<property name="transition-duration" bind-source="main_leaflet" bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
<property name="visible" bind-source="main_leaflet" bind-property="folded" bind-flags="sync-create"/>
<property name="reveal-child" bind-source="main_leaflet" bind-property="folded" bind-flags="sync-create"/>
<object class="AdwHeaderBar" id="panel_headerbar">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="show-start-title-buttons" bind-source="main_leaflet" bind-property="folded" bind-flags="sync-create"/>
<property name="show-end-title-buttons">True</property>
<property name="title-widget">
<object class="AdwWindowTitle" id="panel_title_widget" />
</property>
<child>
<object class="GtkButton" id="back">
<property name="visible">True</property>
<property name="receives_default">False</property>
<property name="valign">center</property>
<property name="icon-name">go-previous-symbolic</property>
<signal name="clicked" handler="back_button_clicked_cb" object="CcWindow" swapped="yes" />
<style>
<class name="image-button"/>
</style>
<accessibility>
<property name="label" translatable="yes">Back</property>
</accessibility>
<object class="GtkRevealer" id="back_revealer">
<property name="transition-type">crossfade</property>
<property name="transition-duration" bind-source="main_leaflet" bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
<property name="visible" bind-source="main_leaflet" bind-property="folded" bind-flags="sync-create"/>
<property name="reveal-child" bind-source="main_leaflet" bind-property="folded" bind-flags="sync-create"/>
<child>
<object class="GtkButton" id="back">
<property name="visible">True</property>
<property name="receives_default">False</property>
<property name="valign">center</property>
<property name="icon-name">go-previous-symbolic</property>
<signal name="clicked" handler="back_button_clicked_cb" object="CcWindow" swapped="yes" />
<style>
<class name="image-button"/>
</style>
<accessibility>
<property name="label" translatable="yes">Back</property>
</accessibility>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="top_left_box" />
</child>
<child type="end">
<object class="GtkBox" id="top_right_box" />
</child>
</object>
</child>
<child>
<object class="GtkBox" id="top_left_box" />
</child>
<child type="end">
<object class="GtkBox" id="top_right_box" />
</child>
</object>
</child>
<child>
<object class="GtkStack" id="stack">
<property name="hexpand">True</property>