Blame SOURCES/evolution-3.22.6-hide-menu-option.patch

a00a81
From 439bf03a5120db0ab3bff9958721297b4c32aa71 Mon Sep 17 00:00:00 2001
a00a81
From: Milan Crha <mcrha@redhat.com>
a00a81
Date: Fri, 7 Oct 2016 13:24:43 +0200
a00a81
Subject: Bug 772175 - Allow hiding menu bar (and show it via alt)
a00a81
a00a81
---
a00a81
 data/org.gnome.evolution.shell.gschema.xml.in | 10 +++
a00a81
 shell/e-shell-window-actions.c                | 25 +++++++
a00a81
 shell/e-shell-window-actions.h                |  2 +
a00a81
 shell/e-shell-window-private.c                | 90 ++++++++++++++++++++++++++
a00a81
 shell/e-shell-window-private.h                |  3 +
a00a81
 shell/e-shell-window.c                        | 93 ++++++++++++++++++++++++++-
a00a81
 shell/e-shell-window.h                        |  5 ++
a00a81
 ui/evolution-shell.ui                         |  1 +
a00a81
 8 files changed, 228 insertions(+), 1 deletion(-)
a00a81
a00a81
diff --git a/data/org.gnome.evolution.shell.gschema.xml.in b/data/org.gnome.evolution.shell.gschema.xml.in
a00a81
index 02a5a18..13b3b36 100644
a00a81
--- a/data/org.gnome.evolution.shell.gschema.xml.in
a00a81
+++ b/data/org.gnome.evolution.shell.gschema.xml.in
a00a81
@@ -60,6 +60,16 @@
a00a81
       <_summary>Window button style</_summary>
a00a81
       <_description>The style of the window buttons.  Can be "text", "icons", "both", "toolbar".  If "toolbar" is set, the style of the buttons is determined by the GNOME toolbar setting.</_description>
a00a81
     </key>
a00a81
+    <key name="menubar-visible" type="b">
a00a81
+      <default>true</default>
a00a81
+      <_summary>Menubar is visible</_summary>
a00a81
+      <_description>Whether the menubar should be visible.</_description>
a00a81
+    </key>
a00a81
+    <key name="menubar-visible-sub" type="b">
a00a81
+      <default>true</default>
a00a81
+      <_summary>Menubar is visible</_summary>
a00a81
+      <_description>Whether the menubar should be visible.</_description>
a00a81
+    </key>
a00a81
     <key name="toolbar-visible" type="b">
a00a81
       <default>true</default>
a00a81
       <_summary>Toolbar is visible</_summary>
a00a81
diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c
a00a81
index 5665821..c1db9c6 100644
a00a81
--- a/shell/e-shell-window-actions.c
a00a81
+++ b/shell/e-shell-window-actions.c
a00a81
@@ -522,6 +522,17 @@ action_search_save_cb (GtkAction *action,
a00a81
 }
a00a81
 
