Hide nautilus sidebar

Hello, I would really like to get the F9 key back for removing the sidebar.

I am aware of this discussion:

and I understand that this is not going to be changed.

My question is, what is the easiest way to do this if I am willing to build myself from source? I have been poking around and I can’t easily find it. I think what I want to do is change the threshold that nautilus uses to decide whether the window is in “narrow” mode. If I can make it always think it is “narrow” then I think the F9 key will do what I want.

thanks!

I think what I want to do is change the threshold that nautilus uses to decide whether the window is in “narrow” mode. If I can make it always think it is “narrow” then I think the F9 key will do what I want.

No, because it changes many other unrelated variables.

Here’s a patch to have it the collapse button show up all the time and the F9 action always active:

diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 84569bca9..2db9e23eb 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1106,7 +1106,6 @@ static void
 nautilus_window_initialize_actions (NautilusWindow *window)
 {
     GApplication *app;
-    GAction *action;
     gchar detailed_action[80];
     gchar accel[80];
     gint i;
@@ -1141,10 +1140,6 @@ nautilus_window_initialize_actions (NautilusWindow *window)
     nautilus_window_on_undo_changed (nautilus_file_undo_manager_get (), window);
 
 #undef ACCELS
-
-    action = g_action_map_lookup_action (G_ACTION_MAP (window), "toggle-sidebar");
-    g_object_bind_property (window->split_view, "collapsed",
-                            action, "enabled", G_BINDING_SYNC_CREATE);
 }
 
 static gboolean
diff --git a/src/resources/ui/nautilus-window.ui b/src/resources/ui/nautilus-window.ui
index feffa930b..b4f1fd7bf 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -154,6 +154,7 @@
                   <object class="AdwToolbarView">
                     <child type="top">
                       <object class="NautilusToolbar" id="toolbar">
+                        <property name="show-sidebar-button">true</property>
                         <property name="show-view-controls">true</property>
                         <property name="show-history-controls">true</property>
                         <property name="sidebar-button-active" bind-source="split_view" bind-property="show-sidebar" bind-flags="bidirectional|sync-create"/>
@@ -204,7 +205,6 @@
         <setter object="split_view" property="collapsed">True</setter>
         <setter object="split_view" property="enable-show-gesture">True</setter>
         <setter object="split_view" property="enable-hide-gesture">True</setter>
-        <setter object="toolbar" property="show-sidebar-button">True</setter>
         <setter object="toolbar" property="show-view-controls">False</setter>
         <setter object="toolbar" property="show-history-controls">False</setter>
         <setter object="action_bar" property="revealed">True</setter>

If you don’t want the button to show up in normal width, then don’t apply the last two changes.

1 Like

Awesome thank you Khalid! I think I am using an older version (43.2, included with Debian 12), but I was able to get the first part of your patch to work, and now the F9 key does work.

My next question is, how do I get it folded by default when I open nautilus?

It feels like I need to do something around line 45 of this file:

or maybe I somehow have to call action_toggle_sidebar() at some point during window construction… but I can’t quite work out what to do (unfortunately Claude was unable to help…)

diff --git a/src/resources/ui/nautilus-window.ui b/src/resources/ui/nautilus-window.ui
index d8db7f7cc..91b6384d0 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -44,6 +44,7 @@
             <child>
               <object class="AdwFlap" id="content_flap">
                 <property name="swipe-to-close" bind-source="content_flap" bind-property="folded" bind-flags="sync-create"/>
+                <property name="reveal-flap">false</property>
                 <child type="flap">
                   <object class="NautilusGtkPlacesSidebar" id="places_sidebar">
                     <property name="vexpand">True</property>
1 Like

amazing thank you!!!