Add an example for split headers

This shows how to deal with variability in window decorations
with split header bars.
This commit is contained in:
Matthias Clasen 2014-01-06 10:30:15 -05:00
parent f723113127
commit d28ca4cdce
3 changed files with 247 additions and 0 deletions

View File

@ -140,6 +140,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
teststack \
testrevealer \
testtitlebar \
testsplitheaders \
testwindowsize
if USE_X11
@ -515,6 +516,7 @@ EXTRA_DIST += \
merge-2.ui \
merge-3.ui \
gnome-textfile.png \
testsplitheaders.ui \
makefile.msc

71
tests/testsplitheaders.c Normal file
View File

@ -0,0 +1,71 @@
#include <gtk/gtk.h>
static void
split_decorations (GObject *obj,
GParamSpec *pspec,
gpointer data)
{
GtkBuilder *builder = data;
GtkWidget *sheader, *mheader;
gchar *layout, *p1, *p2;
gchar **p;
sheader = gtk_builder_get_object (builder, "sidebar-header");
mheader = gtk_builder_get_object (builder, "main-header");
g_object_get (obj, "gtk-decoration-layout", &layout, NULL);
p = g_strsplit (layout, ":", -1);
p1 = g_strconcat (p[0], ":", NULL);
p2 = g_strconcat (":", p[1], NULL);
gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (sheader), p1);
gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (mheader), p2);
g_free (p1);
g_free (p2);
g_strfreev (p);
g_free (layout);
}
int
main (int argc, char *argv[])
{
GtkBuilder *builder;
GtkSettings *settings;
GtkWidget *win;
GtkWidget *entry;
GtkWidget *check;
GtkWidget *header;
gtk_init (NULL, NULL);
builder = gtk_builder_new_from_file ("testsplitheaders.ui");
win = gtk_builder_get_object (builder, "window");
settings = gtk_widget_get_settings (win);
g_signal_connect (settings, "notify::gtk-decoration-layout",
G_CALLBACK (split_decorations), builder);
split_decorations (settings, NULL, builder);
entry = gtk_builder_get_object (builder, "layout-entry");
g_object_bind_property (settings, "gtk-decoration-layout",
entry, "text",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
check = gtk_builder_get_object (builder, "decorations");
header = gtk_builder_get_object (builder, "sidebar-header");
g_object_bind_property (check, "active",
header, "show-close-button",
G_BINDING_DEFAULT);
header = gtk_builder_get_object (builder, "main-header");
g_object_bind_property (check, "active",
header, "show-close-button",
G_BINDING_DEFAULT);
gtk_window_present (GTK_WINDOW (win));
gtk_main ();
return 0;
}

174
tests/testsplitheaders.ui Normal file
View File

@ -0,0 +1,174 @@
<interface>
<object class="GtkWindow" id="window">
<property name="default-width">600</property>
<property name="default-height">400</property>
<property name="icon-name">preferences-desktop-font</property>
<child type="titlebar">
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkHeaderBar" id="sidebar-header">
<property name="visible">True</property>
<child>
<object class="GtkCheckButton">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkHeaderBar" id="main-header">
<property name="visible">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<style>
<class name="linked"/>
</style>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="label">&lt;</property>
<property name="valign">center</property>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="label">&gt;</property>
<property name="valign">center</property>
</object>
</child>
</object>
<packing>
<property name="pack-type">start</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkListBox" id="sidebar-content">
<property name="visible">True</property>
<property name="selection-mode">none</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">Bla</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">Bla bla</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">Bla bla bla</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">Bla bla bla bla</property>
<property name="xalign">0</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="main-content">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar-policy">always</property>
<property name="vscrollbar-policy">always</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="margin">20</property>
<property name="row-spacing">10</property>
<property name="column-spacing">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">Layout</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="layout-entry">
<property name="visible">True</property>
<property name="width-chars">25</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">Decorations</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="decorations">
<property name="visible">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<object class="GtkSizeGroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="sidebar-header"/>
<widget name="sidebar-content"/>
</widgets>
</object>
<object class="GtkSizeGroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="main-header"/>
<widget name="main-content"/>
</widgets>
</object>
</interface>