window: Use a HdyLeaflet
This allows the window to be folded to show either the sidebar or the panel when not enough space is available. This reverts commit 2854669f5c8280a32d0b5fa6c5399cc391ef06f3.
This commit is contained in:
parent
39ed06188a
commit
638dc94a8d
2 changed files with 128 additions and 5 deletions
|
@ -57,11 +57,13 @@ struct _CcWindow
|
|||
GtkWidget *stack;
|
||||
GtkWidget *header;
|
||||
GtkWidget *header_box;
|
||||
GtkWidget *main_leaflet;
|
||||
GtkWidget *list_scrolled;
|
||||
GtkWidget *panel_headerbar;
|
||||
GtkWidget *search_scrolled;
|
||||
GtkWidget *panel_list;
|
||||
GtkWidget *previous_button;
|
||||
GtkWidget *back_revealer;
|
||||
GtkWidget *top_right_box;
|
||||
GtkWidget *search_button;
|
||||
GtkWidget *search_bar;
|
||||
|
@ -80,6 +82,8 @@ struct _CcWindow
|
|||
|
||||
CcPanel *active_panel;
|
||||
GSettings *settings;
|
||||
|
||||
CcPanelListView previous_list_view;
|
||||
};
|
||||
|
||||
static void cc_shell_iface_init (CcShellInterface *iface);
|
||||
|
@ -120,6 +124,13 @@ remove_all_custom_widgets (CcWindow *self)
|
|||
CC_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
on_sidebar_activated_cb (CcPanel *panel,
|
||||
CcWindow *self)
|
||||
{
|
||||
hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "panel");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
activate_panel (CcWindow *self,
|
||||
const gchar *id,
|
||||
|
@ -151,6 +162,8 @@ activate_panel (CcWindow *self,
|
|||
/* Begin the profile */
|
||||
g_timer_start (timer);
|
||||
|
||||
if (self->current_panel)
|
||||
g_signal_handlers_disconnect_by_data (self->current_panel, self);
|
||||
self->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (self), id, parameters));
|
||||
cc_shell_set_active_panel (CC_SHELL (self), CC_PANEL (self->current_panel));
|
||||
gtk_widget_show (self->current_panel);
|
||||
|
@ -170,6 +183,10 @@ activate_panel (CcWindow *self,
|
|||
|
||||
sidebar_widget = cc_panel_get_sidebar_widget (CC_PANEL (self->current_panel));
|
||||
cc_panel_list_add_sidebar_widget (CC_PANEL_LIST (self->panel_list), sidebar_widget);
|
||||
/* Ensure we show the panel when when the leaflet is folded and a sidebar
|
||||
* widget's row is activated.
|
||||
*/
|
||||
g_signal_connect_object (self->current_panel, "sidebar-activated", G_CALLBACK (on_sidebar_activated_cb), self, 0);
|
||||
|
||||
/* Finish profiling */
|
||||
g_timer_stop (timer);
|
||||
|
@ -370,6 +387,7 @@ set_active_panel_from_id (CcShell *shell,
|
|||
const gchar *start_id,
|
||||
GVariant *parameters,
|
||||
gboolean add_to_history,
|
||||
gboolean force_moving_to_the_panel,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GIcon) gicon = NULL;
|
||||
|
@ -378,17 +396,22 @@ set_active_panel_from_id (CcShell *shell,
|
|||
GtkTreeIter iter;
|
||||
GtkWidget *old_panel;
|
||||
CcWindow *self;
|
||||
CcPanelListView view;
|
||||
gboolean activated;
|
||||
gboolean found;
|
||||
|
||||
CC_ENTRY;
|
||||
|
||||
self = CC_WINDOW (shell);
|
||||
view = cc_panel_list_get_view (CC_PANEL_LIST (self->panel_list));
|
||||
|
||||
/* When loading the same panel again, just set its parameters */
|
||||
if (g_strcmp0 (self->current_panel_id, start_id) == 0)
|
||||
{
|
||||
g_object_set (G_OBJECT (self->current_panel), "parameters", parameters, NULL);
|
||||
if (force_moving_to_the_panel || self->previous_list_view == view)
|
||||
hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "panel");
|
||||
self->previous_list_view = view;
|
||||
CC_RETURN (TRUE);
|
||||
}
|
||||
|
||||
|
@ -422,6 +445,9 @@ set_active_panel_from_id (CcShell *shell,
|
|||
if (add_to_history)
|
||||
add_current_panel_to_history (shell, start_id);
|
||||
|
||||
if (force_moving_to_the_panel)
|
||||
hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "panel");
|
||||
|
||||
g_free (self->current_panel_id);
|
||||
self->current_panel_id = g_strdup (start_id);
|
||||
|
||||
|
@ -471,12 +497,39 @@ switch_to_previous_panel (CcWindow *self)
|
|||
|
||||
g_debug ("Going to previous panel (%s)", previous_panel_id);
|
||||
|
||||
set_active_panel_from_id (CC_SHELL (self), previous_panel_id, NULL, FALSE, NULL);
|
||||
set_active_panel_from_id (CC_SHELL (self), previous_panel_id, NULL, FALSE, FALSE, NULL);
|
||||
|
||||
CC_EXIT;
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
static void
|
||||
update_fold_state (CcWindow *shell)
|
||||
{
|
||||
GtkWidget *header_child = hdy_leaflet_get_visible_child (HDY_LEAFLET (shell->header_box));
|
||||
HdyFold fold = hdy_leaflet_get_fold (HDY_LEAFLET (shell->header_box));
|
||||
|
||||
hdy_header_group_set_focus (shell->header_group, fold == HDY_FOLD_FOLDED ? GTK_HEADER_BAR (header_child) : NULL);
|
||||
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (shell->back_revealer), fold == HDY_FOLD_FOLDED);
|
||||
}
|
||||
|
||||
static void
|
||||
notify_header_visible_child_cb (HdyLeaflet *leaflet,
|
||||
GParamSpec *pspec,
|
||||
CcWindow *shell)
|
||||
{
|
||||
update_fold_state (shell);
|
||||
}
|
||||
|
||||
static void
|
||||
notify_fold_cb (HdyLeaflet *leaflet,
|
||||
GParamSpec *pspec,
|
||||
CcWindow *shell)
|
||||
{
|
||||
update_fold_state (shell);
|
||||
}
|
||||
|
||||
static void
|
||||
show_panel_cb (CcPanelList *panel_list,
|
||||
const gchar *panel_id,
|
||||
|
@ -485,7 +538,7 @@ show_panel_cb (CcPanelList *panel_list,
|
|||
if (!panel_id)
|
||||
return;
|
||||
|
||||
set_active_panel_from_id (CC_SHELL (self), panel_id, NULL, TRUE, NULL);
|
||||
set_active_panel_from_id (CC_SHELL (self), panel_id, NULL, TRUE, FALSE, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -499,6 +552,13 @@ search_entry_activate_cb (GtkEntry *entry,
|
|||
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (self->search_bar), !changed);
|
||||
}
|
||||
|
||||
static void
|
||||
back_button_clicked_cb (GtkButton *button,
|
||||
CcWindow *shell)
|
||||
{
|
||||
hdy_leaflet_set_visible_child_name (HDY_LEAFLET (shell->main_leaflet), "sidebar");
|
||||
}
|
||||
|
||||
static void
|
||||
previous_button_clicked_cb (GtkButton *button,
|
||||
CcWindow *shell)
|
||||
|
@ -633,7 +693,7 @@ cc_window_set_active_panel_from_id (CcShell *shell,
|
|||
GVariant *parameters,
|
||||
GError **error)
|
||||
{
|
||||
return set_active_panel_from_id (shell, start_id, parameters, TRUE, error);
|
||||
return set_active_panel_from_id (shell, start_id, parameters, TRUE, TRUE, error);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -812,12 +872,14 @@ cc_window_class_init (CcWindowClass *klass)
|
|||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/gtk/cc-window.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, back_revealer);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, development_warning_dialog);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, header);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_box);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_group);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_sizegroup);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, list_scrolled);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, main_leaflet);
|
||||
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, previous_button);
|
||||
|
@ -827,7 +889,10 @@ cc_window_class_init (CcWindowClass *klass)
|
|||
gtk_widget_class_bind_template_child (widget_class, CcWindow, stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcWindow, top_right_box);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, back_button_clicked_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, gdk_window_set_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, notify_header_visible_child_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, notify_fold_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_development_warning_dialog_responded_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb);
|
||||
|
@ -849,10 +914,13 @@ cc_window_init (CcWindow *self)
|
|||
self->settings = g_settings_new ("org.gnome.ControlCenter");
|
||||
self->custom_widgets = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||
self->previous_panels = g_queue_new ();
|
||||
self->previous_list_view = cc_panel_list_get_view (CC_PANEL_LIST (self->panel_list));
|
||||
|
||||
/* Add a custom CSS class on development builds */
|
||||
if (in_flatpak_sandbox ())
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "devel");
|
||||
|
||||
update_fold_state (self);
|
||||
}
|
||||
|
||||
CcWindow *
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
<signal name="map-event" handler="window_map_event_cb" object="CcWindow" swapped="no" />
|
||||
<signal name="key-press-event" handler="window_key_press_event_cb" object="CcWindow" swapped="no" after="yes" />
|
||||
<child>
|
||||
<object class="GtkBox" id="main_hbox">
|
||||
<object class="HdyLeaflet" id="main_leaflet">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="mode-transition-type">slide</property>
|
||||
<property name="child-transition-type">slide</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="sidebar_box">
|
||||
<property name="visible">True</property>
|
||||
|
@ -73,6 +75,9 @@
|
|||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">sidebar</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator" id="panel_separator">
|
||||
|
@ -96,6 +101,9 @@
|
|||
<class name="background"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">panel</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
@ -104,10 +112,17 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="header_box">
|
||||
<object class="HdyLeaflet" id="header_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="mode-transition-type" bind-source="main_leaflet" bind-property="mode-transition-type" bind-flags="bidirectional|sync-create"/>
|
||||
<property name="mode-transition-duration" bind-source="main_leaflet" bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
|
||||
<property name="child-transition-type" bind-source="main_leaflet" bind-property="child-transition-type" bind-flags="bidirectional|sync-create"/>
|
||||
<property name="child-transition-duration" bind-source="main_leaflet" bind-property="child-transition-duration" bind-flags="bidirectional|sync-create"/>
|
||||
<property name="visible-child-name" bind-source="main_leaflet" bind-property="visible-child-name" bind-flags="bidirectional|sync-create"/>
|
||||
<signal name="notify::visible-child" handler="notify_header_visible_child_cb" swapped="no"/>
|
||||
<signal name="notify::fold" handler="notify_fold_cb" object="CcWindow" after="yes" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkHeaderBar" id="header">
|
||||
<property name="visible">True</property>
|
||||
|
@ -185,6 +200,9 @@
|
|||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">sidebar</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator" id="header_separator">
|
||||
|
@ -202,6 +220,40 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="show_close_button">True</property>
|
||||
<child>
|
||||
<object class="GtkRevealer" id="back_revealer">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="transition-type">crossfade</property>
|
||||
<property name="transition-duration" bind-source="main_leaflet" bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
|
||||
<child>
|
||||
<object class="GtkButton" id="back">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="use-underline">True</property>
|
||||
<signal name="clicked" handler="back_button_clicked_cb" object="CcWindow" swapped="no" />
|
||||
<style>
|
||||
<class name="image-button"/>
|
||||
</style>
|
||||
<child internal-child="accessible">
|
||||
<object class="AtkObject" id="a11y-back">
|
||||
<property name="accessible-name" translatable="yes">Back</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage" id="back_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">go-previous-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="top_right_box">
|
||||
<property name="visible">True</property>
|
||||
|
@ -212,6 +264,9 @@
|
|||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">panel</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue