[gtk/wip/exalm/headerbar-title: 4/6] headerbar: Remove user-settable title
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/exalm/headerbar-title: 4/6] headerbar: Remove user-settable title
- Date: Fri, 1 May 2020 14:45:25 +0000 (UTC)
commit 4ad6bdb9426b1b6f4ea44e9f1f22656f3f45b930
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri May 1 04:04:08 2020 +0500
headerbar: Remove user-settable title
Use window title, or custom title widget if it's set. Remove 'title'
property.
Update demos and tests to set the title on the window instead of
headerbar.
.../constraint-editor/constraint-editor-window.ui | 1 -
demos/gtk-demo/constraints.c | 2 +-
demos/gtk-demo/constraints2.c | 2 +-
demos/gtk-demo/constraints3.c | 2 +-
demos/gtk-demo/fishbowl.c | 7 +-
demos/gtk-demo/font-features.ui | 2 +-
demos/gtk-demo/headerbar.c | 2 +-
demos/gtk-demo/main.c | 6 +-
demos/gtk-demo/main.ui | 1 -
demos/gtk-demo/modelbutton.ui | 2 +-
demos/gtk-demo/paint.c | 2 +-
demos/gtk-demo/password_entry.c | 2 +-
demos/gtk-demo/peg_solitaire.c | 3 +-
demos/gtk-demo/tagged_entry.c | 2 +-
demos/gtk-demo/themes.c | 4 +-
demos/gtk-demo/video_player.c | 1 -
demos/icon-browser/window.ui | 1 -
demos/node-editor/node-editor-window.ui | 6 -
docs/reference/gtk/gtk4-sections.txt | 2 -
docs/tools/widgets.c | 2 +-
examples/sunny.c | 2 -
gtk/gtkheaderbar.c | 142 ++++++++++-----------
gtk/gtkheaderbar.h | 5 -
gtk/gtkwindow.c | 62 ++-------
tests/dialog.ui | 2 +-
tests/gdkgears.c | 3 +-
tests/testheaderbar.c | 1 -
testsuite/a11y/headerbar.ui | 1 -
28 files changed, 99 insertions(+), 171 deletions(-)
---
diff --git a/demos/constraint-editor/constraint-editor-window.ui
b/demos/constraint-editor/constraint-editor-window.ui
index 0d2e72fcea..037de4bd33 100644
--- a/demos/constraint-editor/constraint-editor-window.ui
+++ b/demos/constraint-editor/constraint-editor-window.ui
@@ -9,7 +9,6 @@
<property name="default-height">768</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header">
- <property name="title" translatable="yes">GTK Constraint Editor</property>
<property name="show-title-buttons">1</property>
<child type="start">
<object class="GtkButton">
diff --git a/demos/gtk-demo/constraints.c b/demos/gtk-demo/constraints.c
index 6c6fc30dab..57c5554cc4 100644
--- a/demos/gtk-demo/constraints.c
+++ b/demos/gtk-demo/constraints.c
@@ -257,9 +257,9 @@ do_constraints (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
+ gtk_window_set_title (GTK_WINDOW (window), "Constraints");
header = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Constraints");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/constraints2.c b/demos/gtk-demo/constraints2.c
index beb9c19ba9..db8a75b88f 100644
--- a/demos/gtk-demo/constraints2.c
+++ b/demos/gtk-demo/constraints2.c
@@ -213,9 +213,9 @@ do_constraints2 (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
+ gtk_window_set_title (GTK_WINDOW (window), "Constraints");
header = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Constraints");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/constraints3.c b/demos/gtk-demo/constraints3.c
index ec384e88bd..2c7566b422 100644
--- a/demos/gtk-demo/constraints3.c
+++ b/demos/gtk-demo/constraints3.c
@@ -133,9 +133,9 @@ do_constraints3 (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
+ gtk_window_set_title (GTK_WINDOW (window), "Constraints");
header = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Constraints");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/fishbowl.c b/demos/gtk-demo/fishbowl.c
index e1da414751..3f49ad2f20 100644
--- a/demos/gtk-demo/fishbowl.c
+++ b/demos/gtk-demo/fishbowl.c
@@ -194,7 +194,7 @@ static void
set_widget_type (GtkFishbowl *fishbowl,
int widget_type_index)
{
- GtkWidget *window, *headerbar;
+ GtkWidget *window;
if (widget_type_index == selected_widget_type)
return;
@@ -205,9 +205,8 @@ set_widget_type (GtkFishbowl *fishbowl,
widget_types[selected_widget_type].create_func);
window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (fishbowl)));
- headerbar = gtk_window_get_titlebar (GTK_WINDOW (window));
- gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar),
- widget_types[selected_widget_type].name);
+ gtk_window_set_title (GTK_WINDOW (window),
+ widget_types[selected_widget_type].name);
}
void
diff --git a/demos/gtk-demo/font-features.ui b/demos/gtk-demo/font-features.ui
index d47c5eaf29..464baa0735 100644
--- a/demos/gtk-demo/font-features.ui
+++ b/demos/gtk-demo/font-features.ui
@@ -4,10 +4,10 @@
<object class="GtkWindow" id="window">
<property name="default-width">600</property>
<property name="default-height">500</property>
+ <property name="title">Font Explorer</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">1</property>
- <property name="title">Font Explorer</property>
<child>
<object class="GtkButton" id="reset">
<property name="receives-default">1</property>
diff --git a/demos/gtk-demo/headerbar.c b/demos/gtk-demo/headerbar.c
index 3002504dba..070bb8fa70 100644
--- a/demos/gtk-demo/headerbar.c
+++ b/demos/gtk-demo/headerbar.c
@@ -24,13 +24,13 @@ do_headerbar (GtkWidget *do_widget)
{
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
+ gtk_window_set_title (GTK_WINDOW (window), "Welcome to Facebook - Log in, sign up or learn more");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
header = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Welcome to Facebook - Log in, sign up or learn
more");
button = gtk_button_new ();
icon = g_themed_icon_new ("mail-send-receive-symbolic");
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index a31036d916..524221b915 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -17,7 +17,7 @@ static gchar *current_file = NULL;
static GtkWidget *notebook;
static GtkWidget *treeview;
-static GtkWidget *headerbar;
+static GtkWidget *toplevel;
enum {
NAME_COLUMN,
@@ -915,7 +915,7 @@ selection_cb (GtkTreeSelection *selection,
if (filename)
load_file (name, filename);
- gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), title);
+ gtk_window_set_title (GTK_WINDOW (toplevel), title);
g_free (name);
g_free (title);
@@ -1030,9 +1030,9 @@ activate (GApplication *app)
info_view = (GtkWidget *)gtk_builder_get_object (builder, "info-textview");
source_view = (GtkWidget *)gtk_builder_get_object (builder, "source-textview");
- headerbar = (GtkWidget *)gtk_builder_get_object (builder, "headerbar");
treeview = (GtkWidget *)gtk_builder_get_object (builder, "treeview");
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+ toplevel = GTK_WIDGET (window);
load_file (gtk_demos[0].name, gtk_demos[0].filename);
diff --git a/demos/gtk-demo/main.ui b/demos/gtk-demo/main.ui
index 5256095fc6..c605609c78 100644
--- a/demos/gtk-demo/main.ui
+++ b/demos/gtk-demo/main.ui
@@ -31,7 +31,6 @@
</style>
<property name="default-width">800</property>
<property name="default-height">600</property>
- <property name="title">GTK Demo</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
<property name="show-title-buttons">1</property>
diff --git a/demos/gtk-demo/modelbutton.ui b/demos/gtk-demo/modelbutton.ui
index 818de71309..5bfe1fab52 100644
--- a/demos/gtk-demo/modelbutton.ui
+++ b/demos/gtk-demo/modelbutton.ui
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
+ <property name="title" translatable="yes">Model Button</property>
<property name="resizable">0</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">1</property>
- <property name="title" translatable="yes">Model Button</property>
</object>
</child>
<child>
diff --git a/demos/gtk-demo/paint.c b/demos/gtk-demo/paint.c
index cf5adc4743..f392ea2769 100644
--- a/demos/gtk-demo/paint.c
+++ b/demos/gtk-demo/paint.c
@@ -392,7 +392,6 @@ do_paint (GtkWidget *toplevel)
gtk_container_add (GTK_CONTAINER (window), draw_area);
headerbar = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), "Paint");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (headerbar), TRUE);
colorbutton = gtk_color_button_new ();
@@ -405,6 +404,7 @@ do_paint (GtkWidget *toplevel)
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), colorbutton);
gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
+ gtk_window_set_title (GTK_WINDOW (window), "Paint");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
diff --git a/demos/gtk-demo/password_entry.c b/demos/gtk-demo/password_entry.c
index 5d957ced43..56310d23a5 100644
--- a/demos/gtk-demo/password_entry.c
+++ b/demos/gtk-demo/password_entry.c
@@ -40,9 +40,9 @@ do_password_entry (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
header = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Choose a Password");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
+ gtk_window_set_title (GTK_WINDOW (window), "Choose a Password");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
gtk_window_set_deletable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/peg_solitaire.c b/demos/gtk-demo/peg_solitaire.c
index 2330ebfc01..f4f3fc4e26 100644
--- a/demos/gtk-demo/peg_solitaire.c
+++ b/demos/gtk-demo/peg_solitaire.c
@@ -276,13 +276,12 @@ do_peg_solitaire (GtkWidget *do_widget)
g_signal_connect (restart, "clicked", G_CALLBACK (restart), NULL);
header = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Peg Solitaire");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), restart);
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
- gtk_window_set_title (GTK_WINDOW (window), "Sliding Puzzle");
+ gtk_window_set_title (GTK_WINDOW (window), "Peg Solitaire");
gtk_window_set_titlebar (GTK_WINDOW (window), header);
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/tagged_entry.c b/demos/gtk-demo/tagged_entry.c
index 9a588c6c2b..c7b0816c4a 100644
--- a/demos/gtk-demo/tagged_entry.c
+++ b/demos/gtk-demo/tagged_entry.c
@@ -67,9 +67,9 @@ do_tagged_entry (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
header = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "A tagged entry");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
+ gtk_window_set_title (GTK_WINDOW (window), "A tagged entry");
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
gtk_window_set_deletable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
diff --git a/demos/gtk-demo/themes.c b/demos/gtk-demo/themes.c
index 0627ebe076..88191aa157 100644
--- a/demos/gtk-demo/themes.c
+++ b/demos/gtk-demo/themes.c
@@ -97,7 +97,6 @@ change_theme (GtkWidget *widget,
gpointer data)
{
GtkBuilder *builder = data;
- GtkWidget *header;
GtkWidget *label;
Theme next = themes[theme++ % G_N_ELEMENTS (themes)];
char *name;
@@ -107,9 +106,8 @@ change_theme (GtkWidget *widget,
"gtk-application-prefer-dark-theme", next.dark,
NULL);
- header = GTK_WIDGET (gtk_builder_get_object (builder, "header"));
name = g_strconcat (next.name, next.dark ? " (dark)" : NULL, NULL);
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), name);
+ gtk_window_set_title (GTK_WINDOW (widget), name);
g_free (name);
label = GTK_WIDGET (gtk_builder_get_object (builder, "fps"));
diff --git a/demos/gtk-demo/video_player.c b/demos/gtk-demo/video_player.c
index e06ad2fbb3..848c28ab48 100644
--- a/demos/gtk-demo/video_player.c
+++ b/demos/gtk-demo/video_player.c
@@ -75,7 +75,6 @@ do_video_player (GtkWidget *do_widget)
title = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (title), TRUE);
- gtk_header_bar_set_title (GTK_HEADER_BAR (title), "Video Player");
gtk_window_set_titlebar (GTK_WINDOW (window), title);
open_button = gtk_button_new_with_mnemonic ("_Open");
diff --git a/demos/icon-browser/window.ui b/demos/icon-browser/window.ui
index ffe6612f32..53767d6047 100644
--- a/demos/icon-browser/window.ui
+++ b/demos/icon-browser/window.ui
@@ -25,7 +25,6 @@
<property name="default-height">768</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header">
- <property name="title" translatable="yes">Icon Browser</property>
<property name="show-title-buttons">1</property>
<child type="title">
<object class="GtkBox">
diff --git a/demos/node-editor/node-editor-window.ui b/demos/node-editor/node-editor-window.ui
index 3707c9e2b6..3a8373a080 100644
--- a/demos/node-editor/node-editor-window.ui
+++ b/demos/node-editor/node-editor-window.ui
@@ -86,7 +86,6 @@
<property name="focus-widget">text_view</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header">
- <property name="title" translatable="yes">GTK Node Editor</property>
<property name="show-title-buttons">1</property>
<child type="start">
<object class="GtkButton">
@@ -120,11 +119,6 @@
<property name="popover">testcase_popover</property>
</object>
</child>
- <child type="title">
- <object class="GtkLabel">
- <property name="label" translatable="yes">GTK Node Editor</property>
- </object>
- </child>
</object>
</child>
<child>
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 007c17cd09..9aadbe1999 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5579,8 +5579,6 @@ gtk_action_bar_get_type
<TITLE>GtkHeaderBar</TITLE>
GtkHeaderBar
gtk_header_bar_new
-gtk_header_bar_set_title
-gtk_header_bar_get_title
gtk_header_bar_set_custom_title
gtk_header_bar_get_custom_title
gtk_header_bar_pack_start
diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c
index e6bae49e47..54019a76e1 100644
--- a/docs/tools/widgets.c
+++ b/docs/tools/widgets.c
@@ -1122,12 +1122,12 @@ create_headerbar (void)
GtkWidget *button;
window = gtk_window_new ();
+ gtk_window_set_title (GTK_WINDOW (bar), "Header Bar");
view = gtk_text_view_new ();
gtk_widget_show (view);
gtk_widget_set_size_request (window, 220, 150);
gtk_container_add (GTK_CONTAINER (window), view);
bar = gtk_header_bar_new ();
- gtk_header_bar_set_title (GTK_HEADER_BAR (bar), "Header Bar");
gtk_window_set_titlebar (GTK_WINDOW (window), bar);
button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (button), gtk_image_new_from_icon_name ("bookmark-new-symbolic"));
diff --git a/examples/sunny.c b/examples/sunny.c
index 3e3fc6a672..7aa4a9f89e 100644
--- a/examples/sunny.c
+++ b/examples/sunny.c
@@ -15,8 +15,6 @@ new_window (GApplication *app,
gtk_window_set_icon_name (GTK_WINDOW (window), "sunny");
header = gtk_header_bar_new ();
- gtk_widget_show (header);
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Sunny");
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index f27624c683..7aefc1cb20 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -45,10 +45,10 @@
* @See_also: #GtkBox, #GtkActionBar
*
* GtkHeaderBar is similar to a horizontal #GtkBox. It allows children to
- * be placed at the start or the end. In addition, it allows a title to be
- * displayed. The title will be centered with respect to the width of the
- * box, even if the children at either side take up different amounts of
- * space.
+ * be placed at the start or the end. In addition, it allows the window
+ * title to be displayed. The title will be centered with respect to the
+ * width of the box, even if the children at either side take up different
+ * amounts of space.
*
* GtkHeaderBar can add typical window frame controls, such as minimize,
* maximize and close buttons, or the window icon.
@@ -98,7 +98,6 @@ struct _GtkHeaderBarPrivate
GtkWidget *start_box;
GtkWidget *end_box;
- gchar *title;
GtkWidget *title_label;
GtkWidget *custom_title;
@@ -114,7 +113,6 @@ struct _GtkHeaderBarPrivate
enum {
PROP_0,
- PROP_TITLE,
PROP_CUSTOM_TITLE,
PROP_SHOW_TITLE_BUTTONS,
PROP_DECORATION_LAYOUT,
@@ -213,6 +211,33 @@ _gtk_header_bar_track_default_decoration (GtkHeaderBar *bar)
update_default_decoration (bar);
}
+static void
+update_title (GtkHeaderBar *bar)
+{
+ GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
+ GtkRoot *root;
+ const gchar *title = NULL;
+
+ if (!priv->title_label)
+ return;
+
+ root = gtk_widget_get_root (GTK_WIDGET (bar));
+
+ if (GTK_IS_WINDOW (root))
+ title = gtk_window_get_title (GTK_WINDOW (root));
+
+ if (!title)
+ title = g_get_application_name ();
+
+ if (!title)
+ title = g_get_prgname ();
+
+ if (!title)
+ title = "";
+
+ gtk_label_set_text (GTK_LABEL (priv->title_label), title);
+}
+
static void
construct_title_label (GtkHeaderBar *bar)
{
@@ -222,7 +247,7 @@ construct_title_label (GtkHeaderBar *bar)
g_assert (priv->title_label == NULL);
- label = gtk_label_new (priv->title);
+ label = gtk_label_new (NULL);
gtk_widget_add_css_class (label, GTK_STYLE_CLASS_TITLE);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_label_set_wrap (GTK_LABEL (label), FALSE);
@@ -234,57 +259,8 @@ construct_title_label (GtkHeaderBar *bar)
gtk_center_layout_set_center_widget (GTK_CENTER_LAYOUT (layout), label);
priv->title_label = label;
-}
-/**
- * gtk_header_bar_set_title:
- * @bar: a #GtkHeaderBar
- * @title: (allow-none): a title, or %NULL
- *
- * Sets the title of the #GtkHeaderBar. The title should help a user
- * identify the current view. A good title should not include the
- * application name.
- */
-void
-gtk_header_bar_set_title (GtkHeaderBar *bar,
- const gchar *title)
-{
- GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
- gchar *new_title;
-
- g_return_if_fail (GTK_IS_HEADER_BAR (bar));
-
- new_title = g_strdup (title);
- g_free (priv->title);
- priv->title = new_title;
-
- if (priv->title_label != NULL)
- {
- gtk_label_set_label (GTK_LABEL (priv->title_label), priv->title);
- gtk_widget_queue_resize (GTK_WIDGET (bar));
- }
-
- g_object_notify_by_pspec (G_OBJECT (bar), header_bar_props[PROP_TITLE]);
-}
-
-/**
- * gtk_header_bar_get_title:
- * @bar: a #GtkHeaderBar
- *
- * Retrieves the title of the header. See gtk_header_bar_set_title().
- *
- * Returns: (nullable): the title of the header, or %NULL if none has
- * been set explicitly. The returned string is owned by the widget
- * and must not be modified or freed.
- */
-const gchar *
-gtk_header_bar_get_title (GtkHeaderBar *bar)
-{
- GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
-
- g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), NULL);
-
- return priv->title;
+ update_title (bar);
}
/**
@@ -295,11 +271,10 @@ gtk_header_bar_get_title (GtkHeaderBar *bar)
* Sets a custom title for the #GtkHeaderBar.
*
* The title should help a user identify the current view. This
- * supersedes any title set by gtk_header_bar_set_title(). To
- * achieve the same style as the builtin title, use the “title”
- * style class.
+ * supersedes the window title label. To achieve the same style as
+ * the builtin title, use the “title” style class.
*
- * You should set the custom title to %NULL, for the header title
+ * You should set the custom title to %NULL, for the window title
* label to be visible again.
*/
void
@@ -363,6 +338,31 @@ gtk_header_bar_get_custom_title (GtkHeaderBar *bar)
return priv->custom_title;
}
+static void
+gtk_header_bar_root (GtkWidget *widget)
+{
+ GtkWidget *root;
+
+ GTK_WIDGET_CLASS (gtk_header_bar_parent_class)->root (widget);
+
+ root = GTK_WIDGET (gtk_widget_get_root (widget));
+
+ if (GTK_IS_WINDOW (root))
+ g_signal_connect_swapped (root, "notify::title",
+ G_CALLBACK (update_title), widget);
+
+ update_title (GTK_HEADER_BAR (widget));
+}
+
+static void
+gtk_header_bar_unroot (GtkWidget *widget)
+{
+ g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
+ update_title, widget);
+
+ GTK_WIDGET_CLASS (gtk_header_bar_parent_class)->unroot (widget);
+}
+
static void
gtk_header_bar_dispose (GObject *object)
{
@@ -382,7 +382,6 @@ gtk_header_bar_finalize (GObject *object)
{
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (object));
- g_free (priv->title);
g_free (priv->decoration_layout);
G_OBJECT_CLASS (gtk_header_bar_parent_class)->finalize (object);
@@ -399,10 +398,6 @@ gtk_header_bar_get_property (GObject *object,
switch (prop_id)
{
- case PROP_TITLE:
- g_value_set_string (value, priv->title);
- break;
-
case PROP_CUSTOM_TITLE:
g_value_set_object (value, priv->custom_title);
break;
@@ -431,10 +426,6 @@ gtk_header_bar_set_property (GObject *object,
switch (prop_id)
{
- case PROP_TITLE:
- gtk_header_bar_set_title (bar, g_value_get_string (value));
- break;
-
case PROP_CUSTOM_TITLE:
gtk_header_bar_set_custom_title (bar, g_value_get_object (value));
break;
@@ -575,18 +566,14 @@ gtk_header_bar_class_init (GtkHeaderBarClass *class)
object_class->get_property = gtk_header_bar_get_property;
object_class->set_property = gtk_header_bar_set_property;
+ widget_class->root = gtk_header_bar_root;
+ widget_class->unroot = gtk_header_bar_unroot;
+
container_class->add = gtk_header_bar_add;
container_class->remove = gtk_header_bar_remove;
container_class->forall = gtk_header_bar_forall;
container_class->child_type = gtk_header_bar_child_type;
- header_bar_props[PROP_TITLE] =
- g_param_spec_string ("title",
- P_("Title"),
- P_("The title to display"),
- NULL,
- G_PARAM_READWRITE);
-
header_bar_props[PROP_CUSTOM_TITLE] =
g_param_spec_object ("custom-title",
P_("Custom Title"),
@@ -641,7 +628,6 @@ gtk_header_bar_init (GtkHeaderBar *bar)
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
GtkLayoutManager *layout;
- priv->title = NULL;
priv->custom_title = NULL;
priv->decoration_layout = NULL;
priv->state = GDK_SURFACE_STATE_WITHDRAWN;
diff --git a/gtk/gtkheaderbar.h b/gtk/gtkheaderbar.h
index e7ff801b6f..3da4a96abe 100644
--- a/gtk/gtkheaderbar.h
+++ b/gtk/gtkheaderbar.h
@@ -38,11 +38,6 @@ GDK_AVAILABLE_IN_ALL
GType gtk_header_bar_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget *gtk_header_bar_new (void);
-GDK_AVAILABLE_IN_ALL
-void gtk_header_bar_set_title (GtkHeaderBar *bar,
- const gchar *title);
-GDK_AVAILABLE_IN_ALL
-const gchar *gtk_header_bar_get_title (GtkHeaderBar *bar);
GDK_AVAILABLE_IN_ALL
void gtk_header_bar_set_custom_title (GtkHeaderBar *bar,
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 91ca4fe393..518d9518f5 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2214,29 +2214,6 @@ gtk_window_new (void)
return g_object_new (GTK_TYPE_WINDOW, NULL);
}
-static void
-gtk_window_set_title_internal (GtkWindow *window,
- const gchar *title,
- gboolean update_titlebar)
-{
- GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
- char *new_title;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- new_title = g_strdup (title);
- g_free (priv->title);
- priv->title = new_title;
-
- if (_gtk_widget_get_realized (GTK_WIDGET (window)))
- gdk_toplevel_set_title (GDK_TOPLEVEL (priv->surface), new_title != NULL ? new_title : "");
-
- if (update_titlebar && GTK_IS_HEADER_BAR (priv->title_box))
- gtk_header_bar_set_title (GTK_HEADER_BAR (priv->title_box), new_title != NULL ? new_title : "");
-
- g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_TITLE]);
-}
-
/**
* gtk_window_set_title:
* @window: a #GtkWindow
@@ -2254,11 +2231,21 @@ gtk_window_set_title_internal (GtkWindow *window,
**/
void
gtk_window_set_title (GtkWindow *window,
- const gchar *title)
+ const gchar *title)
{
+ GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
+ char *new_title;
+
g_return_if_fail (GTK_IS_WINDOW (window));
- gtk_window_set_title_internal (window, title, TRUE);
+ new_title = g_strdup (title);
+ g_free (priv->title);
+ priv->title = new_title;
+
+ if (_gtk_widget_get_realized (GTK_WIDGET (window)))
+ gdk_toplevel_set_title (GDK_TOPLEVEL (priv->surface), new_title != NULL ? new_title : "");
+
+ g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_TITLE]);
}
/**
@@ -4100,21 +4087,6 @@ gtk_window_finalize (GObject *object)
G_OBJECT_CLASS (gtk_window_parent_class)->finalize (object);
}
-/* copied from gdksurface-x11.c */
-static const gchar *
-get_default_title (void)
-{
- const gchar *title;
-
- title = g_get_application_name ();
- if (!title)
- title = g_get_prgname ();
- if (!title)
- title = "";
-
- return title;
-}
-
static gboolean
update_csd_visibility (GtkWindow *window)
{
@@ -4151,14 +4123,8 @@ update_window_actions (GtkWindow *window)
static GtkWidget *
create_titlebar (GtkWindow *window)
{
- GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
- GtkWidget *titlebar;
-
- titlebar = gtk_header_bar_new ();
- g_object_set (titlebar,
- "title", priv->title ? priv->title : get_default_title (),
- "show-title-buttons", TRUE,
- NULL);
+ GtkWidget *titlebar = gtk_header_bar_new ();
+ gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (titlebar), TRUE);
gtk_widget_add_css_class (titlebar, GTK_STYLE_CLASS_TITLEBAR);
gtk_widget_add_css_class (titlebar, "default-decoration");
diff --git a/tests/dialog.ui b/tests/dialog.ui
index 040235670b..d2dab24f8c 100644
--- a/tests/dialog.ui
+++ b/tests/dialog.ui
@@ -16,9 +16,9 @@
<property name="type_hint">dialog</property>
<property name="default_width">500</property>
<property name="use_header_bar">1</property>
+ <property name="title" translatable="yes">Join Chat Room</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="titlebar">
- <property name="title" translatable="yes">Join Chat Room</property>
<child>
<object class="GtkButton" id="back_button">
<property name="visible">0</property>
diff --git a/tests/gdkgears.c b/tests/gdkgears.c
index 7eb650528a..6450d915cb 100644
--- a/tests/gdkgears.c
+++ b/tests/gdkgears.c
@@ -130,7 +130,8 @@ main (int argc, char *argv[])
gtk_init ();
window = gtk_window_new ();
- gtk_window_set_titlebar (GTK_WINDOW (window), g_object_new (GTK_TYPE_HEADER_BAR, "visible", TRUE, "title",
"GdkGears", NULL));
+ gtk_window_set_titlebar (GTK_WINDOW (window), gtk_header_bar_new ());
+ gtk_window_set_title (GTK_WINDOW (window), "GdkGears");
gtk_window_set_default_size (GTK_WINDOW (window), 640, 640);
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
diff --git a/tests/testheaderbar.c b/tests/testheaderbar.c
index 8c9c05c275..a065b01a23 100644
--- a/tests/testheaderbar.c
+++ b/tests/testheaderbar.c
@@ -95,7 +95,6 @@ change_header (GtkButton *button, gpointer data)
{
header = gtk_header_bar_new ();
gtk_widget_add_css_class (header, "titlebar");
- gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Example header");
widget = gtk_button_new_with_label ("_Close");
gtk_button_set_use_underline (GTK_BUTTON (widget), TRUE);
diff --git a/testsuite/a11y/headerbar.ui b/testsuite/a11y/headerbar.ui
index accbbdb0d3..86b49a94f4 100644
--- a/testsuite/a11y/headerbar.ui
+++ b/testsuite/a11y/headerbar.ui
@@ -2,7 +2,6 @@
<object class="GtkWindow" id="window1">
<child>
<object class="GtkHeaderBar" id="headerbar1">
- <property name="title">Title</property>
<child type="start">
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Yes</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]