[nautilus/wip/cdavis/adaptive-flap: 172/178] window: Hide toolbar buttons at small sizes
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/cdavis/adaptive-flap: 172/178] window: Hide toolbar buttons at small sizes
- Date: Mon, 22 Feb 2021 10:43:58 +0000 (UTC)
commit f3a32b5a8b3cd3f3442cc1eceb33e04b267a7098
Author: Christopher Davis <brainblasted disroot org>
Date: Tue Nov 17 23:09:20 2020 -0800
window: Hide toolbar buttons at small sizes
This hides toolbar navigation buttons and the operations
button in the headerbar at small sizes.
src/nautilus-adaptive-mode.h | 34 +++++++++++++++++++++++
src/nautilus-toolbar.c | 27 ++++++++++++++++++
src/nautilus-toolbar.h | 4 +++
src/nautilus-window.c | 31 +++++++++++++++++++++
src/resources/ui/nautilus-toolbar.ui | 53 +++++++++++++++++-------------------
5 files changed, 121 insertions(+), 28 deletions(-)
---
diff --git a/src/nautilus-adaptive-mode.h b/src/nautilus-adaptive-mode.h
new file mode 100644
index 000000000..1af632ed7
--- /dev/null
+++ b/src/nautilus-adaptive-mode.h
@@ -0,0 +1,34 @@
+/* nautilus-adaptive-mode.h
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * Adapted from https://gitlab.gnome.org/GNOME/epiphany/-/blob/master/src/ephy-adaptive-mode.h
+ * (C) 2018 Purism SPC, Adrien Plazas <kekun plazas laposte net>
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+ NAUTILUS_ADAPTIVE_MODE_NARROW,
+ NAUTILUS_ADAPTIVE_MODE_NORMAL,
+} NautilusAdaptiveMode;
+
+G_END_DECLS
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 4e8f50821..3f0b1eec8 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -73,7 +73,10 @@ struct _NautilusToolbar
NautilusContainerMaxWidth *toolbar_switcher_container_max_width;
GtkWidget *path_bar;
GtkWidget *location_entry;
+
GtkWidget *fold_button;
+ GtkWidget *navigation_box;
+ GtkWidget *views_box;
gboolean show_location_entry;
gboolean show_fold_button;
@@ -1003,6 +1006,28 @@ nautilus_toolbar_on_window_constructed (NautilusToolbar *self)
undo_manager_changed (self);
}
+void
+nautilus_toolbar_set_adaptive_mode (NautilusToolbar *self,
+ NautilusAdaptiveMode adaptive_mode)
+{
+ switch (adaptive_mode)
+ {
+ case NAUTILUS_ADAPTIVE_MODE_NARROW:
+ {
+ gtk_widget_hide (self->navigation_box);
+ gtk_widget_hide (self->views_box);
+ }
+ break;
+
+ case NAUTILUS_ADAPTIVE_MODE_NORMAL:
+ {
+ gtk_widget_show (self->navigation_box);
+ gtk_widget_show (self->views_box);
+ }
+ break;
+ }
+}
+
static void
nautilus_toolbar_get_property (GObject *object,
guint property_id,
@@ -1271,6 +1296,8 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
"/org/gnome/nautilus/ui/nautilus-toolbar.ui");
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, fold_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, navigation_box);
+ gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, views_box);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, operations_button);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, operations_icon);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, operations_popover);
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index 364bc76d8..8947d2eef 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <libhandy-1/handy.h>
+#include "nautilus-adaptive-mode.h"
#include "nautilus-window-slot.h"
G_BEGIN_DECLS
@@ -51,6 +52,9 @@ gboolean nautilus_toolbar_is_operations_button_active (NautilusToolbar *toolba
void nautilus_toolbar_on_window_constructed (NautilusToolbar *toolbar);
+void nautilus_toolbar_set_adaptive_mode (NautilusToolbar *self,
+ NautilusAdaptiveMode adaptive_mode);
+
void nautilus_toolbar_set_window_slot (NautilusToolbar *self,
NautilusWindowSlot *window_slot);
G_END_DECLS
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 49d0314dc..b0cc14443 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -47,6 +47,7 @@
#define DEBUG_FLAG NAUTILUS_DEBUG_WINDOW
#include "nautilus-debug.h"
+#include "nautilus-adaptive-mode.h"
#include "nautilus-application.h"
#include "nautilus-bookmark-list.h"
#include "nautilus-clipboard.h"
@@ -713,6 +714,35 @@ nautilus_window_grab_focus (GtkWidget *widget)
}
}
+static void
+update_adaptive_mode (NautilusWindow *window)
+{
+ NautilusToolbar *toolbar = NAUTILUS_TOOLBAR (window->toolbar);
+ gboolean is_narrow, is_mobile_landscape;
+ gint width, height;
+ NautilusAdaptiveMode adaptive_mode;
+
+ gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+
+ is_narrow = width <= 600;
+ is_mobile_landscape = height <= 400;
+ adaptive_mode = (is_narrow || is_mobile_landscape) ?
+ NAUTILUS_ADAPTIVE_MODE_NARROW :
+ NAUTILUS_ADAPTIVE_MODE_NORMAL;
+ nautilus_toolbar_set_adaptive_mode (toolbar, adaptive_mode);
+}
+
+static void
+nautilus_window_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ NautilusWindow *window = NAUTILUS_WINDOW (widget);
+
+ GTK_WIDGET_CLASS (nautilus_window_parent_class)->size_allocate (widget, allocation);
+
+ update_adaptive_mode (window);
+}
+
static void
restore_focus_widget (NautilusWindow *window)
{
@@ -2757,6 +2787,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
wclass->key_press_event = nautilus_window_key_press_event;
wclass->delete_event = nautilus_window_delete_event;
wclass->grab_focus = nautilus_window_grab_focus;
+ wclass->size_allocate = nautilus_window_size_allocate;
gtk_widget_class_set_template_from_resource (wclass,
"/org/gnome/nautilus/ui/nautilus-window.ui");
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index bbeb0ecba..7a1bc69b0 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -610,7 +610,31 @@
</object>
</child>
<child>
- <object class="GtkBox">
+ <object class="GtkMenuButton" id="app_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="popover">app_menu</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">open-menu-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="image-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="views_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -657,7 +681,6 @@
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
- <property name="margin_end">6</property>
<child>
<object class="GtkButton" id="view_toggle_button">
<property name="visible">True</property>
@@ -718,32 +741,6 @@
<property name="position">2</property>
</packing>
</child>
- <child>
- <object class="GtkMenuButton" id="app_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="popover">app_menu</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">open-menu-symbolic</property>
- <property name="icon_size">1</property>
- </object>
- </child>
- <style>
- <class name="image-button"/>
- </style>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
- </child>
</object>
<packing>
<property name="pack_type">end</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]