[gnome-software: 10/18] gs-shell: Add adaptive support to the headerbar
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 10/18] gs-shell: Add adaptive support to the headerbar
- Date: Thu, 15 Apr 2021 12:54:06 +0000 (UTC)
commit 70bc354f2b387fc42c667c42fa38537597f4f7a3
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Mar 17 16:07:04 2021 +0000
gs-shell: Add adaptive support to the headerbar
This allows simplifying the visibility code for the various UI elements.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1111
src/gs-shell.c | 100 ++++++++++++++++++++++++++++++++++++++------------------
src/gs-shell.ui | 30 ++++++++---------
2 files changed, 83 insertions(+), 47 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 90626a813..1f1ab0a08 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -10,6 +10,7 @@
#include "config.h"
+#include <handy.h>
#include <string.h>
#include <glib/gi18n.h>
@@ -69,6 +70,7 @@ struct _GsShell
GQueue *back_entry_stack;
GPtrArray *modal_dialogs;
gchar *events_info_uri;
+ HdyLeaflet *main_leaflet;
GtkStack *stack_main;
GsPage *page;
GsSidebar *sidebar;
@@ -81,10 +83,13 @@ struct _GsShell
gulong scheduler_invalidated_handler;
#endif /* HAVE_MOGWAI */
+ GtkWidget *sidebar_box;
GtkWidget *main_header;
GtkWidget *metered_updates_bar;
- GtkWidget *menu_button;
- GtkWidget *search_button;
+ GtkWidget *menu_button_main;
+ GtkWidget *menu_button_sidebar;
+ GtkWidget *search_button_main;
+ GtkWidget *search_button_sidebar;
GtkWidget *entry_search;
GtkWidget *search_bar;
GtkWidget *button_back;
@@ -400,6 +405,48 @@ gs_shell_clean_back_entry_stack (GsShell *shell)
static void search_button_clicked_cb (GtkToggleButton *toggle_button, GsShell *shell);
static void gs_overview_page_button_cb (GtkWidget *widget, GsShell *shell);
+static void
+update_header_widgets (GsShell *shell)
+{
+ GsShellMode mode = gs_shell_get_mode (shell);
+ gboolean mode_needs_sidebar;
+ gboolean sidebar_visible;
+ gboolean mode_needs_menu;
+ gboolean mode_needs_search;
+
+ /* update the visibility of various shell widgets */
+ mode_needs_sidebar = (mode == GS_SHELL_MODE_OVERVIEW ||
+ mode == GS_SHELL_MODE_INSTALLED ||
+ mode == GS_SHELL_MODE_UPDATES ||
+ mode == GS_SHELL_MODE_SEARCH);
+ gtk_widget_set_visible (shell->sidebar_box, mode_needs_sidebar);
+ sidebar_visible = mode_needs_sidebar && !hdy_leaflet_get_folded (shell->main_leaflet);
+
+ mode_needs_menu = (mode == GS_SHELL_MODE_OVERVIEW ||
+ mode == GS_SHELL_MODE_INSTALLED ||
+ mode == GS_SHELL_MODE_UPDATES ||
+ mode == GS_SHELL_MODE_SEARCH);
+ gtk_widget_set_visible (shell->menu_button_main, mode_needs_menu && !sidebar_visible);
+ gtk_widget_set_visible (shell->menu_button_sidebar, mode_needs_menu && sidebar_visible);
+
+ /* only show the search button in overview and search pages */
+ g_signal_handlers_block_by_func (shell->search_button_main, search_button_clicked_cb, shell);
+ g_signal_handlers_block_by_func (shell->search_button_sidebar, search_button_clicked_cb, shell);
+
+ mode_needs_search = (mode == GS_SHELL_MODE_OVERVIEW ||
+ mode == GS_SHELL_MODE_SEARCH ||
+ mode == GS_SHELL_MODE_INSTALLED);
+ gtk_widget_set_visible (shell->search_button_main, mode_needs_search && !sidebar_visible);
+ gtk_widget_set_visible (shell->search_button_sidebar, mode_needs_search && sidebar_visible);
+
+ /* hide unless we're going to search */
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (shell->search_bar),
+ mode == GS_SHELL_MODE_SEARCH);
+
+ g_signal_handlers_unblock_by_func (shell->search_button_sidebar, search_button_clicked_cb, shell);
+ g_signal_handlers_unblock_by_func (shell->search_button_main, search_button_clicked_cb, shell);
+}
+
static void
stack_notify_visible_child_cb (GObject *object,
GParamSpec *pspec,
@@ -408,10 +455,8 @@ stack_notify_visible_child_cb (GObject *object,
GsShell *shell = GS_SHELL (user_data);
GsPage *page;
GtkWidget *widget;
- GtkStyleContext *context;
GsShellMode mode;
gsize i;
- gboolean buttonbox_visible;
/* Work out the mode for this child. */
for (i = 0; i < G_N_ELEMENTS (page_name); i++) {
@@ -422,32 +467,7 @@ stack_notify_visible_child_cb (GObject *object,
}
g_assert (i < G_N_ELEMENTS (page_name));
- gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (shell->main_header), TRUE);
-
- /* update the visibility of mode-specific header widgets
- */
- buttonbox_visible = (mode == GS_SHELL_MODE_OVERVIEW ||
- mode == GS_SHELL_MODE_INSTALLED ||
- mode == GS_SHELL_MODE_UPDATES ||
- mode == GS_SHELL_MODE_SEARCH);
-
- gtk_widget_set_visible (shell->menu_button, buttonbox_visible);
-
- gtk_widget_set_visible (shell->application_details_header, !buttonbox_visible);
-
- /* only show the search button in overview and search pages */
- g_signal_handlers_block_by_func (shell->search_button, search_button_clicked_cb, shell);
- gtk_widget_set_visible (shell->search_button,
- mode == GS_SHELL_MODE_OVERVIEW ||
- mode == GS_SHELL_MODE_SEARCH ||
- mode == GS_SHELL_MODE_INSTALLED);
- /* hide unless we're going to search */
- gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (shell->search_bar),
- mode == GS_SHELL_MODE_SEARCH);
- g_signal_handlers_unblock_by_func (shell->search_button, search_button_clicked_cb, shell);
-
- context = gtk_widget_get_style_context (shell->main_header);
- gtk_style_context_remove_class (context, "selection-mode");
+ update_header_widgets (shell);
/* set the window title back to default */
gtk_window_set_title (GTK_WINDOW (shell), g_get_application_name ());
@@ -508,6 +528,16 @@ stack_notify_visible_child_cb (GObject *object,
}
}
+static void
+main_leaflet_notify_folded_cb (GObject *obj,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GsShell *shell = GS_SHELL (user_data);
+
+ update_header_widgets (shell);
+}
+
void
gs_shell_change_mode (GsShell *shell,
GsShellMode mode,
@@ -2304,11 +2334,16 @@ gs_shell_class_init (GsShellClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell.ui");
+ gtk_widget_class_bind_template_child (widget_class, GsShell, sidebar_box);
gtk_widget_class_bind_template_child (widget_class, GsShell, main_header);
+ gtk_widget_class_bind_template_child (widget_class, GsShell, main_leaflet);
gtk_widget_class_bind_template_child (widget_class, GsShell, stack_main);
+ gtk_widget_class_bind_template_child (widget_class, GsShell, sidebar);
gtk_widget_class_bind_template_child (widget_class, GsShell, metered_updates_bar);
- gtk_widget_class_bind_template_child (widget_class, GsShell, menu_button);
- gtk_widget_class_bind_template_child (widget_class, GsShell, search_button);
+ gtk_widget_class_bind_template_child (widget_class, GsShell, menu_button_main);
+ gtk_widget_class_bind_template_child (widget_class, GsShell, menu_button_sidebar);
+ gtk_widget_class_bind_template_child (widget_class, GsShell, search_button_main);
+ gtk_widget_class_bind_template_child (widget_class, GsShell, search_button_sidebar);
gtk_widget_class_bind_template_child (widget_class, GsShell, entry_search);
gtk_widget_class_bind_template_child (widget_class, GsShell, search_bar);
gtk_widget_class_bind_template_child (widget_class, GsShell, button_back);
@@ -2353,6 +2388,7 @@ gs_shell_class_init (GsShellClass *klass)
gtk_widget_class_bind_template_callback (widget_class, gs_shell_metered_updates_bar_response_cb);
gtk_widget_class_bind_template_callback (widget_class, stack_notify_visible_child_cb);
gtk_widget_class_bind_template_callback (widget_class, initial_refresh_done);
+ gtk_widget_class_bind_template_callback (widget_class, main_leaflet_notify_folded_cb);
}
static void
diff --git a/src/gs-shell.ui b/src/gs-shell.ui
index 52b958171..f3bd92ab5 100644
--- a/src/gs-shell.ui
+++ b/src/gs-shell.ui
@@ -53,7 +53,7 @@
<property name="active" bind-source="search_bar" bind-property="search-mode-enabled"
bind-flags="sync-create|bidirectional" />
<signal name="clicked" handler="search_button_clicked_cb"/>
<child internal-child="accessible">
- <object class="AtkObject" id="search_button_accessible_sidebar">
+ <object class="AtkObject">
<property name="accessible-name" translatable="yes">Search</property>
</object>
</child>
@@ -61,7 +61,7 @@
<class name="image-button"/>
</style>
<child>
- <object class="GtkImage" id="search_image_sidebar">
+ <object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">edit-find-symbolic</property>
<property name="icon_size">1</property>
@@ -105,7 +105,7 @@
</child>
<child>
<object class="GtkSeparator" id="header_separator">
- <property name="visible">True</property>
+ <property name="visible" bind-source="sidebar_header" bind-property="visible"
bind-flags="sync-create" />
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<style>
@@ -154,13 +154,13 @@
</object>
</child>
<child>
- <object class="GtkToggleButton" id="search_button">
- <property name="visible">True</property>
+ <object class="GtkToggleButton" id="search_button_main">
+ <property name="visible">False</property>
<property name="can_focus">True</property>
<property name="active" bind-source="search_bar" bind-property="search-mode-enabled"
bind-flags="sync-create|bidirectional" />
<signal name="clicked" handler="search_button_clicked_cb"/>
<child internal-child="accessible">
- <object class="AtkObject" id="search_button_accessible">
+ <object class="AtkObject">
<property name="accessible-name" translatable="yes">Search</property>
</object>
</child>
@@ -168,7 +168,7 @@
<class name="image-button"/>
</style>
<child>
- <object class="GtkImage" id="search_image">
+ <object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">edit-find-symbolic</property>
<property name="icon_size">1</property>
@@ -193,8 +193,8 @@
</object>
</child>
<child>
- <object class="GtkMenuButton" id="menu_button">
- <property name="visible">True</property>
+ <object class="GtkMenuButton" id="menu_button_main">
+ <property name="visible">False</property>
<property name="can_focus">True</property>
<property name="sensitive">True</property>
<property name="menu_model">primary_menu</property>
@@ -337,6 +337,7 @@
<property name="can-focus">False</property>
<property name="visible-child">main_box</property>
<property name="transition-type">slide</property>
+ <signal name="notify::folded" handler="main_leaflet_notify_folded_cb"/>
<child>
<object class="GtkBox" id="sidebar_box">
@@ -359,9 +360,6 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="stack">stack_main</property>
- <!-- TODO <property name="search-mode" bind-source="search_bar"
bind-property="search-mode-enabled" bind-flags="bidirectional" />
- <property name="search-query" bind-source="search_entry" bind-property="text"
bind-flags="default" />-->
- <!-- TODO <signal name="show-panel" handler="show_panel_cb" object="CcWindow"
swapped="yes" />-->
<child internal-child="accessible">
<object class="AtkObject">
<property name="accessible-description" translatable="yes">Navigation
sidebar</property>
@@ -479,7 +477,7 @@
</object>
<packing>
<property name="name">overview</property>
- <property name="title" translatable="yes" comments="Translators: A label for a
button to show all available software.">_Explore</property>
+ <property name="title" translatable="yes" comments="Translators: A label for a
button to show all available software.">Explore</property>
<property name="icon-name">non-starred-symbolic</property>
</packing>
</child>
@@ -489,7 +487,9 @@
</object>
<packing>
<property name="name">installed</property>
- <property name="title" translatable="yes" comments="Translators: A label for a
button to show only software which is already installed.">_Installed</property>
+ <!-- FIXME: Add mnemonics support when it’s supported in GTK (same for the other
pages).
+ See https://gitlab.gnome.org/GNOME/gtk/-/issues/3134 -->
+ <property name="title" translatable="yes" comments="Translators: A label for a
button to show only software which is already installed.">Installed</property>
<property name="icon-name">view-list-symbolic</property>
</packing>
</child>
@@ -524,7 +524,7 @@
</object>
<packing>
<property name="name">updates</property>
- <property name="title" translatable="yes" comments="Translators: A label for a
button to show only updates which are available to install.">_Updates</property>
+ <property name="title" translatable="yes" comments="Translators: A label for a
button to show only updates which are available to install.">Updates</property>
<property name="icon-name">view-refresh-symbolic</property>
</packing>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]