a00a81
 /**
a00a81
+ * E_SHELL_WINDOW_ACTION_SHOW_MENUBAR:
a00a81
+ * @window: an #EShellWindow
a00a81
+ *
a00a81
+ * This toggle action controls whether the menu bar is visible.
a00a81
+ *
a00a81
+ * Main menu item: View -> Layout -> Show Menu Bar
a00a81
+ *
a00a81
+ * Since: 3.24
a00a81
+ **/
a00a81
+
a00a81
+/**
a00a81
  * E_SHELL_WINDOW_ACTION_SHOW_SIDEBAR:
a00a81
  * @window: an #EShellWindow
a00a81
  *
a00a81
@@ -1022,6 +1033,14 @@ static EPopupActionEntry shell_popup_entries[] = {
a00a81
 
a00a81
 static GtkToggleActionEntry shell_toggle_entries[] = {
a00a81
 
a00a81
+	{ "show-menubar",
a00a81
+	  NULL,
a00a81
+	  N_("Show _Menu Bar"),
a00a81
+	  NULL,
a00a81
+	  N_("Show the menu bar"),
a00a81
+	  NULL,
a00a81
+	  TRUE },
a00a81
+
a00a81
 	{ "show-sidebar",
a00a81
 	  NULL,
a00a81
 	  N_("Show Side _Bar"),
a00a81
@@ -1272,6 +1291,12 @@ e_shell_window_actions_init (EShellWindow *shell_window)
a00a81
 		e_shell_utils_is_quick_reference_available (e_shell_window_get_shell (shell_window)));
a00a81
 
a00a81
 	e_binding_bind_property (
a00a81
+		shell_window, "menubar-visible",
a00a81
+		ACTION (SHOW_MENUBAR), "active",
a00a81
+		G_BINDING_BIDIRECTIONAL |
a00a81
+		G_BINDING_SYNC_CREATE);
a00a81
+
a00a81
+	e_binding_bind_property (
a00a81
 		shell_window, "sidebar-visible",
a00a81
 		ACTION (SHOW_SIDEBAR), "active",
a00a81
 		G_BINDING_BIDIRECTIONAL |
a00a81
diff --git a/shell/e-shell-window-actions.h b/shell/e-shell-window-actions.h
a00a81
index 09682c4..b3e37fb 100644
a00a81
--- a/shell/e-shell-window-actions.h
a00a81
+++ b/shell/e-shell-window-actions.h
a00a81
@@ -74,6 +74,8 @@
a00a81
 	E_SHELL_WINDOW_ACTION ((window), "search-save")
a00a81
 #define E_SHELL_WINDOW_ACTION_SELECT_ALL(window) \
a00a81
 	E_SHELL_WINDOW_ACTION ((window), "select-all")
a00a81
+#define E_SHELL_WINDOW_ACTION_SHOW_MENUBAR(window) \
a00a81
+	E_SHELL_WINDOW_ACTION ((window), "show-menubar")
a00a81
 #define E_SHELL_WINDOW_ACTION_SHOW_SIDEBAR(window) \
a00a81
 	E_SHELL_WINDOW_ACTION ((window), "show-sidebar")
a00a81
 #define E_SHELL_WINDOW_ACTION_SHOW_SWITCHER(window) \
a00a81
diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c
a00a81
index f9e21b1..2de82b6 100644
a00a81
--- a/shell/e-shell-window-private.c
a00a81
+++ b/shell/e-shell-window-private.c
a00a81
@@ -247,6 +247,77 @@ e_shell_window_private_init (EShellWindow *shell_window)
a00a81
 }
a00a81
 
a00a81
 static gboolean
a00a81
+delayed_menubar_show_cb (gpointer user_data)
a00a81
+{
a00a81
+	EShellWindow *shell_window = user_data;
a00a81
+
a00a81
+	g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), FALSE);
a00a81
+
a00a81
+	shell_window->priv->delayed_menubar_show_id = 0;
a00a81
+
a00a81
+	if (!e_shell_window_get_menubar_visible (shell_window)) {
a00a81
+		GtkWidget *main_menu;
a00a81
+
a00a81
+		main_menu = e_shell_window_get_managed_widget (shell_window, "/main-menu");
a00a81
+
a00a81
+		gtk_widget_show (main_menu);
a00a81
+		gtk_widget_grab_focus (main_menu);
a00a81
+	}
a00a81
+
a00a81
+	return FALSE;
a00a81
+}
a00a81
+
a00a81
+static void
a00a81
+e_shell_window_event_after_cb (EShellWindow *shell_window,
a00a81
+			       GdkEvent *event)
a00a81
+{
a00a81
+	GtkWidget *main_menu;
a00a81
+
a00a81
+	g_return_if_fail (event != NULL);
a00a81
+
a00a81
+	if (event->type != GDK_KEY_PRESS &&
a00a81
+	    event->type != GDK_KEY_RELEASE &&
a00a81
+	    event->type != GDK_BUTTON_RELEASE &&
a00a81
+	    event->type != GDK_FOCUS_CHANGE)
a00a81
+		return;
a00a81
+
a00a81
+	g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
a00a81
+
a00a81
+	if (e_shell_window_get_menubar_visible (shell_window))
a00a81
+		return;
a00a81
+
a00a81
+	main_menu = e_shell_window_get_managed_widget (shell_window, "/main-menu");
a00a81
+
a00a81
+	if (event->type == GDK_KEY_PRESS) {
a00a81
+		GdkEventKey *key_event;
a00a81
+
a00a81
+		key_event = (GdkEventKey *) event;
a00a81
+
a00a81
+		if ((key_event->keyval == GDK_KEY_Alt_L || key_event->keyval == GDK_KEY_Alt_R) &&
a00a81
+		    !(key_event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK))) {
a00a81
+			if (shell_window->priv->delayed_menubar_show_id) {
a00a81
+				g_source_remove (shell_window->priv->delayed_menubar_show_id);
a00a81
+				shell_window->priv->delayed_menubar_show_id = 0;
a00a81
+
a00a81
+				delayed_menubar_show_cb (shell_window);
a00a81
+			} else {
a00a81
+				/* To not flash when using Alt+Tab or similar system-wide shortcuts */
a00a81
+				shell_window->priv->delayed_menubar_show_id =
a00a81
+					e_named_timeout_add (250, delayed_menubar_show_cb, shell_window);
a00a81
+			}
a00a81
+		}
a00a81
+	} else if (event->type != GDK_BUTTON_RELEASE || !(event->button.state & GDK_MOD1_MASK)) {
a00a81
+		if (shell_window->priv->delayed_menubar_show_id) {
a00a81
+			g_source_remove (shell_window->priv->delayed_menubar_show_id);
a00a81
+			shell_window->priv->delayed_menubar_show_id = 0;
a00a81
+		}
a00a81
+
a00a81
+		if (gtk_widget_get_visible (main_menu))
a00a81
+			gtk_widget_hide (main_menu);
a00a81
+	}
a00a81
+}
a00a81
+
a00a81
+static gboolean
a00a81
 shell_window_check_is_main_instance (GtkApplication *application,
a00a81
 				     GtkWindow *window)
