testsplitheaders.c 2.19 KB
Newer Older
1 2 3
#include <gtk/gtk.h>

static void
Matthias Clasen's avatar
Matthias Clasen committed
4 5 6
split_decorations (GtkSettings *settings,
                   GParamSpec  *pspec,
                   GtkBuilder  *builder)
7 8 9 10 11
{
  GtkWidget *sheader, *mheader;
  gchar *layout, *p1, *p2;
  gchar **p;

Matthias Clasen's avatar
Matthias Clasen committed
12 13
  sheader = (GtkWidget *)gtk_builder_get_object (builder, "sidebar-header");
  mheader = (GtkWidget *)gtk_builder_get_object (builder, "main-header");
14

Matthias Clasen's avatar
Matthias Clasen committed
15
  g_object_get (settings, "gtk-decoration-layout", &layout, NULL);
16 17 18

  p = g_strsplit (layout, ":", -1);

19 20 21 22 23 24
  p1 = g_strconcat ("", p[0], ":", NULL);

  if (g_strv_length (p) >= 2)
    p2 = g_strconcat (":", p[1], NULL);
  else
    p2 = g_strdup ("");
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

  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");

Matthias Clasen's avatar
Matthias Clasen committed
49
  win = (GtkWidget *)gtk_builder_get_object (builder, "window");
50 51 52 53 54 55
  settings = gtk_widget_get_settings (win);

  g_signal_connect (settings, "notify::gtk-decoration-layout",
                    G_CALLBACK (split_decorations), builder);
  split_decorations (settings, NULL, builder);
  
Matthias Clasen's avatar
Matthias Clasen committed
56
  entry = (GtkWidget *)gtk_builder_get_object (builder, "layout-entry");
57 58 59
  g_object_bind_property (settings, "gtk-decoration-layout",
                          entry, "text",
                          G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);                      
Matthias Clasen's avatar
Matthias Clasen committed
60 61
  check = (GtkWidget *)gtk_builder_get_object (builder, "decorations");
  header = (GtkWidget *)gtk_builder_get_object (builder, "sidebar-header");
62 63 64
  g_object_bind_property (check, "active", 
                          header, "show-close-button",
			  G_BINDING_DEFAULT);                      
Matthias Clasen's avatar
Matthias Clasen committed
65
  header = (GtkWidget *)gtk_builder_get_object (builder, "main-header");
66 67 68 69 70 71 72 73 74
  g_object_bind_property (check, "active", 
                          header, "show-close-button",
			  G_BINDING_DEFAULT);                      
  gtk_window_present (GTK_WINDOW (win));

  gtk_main ();

  return 0;
}