[gnome-control-center/gbsneto/gtk4: 47/53] shell: Allow panels set custom titlebars




commit 3f322e85530899ecfeafe48770b63543e9d2a704
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Nov 11 15:30:44 2021 -0300

    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.

 shell/cc-shell.c   |  9 ++++++++
 shell/cc-shell.h   |  5 ++++
 shell/cc-window.c  | 28 ++++++++++++++++++++++
 shell/cc-window.ui | 68 ++++++++++++++++++++++++++++++------------------------
 4 files changed, 80 insertions(+), 30 deletions(-)
---
diff --git a/shell/cc-shell.c b/shell/cc-shell.c
index ffab0a68d..416f00394 100644
--- a/shell/cc-shell.c
+++ b/shell/cc-shell.c
@@ -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);
+}
diff --git a/shell/cc-shell.h b/shell/cc-shell.h
index f5d35dbe6..96d0ca30c 100644
--- a/shell/cc-shell.h
+++ b/shell/cc-shell.h
@@ -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
diff --git a/shell/cc-window.c b/shell/cc-window.c
index a3de5c134..dad3fc24d 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -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);
diff --git a/shell/cc-window.ui b/shell/cc-window.ui
index c03a66944..70fbcb00e 100644
--- a/shell/cc-window.ui
+++ b/shell/cc-window.ui
@@ -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>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]