[gnome-terminal] app: Automatically determine if headerbars should be used
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] app: Automatically determine if headerbars should be used
- Date: Tue, 26 Feb 2019 21:08:15 +0000 (UTC)
commit 62c807a7433ae031085d69b9ead614e9ad14c5da
Author: Christian Persch <chpe src gnome org>
Date: Tue Feb 26 22:07:08 2019 +0100
app: Automatically determine if headerbars should be used
If the XDG_CURRENT_DESKTOP env var contains either GNOME or GNOME-Classic,
use headerbars, unless the user has explicitly set the pref.
NOTE! This makes it unnecessary for distributions to override the default
value of the headerbar pref.
src/org.gnome.Terminal.gschema.xml | 4 +--
src/terminal-app.c | 56 ++++++++++++++++++++++++++++++++++----
2 files changed, 52 insertions(+), 8 deletions(-)
---
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index b9ba2390..e4e0c003 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -744,8 +744,8 @@
when gnome-terminal-server is restarted.
-->
- <key name="headerbar" type="b">
- <default>false</default>
+ <key name="headerbar" type="mb">
+ <default>nothing</default>
</key>
<key name="unified-menu" type="b">
diff --git a/src/terminal-app.c b/src/terminal-app.c
index db1c4c36..832c3325 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -212,6 +212,55 @@ terminal_app_init_debug (void)
/* Helper functions */
+static gboolean
+strv_contains_gnome (char **strv)
+{
+ if (strv == NULL)
+ return FALSE;
+
+ for (int i = 0; strv[i] != NULL; i++) {
+ if (g_ascii_strcasecmp (strv[i], "gnome") == 0 ||
+ g_ascii_strcasecmp (strv[i], "gnome-classic") == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
+ * terminal_app_should_use_headerbar:
+ *
+ * Determines if the app should use headerbars. This is determined
+ * * If GNOME_TERMINAL_HEADERBAR env var is set, the app uses headerbars iff
+ * the value is 1
+ * * Otherwise, if the pref is set, the pref value is used
+ * * Otherwise, if XDG_CURRENT_DESKTOP contains GNOME or GNOME-Classic,
+ * headerbar is used
+ * * Otherwise, headerbar is not used.
+ */
+static gboolean
+terminal_app_should_use_headerbar (TerminalApp *app)
+{
+ const char *env = g_getenv("GNOME_TERMINAL_HEADERBAR");
+ if (env != NULL)
+ return g_strcmp0 (env, "1") == 0;
+
+ gboolean set, use;
+ g_settings_get (app->global_settings, TERMINAL_SETTING_HEADERBAR_KEY, "mb", &set, &use);
+ if (set)
+ return use;
+
+ const char *desktop = g_getenv ("XDG_CURRENT_DESKTOP");
+ if (desktop == NULL)
+ return FALSE;
+
+ char **desktops = g_strsplit (desktop, G_SEARCHPATH_SEPARATOR_S, -1);
+ use = strv_contains_gnome (desktops);
+ g_strfreev (desktops);
+
+ return use;
+}
+
static gboolean
load_css_from_resource (GApplication *application,
GtkCssProvider *provider,
@@ -788,12 +837,7 @@ terminal_app_init (TerminalApp *app)
* to override, so we cache them on startup and don't react to changes.
*/
app->unified_menu = g_settings_get_boolean (app->global_settings, TERMINAL_SETTING_UNIFIED_MENU_KEY);
-
- const char *env = g_getenv("GNOME_TERMINAL_HEADERBAR");
- if (env != NULL)
- app->use_headerbar = g_strcmp0 (env, "1") == 0;
- else
- app->use_headerbar = g_settings_get_boolean (app->global_settings, TERMINAL_SETTING_HEADERBAR_KEY);
+ app->use_headerbar = terminal_app_should_use_headerbar (app);
#if GTK_CHECK_VERSION (3, 19, 0)
GtkSettings *gtk_settings = gtk_settings_get_default ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]