a00a81
 {
a00a81
@@ -444,6 +515,11 @@ e_shell_window_private_constructed (EShellWindow *shell_window)
a00a81
 			G_SETTINGS_BIND_DEFAULT);
a00a81
 
a00a81
 		g_settings_bind (
a00a81
+			settings, "menubar-visible",
a00a81
+			shell_window, "menubar-visible",
a00a81
+			G_SETTINGS_BIND_DEFAULT);
a00a81
+
a00a81
+		g_settings_bind (
a00a81
 			settings, "sidebar-visible",
a00a81
 			shell_window, "sidebar-visible",
a00a81
 			G_SETTINGS_BIND_DEFAULT);
a00a81
@@ -464,6 +540,12 @@ e_shell_window_private_constructed (EShellWindow *shell_window)
a00a81
 			G_SETTINGS_BIND_DEFAULT);
a00a81
 	} else {
a00a81
 		g_settings_bind (
a00a81
+			settings, "menubar-visible-sub",
a00a81
+			shell_window, "menubar-visible",
a00a81
+			G_SETTINGS_BIND_DEFAULT |
a00a81
+			G_SETTINGS_BIND_GET_NO_CHANGES);
a00a81
+
a00a81
+		g_settings_bind (
a00a81
 			settings, "folder-bar-width-sub",
a00a81
 			priv->content_pane, "position",
a00a81
 			G_SETTINGS_BIND_DEFAULT |
a00a81
@@ -521,6 +603,9 @@ e_shell_window_private_constructed (EShellWindow *shell_window)
a00a81
 	gtk_application_add_window (GTK_APPLICATION (shell), window);
a00a81
 
a00a81
 	g_object_unref (settings);
a00a81
+
a00a81
+	g_signal_connect (shell_window, "event-after",
a00a81
+		G_CALLBACK (e_shell_window_event_after_cb), NULL);
a00a81
 }
a00a81
 
a00a81
 void
a00a81
@@ -528,6 +613,11 @@ e_shell_window_private_dispose (EShellWindow *shell_window)
a00a81
 {
a00a81
 	EShellWindowPrivate *priv = shell_window->priv;
a00a81
 
a00a81
+	if (priv->delayed_menubar_show_id) {
a00a81
+		g_source_remove (priv->delayed_menubar_show_id);
a00a81
+		priv->delayed_menubar_show_id = 0;
a00a81
+	}
a00a81
+
a00a81
 	/* Need to disconnect handlers before we unref the shell. */
a00a81
 	if (priv->signal_handler_ids != NULL) {
a00a81
 		GArray *array = priv->signal_handler_ids;
a00a81
diff --git a/shell/e-shell-window-private.h b/shell/e-shell-window-private.h
a00a81
index 0ef85d5..f761fb8 100644
a00a81
--- a/shell/e-shell-window-private.h
a00a81
+++ b/shell/e-shell-window-private.h
a00a81
@@ -90,11 +90,14 @@ struct _EShellWindowPrivate {
a00a81
 
a00a81
 	guint destroyed        : 1;  /* XXX Do we still need this? */
a00a81
 	guint safe_mode : 1;
a00a81
+	guint menubar_visible : 1;
a00a81
 	guint sidebar_visible : 1;
a00a81
 	guint switcher_visible : 1;
a00a81
 	guint taskbar_visible : 1;
a00a81
 	guint toolbar_visible : 1;
a00a81
 	guint is_main_instance : 1;
a00a81
+
a00a81
+	gulong delayed_menubar_show_id;
a00a81
 };
a00a81
 
a00a81
 void		e_shell_window_private_init	(EShellWindow *shell_window);
a00a81
diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c
a00a81
index 6d3b3c5..0fe229f 100644
a00a81
--- a/shell/e-shell-window.c
a00a81
+++ b/shell/e-shell-window.c
a00a81
@@ -38,6 +38,7 @@ enum {
a00a81
 	PROP_GEOMETRY,
a00a81
 	PROP_SAFE_MODE,
a00a81
 	PROP_SHELL,
a00a81
+	PROP_MENUBAR_VISIBLE,
a00a81
 	PROP_SIDEBAR_VISIBLE,
a00a81
 	PROP_SWITCHER_VISIBLE,
a00a81
 	PROP_TASKBAR_VISIBLE,
a00a81
@@ -322,6 +323,12 @@ shell_window_set_property (GObject *object,
a00a81
 				g_value_get_object (value));
a00a81
 			return;
a00a81
 
a00a81
+		case PROP_MENUBAR_VISIBLE:
a00a81
+			e_shell_window_set_menubar_visible (
a00a81
+				E_SHELL_WINDOW (object),
a00a81
+				g_value_get_boolean (value));
a00a81
+			return;
a00a81
+
a00a81
 		case PROP_SIDEBAR_VISIBLE:
a00a81
 			e_shell_window_set_sidebar_visible (
a00a81
 				E_SHELL_WINDOW (object),
a00a81
@@ -387,6 +394,12 @@ shell_window_get_property (GObject *object,
a00a81
 				E_SHELL_WINDOW (object)));
a00a81
 			return;
a00a81
 
a00a81
+		case PROP_MENUBAR_VISIBLE:
a00a81
+			g_value_set_boolean (
a00a81
+				value, e_shell_window_get_menubar_visible (
a00a81
+				E_SHELL_WINDOW (object)));
a00a81
+			return;
a00a81
+
a00a81
 		case PROP_SIDEBAR_VISIBLE:
a00a81
 			g_value_set_boolean (
a00a81
 				value, e_shell_window_get_sidebar_visible (
a00a81
@@ -507,6 +520,18 @@ shell_window_close_alert (EShellWindow *shell_window)
a00a81
 	}
a00a81
 }
a00a81
 
a00a81
+static void
a00a81
+shell_window_menubar_deactivate_cb (GtkWidget *main_menu,
a00a81
+				    gpointer user_data)
a00a81
+{
a00a81
+	EShellWindow *shell_window = user_data;
a00a81
+
a00a81
+	g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
a00a81
+
a00a81
+	if (!e_shell_window_get_menubar_visible (shell_window))
a00a81
+		gtk_widget_hide (main_menu);
a00a81
+}
a00a81
+
a00a81
 static GtkWidget *
a00a81
 shell_window_construct_menubar (EShellWindow *shell_window)
a00a81
 {
a00a81
@@ -514,7 +539,14 @@ shell_window_construct_menubar (EShellWindow *shell_window)
a00a81
 
a00a81
 	main_menu = e_shell_window_get_managed_widget (
a00a81
 		shell_window, "/main-menu");
a00a81
-	gtk_widget_show (main_menu);
a00a81
+
a00a81
+	g_signal_connect (main_menu, "deactivate",
a00a81
+		G_CALLBACK (shell_window_menubar_deactivate_cb), shell_window);
a00a81
+
a00a81
+	e_binding_bind_property (
a00a81
+		shell_window, "menubar-visible",
a00a81
+		main_menu, "visible",
a00a81
+		G_BINDING_SYNC_CREATE);
a00a81
 
a00a81
 	e_signal_connect_notify (
a00a81
 		shell_window, "notify::active-view",
a00a81
@@ -994,6 +1026,24 @@ e_shell_window_class_init (EShellWindowClass *class)
a00a81
 			G_PARAM_STATIC_STRINGS));
a00a81
 
a00a81
 	/**
a00a81
+	 * EShellWindow:menubar-visible
a00a81
+	 *
a00a81
+	 * Whether the shell window's menu bar is visible.
a00a81
+	 *
a00a81
+	 * Since: 3.24
a00a81
+	 **/
a00a81
+	g_object_class_install_property (
a00a81
+		object_class,
a00a81
+		PROP_MENUBAR_VISIBLE,
a00a81
+		g_param_spec_boolean (
a00a81
+			"menubar-visible",
a00a81
+			"Menubar Visible",
a00a81
+			"Whether the shell window's menu bar is visible",
a00a81
+			TRUE,
a00a81
+			G_PARAM_READWRITE |
a00a81
+			G_PARAM_STATIC_STRINGS));
a00a81
+
a00a81
+	/**
a00a81
 	 * EShellWindow:sidebar-visible
a00a81
 	 *
a00a81
 	 * Whether the shell window's side bar is visible.
a00a81
@@ -1565,6 +1615,47 @@ e_shell_window_add_action_group (EShellWindow *shell_window,
a00a81
 }
a00a81
 
a00a81
 /**
a00a81
+ * e_shell_window_get_menubar_visible:
a00a81
+ * @shell_window: an #EShellWindow
a00a81
+ *
a00a81
+ * Returns %TRUE if @shell_window's menu bar is visible.
a00a81
+ *
a00a81
+ * Returns: %TRUE is the menu bar is visible
a00a81
+ *
a00a81
+ * Since: 3.24
a00a81
+ **/
a00a81
+gboolean
a00a81
+e_shell_window_get_menubar_visible (EShellWindow *shell_window)
a00a81
+{
a00a81
+	g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), FALSE);
a00a81
+
a00a81
+	return shell_window->priv->menubar_visible;
a00a81
+}
a00a81
+
a00a81
+/**
a00a81
+ * e_shell_window_set_menubar_visible:
a00a81
+ * @shell_window: an #EShellWindow
a00a81
+ * @menubar_visible: whether the menu bar should be visible
a00a81
+ *
a00a81
+ * Makes @shell_window's menu bar visible or invisible.
a00a81
+ *
a00a81
+ * Since: 3.24
a00a81
+ **/
a00a81
+void
a00a81
+e_shell_window_set_menubar_visible (EShellWindow *shell_window,
a00a81
+				    gboolean menubar_visible)
a00a81
+{
a00a81
+	g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
a00a81
+
a00a81
+	if (shell_window->priv->menubar_visible == menubar_visible)
a00a81
+		return;
a00a81
+
a00a81
+	shell_window->priv->menubar_visible = menubar_visible;
a00a81
+
a00a81
+	g_object_notify (G_OBJECT (shell_window), "menubar-visible");
a00a81
+}
a00a81
+
a00a81
+/**
a00a81
  * e_shell_window_get_sidebar_visible:
a00a81
  * @shell_window: an #EShellWindow
a00a81
  *
a00a81
diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h
a00a81
index c67c1ea..1c6c9a5 100644
a00a81
--- a/shell/e-shell-window.h
a00a81
+++ b/shell/e-shell-window.h
a00a81
@@ -115,6 +115,11 @@ void		e_shell_window_set_safe_mode	(EShellWindow *shell_window,
a00a81
 						 gboolean safe_mode);
a00a81
 void		e_shell_window_add_action_group (EShellWindow *shell_window,
a00a81
 						 const gchar *group_name);
a00a81
+gboolean	e_shell_window_get_menubar_visible
a00a81
+						(EShellWindow *shell_window);
a00a81
+void		e_shell_window_set_menubar_visible
a00a81
+						(EShellWindow *shell_window,
a00a81
+						 gboolean menubar_visible);
a00a81
 gboolean	e_shell_window_get_sidebar_visible
a00a81
 						(EShellWindow *shell_window);
a00a81
 void		e_shell_window_set_sidebar_visible
a00a81
diff --git a/ui/evolution-shell.ui b/ui/evolution-shell.ui
a00a81
index bc7e349..9035fb2 100644
a00a81
--- a/ui/evolution-shell.ui
a00a81
+++ b/ui/evolution-shell.ui
a00a81
@@ -43,6 +43,7 @@
a00a81
       </menu>
a00a81
       <menu action='window-menu'/>
a00a81
       <menu action='layout-menu'>
a00a81
+        <menuitem action='show-menubar'/>
a00a81
         <menuitem action='show-toolbar'/>
a00a81
         <menuitem action='show-taskbar'/>
a00a81
         <menuitem action='show-sidebar'/>
a00a81
-- 
a00a81
cgit v0.12
a00a81