Skip to content

Instantly share code, notes, and snippets.

@M4he
Last active October 1, 2022 22:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M4he/3a8171a7f39d9ba9a0cf6bb387b08061 to your computer and use it in GitHub Desktop.
Save M4he/3a8171a7f39d9ba9a0cf6bb387b08061 to your computer and use it in GitHub Desktop.
PCManFM patch for hiding menubar toggle (GTK2 version), accessed via 'View' menu or pressing Ctrl+M
Description: Make menubar visibility optional
Introduces a new toggle for hiding the menubar in the 'View' menu
as well as via Ctrl+M.
pcmanfm (1.3.1-1)
--- pcmanfm-1.3.1.orig/src/app-config.c
+++ pcmanfm-1.3.1/src/app-config.c
@@ -527,6 +527,7 @@ static void fm_app_config_init(FmAppConf
cfg->autorun_choices = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, _free_archoice);
cfg->show_statusbar = TRUE;
+ cfg->show_menubar = TRUE;
#if FM_CHECK_VERSION(1, 2, 0)
cfg->home_path = NULL;
cfg->focus_previous = FALSE;
@@ -770,6 +771,7 @@ void fm_app_config_load_from_key_file(Fm
}
g_strfreev(tmpv);
}
+ fm_key_file_get_bool(kf, "ui", "show_menubar", &cfg->show_menubar);
fm_key_file_get_bool(kf, "ui", "show_statusbar", &cfg->show_statusbar);
if (g_key_file_has_group(kf, "autorun"))
{
@@ -1170,6 +1172,7 @@ void fm_app_config_save_profile(FmAppCon
if (cfg->tb.home)
g_string_append(buf, "home;");
g_string_append_c(buf, '\n');
+ g_string_append_printf(buf, "show_menubar=%d\n", cfg->show_menubar);
g_string_append_printf(buf, "show_statusbar=%d\n", cfg->show_statusbar);
g_string_append_printf(buf, "pathbar_mode_buttons=%d\n", cfg->pathbar_mode_buttons);
--- pcmanfm-1.3.1.orig/src/app-config.h
+++ pcmanfm-1.3.1/src/app-config.h
@@ -144,6 +144,7 @@ struct _FmAppConfig
GtkSortType sort_type;
int sort_by;
#endif
+ gboolean show_menubar;
gboolean show_statusbar;
#if FM_CHECK_VERSION(1, 2, 0)
char *home_path;
--- pcmanfm-1.3.1.orig/src/main-win-ui.c
+++ pcmanfm-1.3.1/src/main-win-ui.c
@@ -119,6 +119,7 @@ static const char main_menu_xml[] =
"<menuitem action='DirTree' />"
#endif
"</menu>"
+ "<menuitem action='ShowMenuBar'/>"
"<menuitem action='ShowStatus'/>"
"<separator/>"
"<menuitem action='DualPane'/>"
@@ -284,6 +285,7 @@ static GtkToggleActionEntry main_win_tog
{"ToolbarNav", NULL, N_("Show _Navigation Buttons"), NULL, NULL, G_CALLBACK(on_toolbar_nav), TRUE},
{"ToolbarHome", NULL, N_("Show '_Home' Button"), NULL, NULL, G_CALLBACK(on_toolbar_home), TRUE},
{"ShowSidePane", NULL, N_("Sho_w Side Pane"), "F9", NULL, G_CALLBACK(on_show_side_pane), TRUE},
+ {"ShowMenuBar", NULL, N_("Show Menu _Bar"), "<Ctrl>M", NULL, G_CALLBACK(on_show_menubar), TRUE},
{"ShowStatus", NULL, N_("Show Status B_ar"), "<Ctrl>B", NULL, G_CALLBACK(on_show_status), TRUE},
{"DualPane", NULL, N_("_Dual Pane Mode"), "F3", N_("Show two panels with folder views"), G_CALLBACK(on_dual_pane), FALSE},
{"Fullscreen", NULL, N_("Fullscreen _Mode"), "F11", NULL, G_CALLBACK(on_fullscreen), FALSE}
--- pcmanfm-1.3.1.orig/src/main-win.c
+++ pcmanfm-1.3.1/src/main-win.c
@@ -107,6 +107,7 @@ static void on_toolbar_new_win(GtkToggle
static void on_toolbar_new_tab(GtkToggleAction *act, FmMainWin *win);
static void on_toolbar_nav(GtkToggleAction *act, FmMainWin *win);
static void on_toolbar_home(GtkToggleAction *act, FmMainWin *win);
+static void on_show_menubar(GtkToggleAction *action, FmMainWin *win);
static void on_show_status(GtkToggleAction *action, FmMainWin *win);
static void on_change_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
static void on_sort_by(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
@@ -913,7 +914,7 @@ static void fm_main_win_init(FmMainWin *
}
#endif
- menubar = gtk_ui_manager_get_widget(ui, "/menubar");
+ win->menubar = GTK_TOOLBAR(gtk_ui_manager_get_widget(ui, "/menubar"));
win->toolbar = GTK_TOOLBAR(gtk_ui_manager_get_widget(ui, "/toolbar"));
/* FIXME: should make these optional */
gtk_toolbar_set_icon_size(win->toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
@@ -946,7 +947,7 @@ static void fm_main_win_init(FmMainWin *
if (atk_obj)
atk_object_set_name(atk_obj, _("History"));
- gtk_box_pack_start( vbox, menubar, FALSE, TRUE, 0 );
+ gtk_box_pack_start( vbox, GTK_WIDGET(win->menubar), FALSE, TRUE, 0 );
gtk_box_pack_start( vbox, GTK_WIDGET(win->toolbar), FALSE, TRUE, 0 );
/* load bookmarks menu */
@@ -1720,6 +1721,10 @@ FmMainWin* fm_main_win_add_win(FmMainWin
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/ShowStatus");
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->show_statusbar);
gtk_widget_set_visible(GTK_WIDGET(win->statusbar), app_config->show_statusbar);
+ /* the same for menu bar */
+ act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/ShowMenuBar");
+ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->show_menubar);
+ gtk_widget_set_visible(GTK_WIDGET(win->menubar), app_config->show_menubar);
/* the same for path bar mode */
gtk_widget_hide(GTK_WIDGET(win->path_bar));
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/PathMode/PathEntry");
@@ -2689,3 +2694,17 @@ static void on_show_status(GtkToggleActi
pcmanfm_save_config(FALSE);
}
}
+
+static void on_show_menubar(GtkToggleAction *action, FmMainWin *win)
+{
+ gboolean active;
+
+ active = gtk_toggle_action_get_active(action);
+ if (active != app_config->show_menubar)
+ {
+ app_config->show_menubar = active;
+ fm_config_emit_changed(fm_config, "menubar");
+ gtk_widget_set_visible(GTK_WIDGET(win->menubar), active);
+ pcmanfm_save_config(FALSE);
+ }
+}
--- pcmanfm-1.3.1.orig/src/main-win.h
+++ pcmanfm-1.3.1/src/main-win.h
@@ -51,6 +51,7 @@ struct _FmMainWin
GtkRadioAction* first_view_mode;
GtkRadioAction* first_side_pane_mode;
GtkToolbar* toolbar;
+ GtkToolbar* menubar;
FmPathEntry* location;
FmPathBar* path_bar;
GtkNotebook* notebook;
@kaythomas0
Copy link

This is great, thank you!

@pdachim
Copy link

pdachim commented Apr 13, 2022

Hey mate I am a bit new to Linux and still learning how do I some things. how exactly would I use this patch on pcmanfm as I dont really like some of the other file managers.

@M4he
Copy link
Author

M4he commented Apr 13, 2022

Hey mate I am a bit new to Linux and still learning how do I some things. how exactly would I use this patch on pcmanfm as I dont really like some of the other file managers.

@pdachim the process will be specific to the distribution and package manager you are using.
I can show you the process for Ubuntu 20.04 to get you started. It should be applicable to any Debian-based distribution as well.
Note that the patch command might show errors and fail if the PCManFM version is too old or new and the patch doesn't match its code structure. I've only tested the patch with PCManFM 1.3.1 so your mileage may vary.

# download the source code package
# (this will also automatically extract it in a subfolder)
apt source pcmanfm

# install necessary packages to compile pcmanfm
sudo apt build-dep pcmanfm

# enter the extracted source code directory (version number may differ)
cd pcmanfm-1.3.1/

# create a file using any editor (e.g. nano) and paste the patch into it
nano pcmanfm_hide_menubar.patch

# apply the patch
patch -p1 < pcmanfm_hide_menubar.patch

# build the modified pcmanfm package
dpkg-buildpackage -rfakeroot -uc -b

The built package will be in the parent directory, e.g. you can install it like this:

sudo dpkg -i ../pcmanfm_1.3.1-1_amd64.deb

@pdachim
Copy link

pdachim commented Apr 13, 2022

Thanks alot mate will give it ago... I am using raspian light with lxde as a environment and openbox as a window manager. So that is nice and light for a raspberry pi. And raspian is Debian based.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment