[gnome-terminal] window: Add headerbar infrastructure



commit 7b6226aea299160338e6ab4e386c5099e9066da1
Author: Christian Persch <chpe src gnome org>
Date:   Fri Nov 2 19:14:12 2018 +0100

    window: Add headerbar infrastructure
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756798

 po/POTFILES.in                     |   2 +
 src/Makefile.am                    |   3 +
 src/org.gnome.Terminal.gschema.xml |   8 +++
 src/terminal-app.c                 |  16 ++++-
 src/terminal-app.h                 |   2 +
 src/terminal-headerbar.c           | 135 +++++++++++++++++++++++++++++++++++++
 src/terminal-headerbar.h           |  40 +++++++++++
 src/terminal-headerbar.ui          |  24 +++++++
 src/terminal-schemas.h             |   3 +-
 src/terminal-window.c              |  14 +++-
 src/terminal.gresource.xml         |   1 +
 11 files changed, 242 insertions(+), 6 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fb4e696c..1aa950d8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,6 +13,8 @@ src/terminal-accels.c
 src/terminal-app.c
 src/terminal.c
 src/terminal-encoding.c
+[type: gettext/glade]src/terminal-headerbar.ui
+src/terminal-headerbar.c
 src/terminal-mdi-container.c
 [type: gettext/glade]src/terminal-menubar.ui.in
 src/terminal-menu-button.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f8f2c8e7..30b7cebd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,6 +53,8 @@ gnome_terminal_server_SOURCES = \
        terminal-encoding.h \
        terminal-gdbus.c \
        terminal-gdbus.h \
+       terminal-headerbar.c \
+       terminal-headerbar.h \
        terminal-icon-button.h \
        terminal-icon-button.c \
        terminal-info-bar.c \
@@ -325,6 +327,7 @@ CLEANFILES = \
 
 EXTRA_DIST = \
        terminal.about \
+       terminal-headerbar.ui \
        terminal-menubar.ui.in \
        terminal-notebook-menu.ui \
        terminal-window.ui \
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index 3e080806..fc1602f2 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -736,6 +736,14 @@
       <summary>Which theme variant to use</summary>
     </key>
 
+    <!-- Note that changing the following settings will only take effect
+         when gnome-terminal-server is restarted.
+    -->
+
+    <key name="headerbar" type="b">
+      <default>false</default>
+    </key>
+
     <key name="unified-menu" type="b">
       <default>true</default>
     </key>
diff --git a/src/terminal-app.c b/src/terminal-app.c
index be39e6e3..bb232e09 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -115,6 +115,7 @@ struct _TerminalApp
   int n_clipboard_targets;
 
   gboolean unified_menu;
+  gboolean use_headerbar;
 };
 
 enum
@@ -700,10 +701,11 @@ terminal_app_init (TerminalApp *app)
                                                      GTK_DEBUG_ENABLE_INSPECTOR_KEY,
                                                      GTK_DEBUG_ENABLE_INSPECTOR_TYPE);
 
-  /* This is an internal setting that exists only for distributions
-   * to override, so we cache it on startup and don't react to changes.
+  /* These are internal settings that exists only for distributions
+   * 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);
+  app->unified_menu = g_settings_get_boolean (app->global_settings, TERMINAL_SETTING_UNIFIED_MENU_KEY);
+  app->use_headerbar = g_settings_get_boolean (app->global_settings, TERMINAL_SETTING_HEADERBAR_KEY);
 
 #if GTK_CHECK_VERSION (3, 19, 0)
   GtkSettings *gtk_settings = gtk_settings_get_default ();
@@ -1162,3 +1164,11 @@ terminal_app_get_menu_unified (TerminalApp *app)
 
   return app->unified_menu;
 }
+
+gboolean
+terminal_app_get_use_headerbar (TerminalApp *app)
+{
+  g_return_val_if_fail (TERMINAL_IS_APP (app), FALSE);
+
+  return app->use_headerbar;
+}
diff --git a/src/terminal-app.h b/src/terminal-app.h
index efceda96..975b876c 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -105,6 +105,8 @@ GMenuModel *terminal_app_get_profile_section (TerminalApp *app);
 
 gboolean terminal_app_get_menu_unified (TerminalApp *app);
 
+gboolean terminal_app_get_use_headerbar (TerminalApp *app);
+
 /* GSettings */
 
 GSettings *terminal_app_get_global_settings (TerminalApp *app);
diff --git a/src/terminal-headerbar.c b/src/terminal-headerbar.c
new file mode 100644
index 00000000..58132e31
--- /dev/null
+++ b/src/terminal-headerbar.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright © 2018 Christian Persch
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "terminal-headerbar.h"
+#include "terminal-libgsystem.h"
+
+typedef struct _TerminalHeaderbarPrivate TerminalHeaderbarPrivate;
+
+struct _TerminalHeaderbar
+{
+  GtkHeaderBar parent_instance;
+};
+
+struct _TerminalHeaderbarClass
+{
+  GtkHeaderBarClass parent_class;
+};
+
+struct _TerminalHeaderbarPrivate
+{
+  gpointer dummy;
+};
+
+enum {
+  PROP_0,
+  LAST_PROP
+};
+
+enum {
+  LAST_SIGNAL
+};
+
+/* static guint signals[LAST_SIGNAL]; */
+/* static GParamSpec *pspecs[LAST_PROP]; */
+
+G_DEFINE_TYPE_WITH_PRIVATE (TerminalHeaderbar, terminal_headerbar, GTK_TYPE_HEADER_BAR)
+
+#define PRIV(obj) ((TerminalHeaderbarPrivate *) terminal_headerbar_get_instance_private ((TerminalHeaderbar 
*)(obj)))
+
+/* Class implementation */
+
+static void
+terminal_headerbar_init (TerminalHeaderbar *headerbar)
+{
+  //  TerminalHeaderbarPrivate *priv = PRIV (headerbar);
+  GtkWidget *widget = GTK_WIDGET (headerbar);
+
+  gtk_widget_init_template (widget);
+}
+
+static void
+terminal_headerbar_finalize (GObject *object)
+{
+#if 0
+  TerminalHeaderbar *headerbar = TERMINAL_HEADERBAR (object);
+  TerminalHeaderbarPrivate *priv = PRIV (headerbar);
+#endif
+
+  G_OBJECT_CLASS (terminal_headerbar_parent_class)->finalize (object);
+}
+
+static void
+terminal_headerbar_get_property (GObject *object,
+                                 guint prop_id,
+                                 GValue *value,
+                                 GParamSpec *pspec)
+{
+  //  TerminalHeaderbar *headerbar = TERMINAL_HEADERBAR (object);
+
+  switch (prop_id) {
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+terminal_headerbar_set_property (GObject *object,
+                                 guint prop_id,
+                                 const GValue *value,
+                                 GParamSpec *pspec)
+{
+  switch (prop_id) {
+  default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+terminal_headerbar_class_init (TerminalHeaderbarClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gobject_class->finalize = terminal_headerbar_finalize;
+  gobject_class->get_property = terminal_headerbar_get_property;
+  gobject_class->set_property = terminal_headerbar_set_property;
+
+  /* g_object_class_install_properties (gobject_class, G_N_ELEMENTS (pspecs), pspecs); */
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/terminal/ui/headerbar.ui");
+}
+
+/* public API */
+
+/**
+ * terminal_headerbar_new:
+ *
+ * Returns: a new #TerminalHeaderbar
+ */
+GtkWidget *
+terminal_headerbar_new (void)
+{
+  return g_object_new (TERMINAL_TYPE_HEADERBAR,
+                       NULL);
+}
diff --git a/src/terminal-headerbar.h b/src/terminal-headerbar.h
new file mode 100644
index 00000000..f4ee6f78
--- /dev/null
+++ b/src/terminal-headerbar.h
@@ -0,0 +1,40 @@
+/*
+ *  Copyright © 2018 Christian Persch
+ *
+ * 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/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "terminal-screen.h"
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_HEADERBAR         (terminal_headerbar_get_type ())
+#define TERMINAL_HEADERBAR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TERMINAL_TYPE_HEADERBAR, 
TerminalHeaderbar))
+#define TERMINAL_HEADERBAR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), TERMINAL_TYPE_HEADERBAR, 
TerminalHeaderbarClass))
+#define TERMINAL_IS_HEADERBAR(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TERMINAL_TYPE_HEADERBAR))
+#define TERMINAL_IS_HEADERBAR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TERMINAL_TYPE_HEADERBAR))
+#define TERMINAL_HEADERBAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TERMINAL_TYPE_HEADERBAR, 
TerminalHeaderbarClass))
+
+typedef struct _TerminalHeaderbar        TerminalHeaderbar;
+typedef struct _TerminalHeaderbarClass   TerminalHeaderbarClass;
+
+GType      terminal_headerbar_get_type (void);
+
+GtkWidget *terminal_headerbar_new      (void);
+
+G_END_DECLS
diff --git a/src/terminal-headerbar.ui b/src/terminal-headerbar.ui
new file mode 100644
index 00000000..3f8c5965
--- /dev/null
+++ b/src/terminal-headerbar.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright © 2018 Christian Persch
+
+  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, or (at your option)
+  any later version.
+
+  This program is distributed in the hope conf 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/>.
+-->
+<interface>
+  <template class="TerminalHeaderbar" parent="GtkHeaderBar">
+    <property name="can-focus">False</property>
+    <property name="visible">True</property>
+    <property name="show-close-button">True</property>
+  </template>
+</interface>
diff --git a/src/terminal-schemas.h b/src/terminal-schemas.h
index 5b0d8c3e..ef30bd59 100644
--- a/src/terminal-schemas.h
+++ b/src/terminal-schemas.h
@@ -78,13 +78,14 @@ G_BEGIN_DECLS
 #define TERMINAL_SETTING_ENABLE_MENU_BAR_ACCEL_KEY      "menu-accelerator-enabled"
 #define TERMINAL_SETTING_ENABLE_MNEMONICS_KEY           "mnemonics-enabled"
 #define TERMINAL_SETTING_ENABLE_SHORTCUTS_KEY           "shortcuts-enabled"
+#define TERMINAL_SETTING_HEADERBAR_KEY                  "headerbar"
 #define TERMINAL_SETTING_NEW_TERMINAL_MODE_KEY          "new-terminal-mode"
 #define TERMINAL_SETTING_SCHEMA_VERSION                 "schema-version"
 #define TERMINAL_SETTING_SHELL_INTEGRATION_KEY          "shell-integration-enabled"
 #define TERMINAL_SETTING_TAB_POLICY_KEY                 "tab-policy"
 #define TERMINAL_SETTING_TAB_POSITION_KEY               "tab-position"
 #define TERMINAL_SETTING_THEME_VARIANT_KEY              "theme-variant"
-#define TERMINAL_SETTING_UNIFIED_MENU                   "unified-menu"
+#define TERMINAL_SETTING_UNIFIED_MENU_KEY               "unified-menu"
 
 #define TERMINAL_SETTINGS_LIST_LIST_KEY                 "list"
 #define TERMINAL_SETTINGS_LIST_DEFAULT_KEY              "default"
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 4ed36474..dc653fc0 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -32,6 +32,7 @@
 #include "terminal-debug.h"
 #include "terminal-enums.h"
 #include "terminal-encoding.h"
+#include "terminal-headerbar.h"
 #include "terminal-icon-button.h"
 #include "terminal-intl.h"
 #include "terminal-mdi-container.h"
@@ -2094,6 +2095,7 @@ terminal_window_init (TerminalWindow *window)
   uuid_t u;
   char uuidstr[37], role[64];
   gboolean shell_shows_menubar;
+  gboolean use_headerbar;
   GSimpleAction *action;
 
   app = terminal_app_get ();
@@ -2117,6 +2119,14 @@ terminal_window_init (TerminalWindow *window)
     }
 #endif
 
+  use_headerbar = terminal_app_get_use_headerbar (app);
+  if (use_headerbar) {
+    GtkWidget *headerbar;
+
+    headerbar = terminal_headerbar_new ();
+    gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
+  }
+
   gtk_window_set_title (GTK_WINDOW (window), _("Terminal"));
 
   priv->active_screen = NULL;
@@ -2191,8 +2201,8 @@ terminal_window_init (TerminalWindow *window)
                         priv->menubar,
                         FALSE, FALSE, 0);
 
-    terminal_window_set_menubar_visible (window, TRUE);
-    priv->use_default_menubar_visibility = TRUE;
+    terminal_window_set_menubar_visible (window, !use_headerbar);
+    priv->use_default_menubar_visibility = !use_headerbar;
   }
 
   /* Maybe make Inspector available */
diff --git a/src/terminal.gresource.xml b/src/terminal.gresource.xml
index f408877f..ba26f3c8 100644
--- a/src/terminal.gresource.xml
+++ b/src/terminal.gresource.xml
@@ -18,6 +18,7 @@
 <gresources>
   <gresource prefix="/org/gnome/terminal">
     <file alias="css/terminal.css" compressed="true">terminal.common.css</file>
+    <file alias="ui/headerbar.ui" compressed="true" preprocess="xml-stripblanks">terminal-headerbar.ui</file>
     <file alias="ui/menubar-with-mnemonics.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-menubar-with-mnemonics.ui</file>
     <file alias="ui/menubar-without-mnemonics.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-menubar-without-mnemonics.ui</file>
     <file alias="ui/notebook-menu.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-notebook-menu.ui</file>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]