diff -urN glade3/src/glade-project-window.c glade3-session/src/glade-project-window.c
--- glade3/src/glade-project-window.c	2004-05-08 17:01:30.000000000 -0300
+++ glade3-session/src/glade-project-window.c	2004-05-12 14:30:06.000000000 -0300
@@ -41,6 +41,7 @@
 #include "glade-project-window.h"
 #include "glade-placeholder.h"
 #include "glade-command.h"
+#include "glade-session.h"
 #include "glade-debug.h"
 #include "glade-utils.h"
 #include <gdk/gdkkeysyms.h>
@@ -403,6 +404,8 @@
 		}
 	}
 
+	glade_session_save ();
+
 	gtk_main_quit ();
 }
 
@@ -547,8 +550,6 @@
 static void
 gpw_create_palette (GladeProjectWindow *gpw)
 {
-	GtkWidget *palette_item;
-
 	g_return_if_fail (gpw != NULL);
 
 	gpw->palette_window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
@@ -567,10 +568,6 @@
 
 	g_signal_connect (G_OBJECT (gpw->palette), "toggled",
 			  G_CALLBACK (gpw_palette_button_clicked), NULL);
-
-	palette_item = gtk_item_factory_get_item (gpw->item_factory,
-						  "<main>/View/Palette");
-	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (palette_item), TRUE);
 }
 
 static void
@@ -623,8 +620,6 @@
 static void
 gpw_create_editor (GladeProjectWindow *gpw)
 {
-	GtkWidget *editor_item;
-
 	g_return_if_fail (gpw != NULL);
 
 	if (gpw->editor != NULL)
@@ -643,9 +638,6 @@
 	g_signal_connect (G_OBJECT (gpw->editor_window), "delete_event",
 			  G_CALLBACK (gpw_hide_editor_on_delete), gpw->item_factory);
 
-	editor_item = gtk_item_factory_get_item (gpw->item_factory,
-						 "<main>/View/Property Editor");
-	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (editor_item), TRUE);
 }
 
 static void
@@ -696,12 +688,11 @@
 	return TRUE;
 }
 
-static GtkWidget* 
+static void 
 gpw_create_widget_tree (GladeProjectWindow *gpw)
 {
 	GtkWidget *widget_tree;
 	GladeProjectView *view;
-	GtkWidget *widget_tree_item;
 
 	widget_tree = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 	gtk_window_set_default_size (GTK_WINDOW (widget_tree), 230, 300);
@@ -719,23 +710,16 @@
 	g_signal_connect (G_OBJECT (widget_tree), "delete_event",
 			  G_CALLBACK (gpw_hide_widget_tree_on_delete), gpw->item_factory);
 
-	widget_tree_item = gtk_item_factory_get_item (gpw->item_factory,
-						      "<main>/View/Widget Tree");
-	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget_tree_item), TRUE);
-
-	return widget_tree;
+	gpw->widget_tree = widget_tree;
 }
 
-static void 
+void 
 gpw_show_widget_tree (GladeProjectWindow *gpw) 
 {
 	GtkWidget *widget_tree_item;
 
 	g_return_if_fail (gpw != NULL);
 
-	if (gpw->widget_tree == NULL)
-		gpw->widget_tree = gpw_create_widget_tree (gpw);
-
 	gtk_widget_show_all (gpw->widget_tree);
 
 	widget_tree_item = gtk_item_factory_get_item (gpw->item_factory,
@@ -792,7 +776,6 @@
 gpw_create_clipboard_view (GladeProjectWindow *gpw)
 {
 	GtkWidget *view;
-	GtkWidget *clipboard_item;
 
 	gpw_create_clipboard (gpw);
 	
@@ -802,10 +785,6 @@
 			  G_CALLBACK (gpw_hide_clipboard_view_on_delete),
 			  gpw->item_factory);
 	gpw->clipboard->view = view;
-
-	clipboard_item = gtk_item_factory_get_item (gpw->item_factory,
-						    "<main>/View/Clipboard");
-	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (clipboard_item), TRUE);
 }
 
 static void
@@ -1255,7 +1234,10 @@
 	glade_project_window_create (gpw);
 	gpw_create_palette (gpw);
 	gpw_create_editor  (gpw);
-	gpw_create_clipboard (gpw);
+	gpw_create_widget_tree (gpw);
+	gpw_create_clipboard_view (gpw);
+
+	glade_session_restore ();
 
 	return gpw;
 }
@@ -1470,7 +1452,5 @@
 	gpw = glade_project_window_get ();
 
 	gtk_widget_show_all (gpw->window);
-	gpw_show_palette (gpw);
-	gpw_show_editor (gpw);
 }
 
diff -urN glade3/src/glade-project-window.h glade3-session/src/glade-project-window.h
--- glade3/src/glade-project-window.h	2004-02-11 11:37:07.000000000 -0200
+++ glade3-session/src/glade-project-window.h	2004-05-12 13:01:09.000000000 -0300
@@ -60,6 +60,8 @@
 
 void glade_project_window_refresh_undo_redo (void);
 
+void 
+gpw_show_widget_tree (GladeProjectWindow *gpw) ;
 
 G_END_DECLS
 
diff -urN glade3/src/glade-session.c glade3-session/src/glade-session.c
--- glade3/src/glade-session.c	1969-12-31 21:00:00.000000000 -0300
+++ glade3-session/src/glade-session.c	2004-05-12 15:03:10.000000000 -0300
@@ -0,0 +1,362 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2004 The GNOME Foundation
+ *
+ * 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 2 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Paolo Borelli
+ *   Gustavo Noronha Silva
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <libxml/tree.h>
+
+#include "glade.h"
+#include "glade-project-window.h"
+#include "glade-clipboard.h"
+#include "glade-session.h"
+
+static int
+write_window_geometry (FILE *file,
+		       GtkWindow *window,
+		       const char *id)
+{
+	int x = 0, y = 0;
+	int width = 0, height = 0;
+	int ret;
+
+	/* get window geometry */
+	gtk_window_get_size (window, &width, &height);
+	gtk_window_get_position (window, &x, &y);
+
+	ret = fprintf(file, 
+		      "\t<window id=\"%s\" visible=\"%d\" x=\"%d\" y=\"%d\" "
+		      "width=\"%d\" height=\"%d\"/>\n", 
+		      id, GTK_WIDGET_VISIBLE(window), x, y, width, height);
+
+	return ret;
+}
+
+static int
+glade_session_write_geometry (FILE *file)
+{
+	GladeProjectWindow *gpw;
+	int ret;
+
+	gpw = glade_project_window_get ();
+
+	/* project window */
+	ret = write_window_geometry (file, GTK_WINDOW (gpw->window), 
+				     "project-window");
+	if (ret < 0)
+		return ret;
+
+	/* palette */
+	ret = write_window_geometry (file, gpw->palette_window, 
+				     "palette");
+	if (ret < 0)
+		return ret;
+
+	/* editor */
+	ret = write_window_geometry (file, gpw->editor_window, 
+				     "editor");
+	if (ret < 0)
+		return ret;
+
+	/* widget tree */
+	ret = write_window_geometry (file, GTK_WINDOW (gpw->widget_tree), 
+				     "widget-tree");
+	if (ret < 0)
+		return ret;
+
+	/* clipboard */
+	ret = write_window_geometry (file, GTK_WINDOW (gpw->clipboard->view), 
+				     "clipboard");
+
+	return ret;
+}
+
+static gboolean
+switch_temp_file (const char *filename,
+		  const char *filename_temp)
+{
+	char *old_file;
+	gboolean old_exist;
+	gboolean retval = TRUE;
+
+	old_file = g_strconcat (filename, ".old", NULL);
+
+	old_exist = g_file_test (filename, G_FILE_TEST_EXISTS);
+
+	if (old_exist)
+	{
+		if (rename (filename, old_file) < 0)
+		{
+			g_warning ("Failed to rename %s to %s", filename, old_file);
+			retval = FALSE;
+			goto failed;
+		}
+	}
+
+	if (rename (filename_temp, filename) < 0)
+	{
+		g_warning ("Failed to rename %s to %s", filename_temp, filename);
+
+		if (rename (old_file, filename) < 0)
+		{
+			g_warning ("Failed to restore %s from %s",
+				   filename, filename_temp);
+		}
+		retval = FALSE;
+		goto failed;
+	}
+
+	if (old_exist)
+	{
+		if (unlink (old_file) < 0)
+		{
+			g_warning ("Failed to delete old file %s", old_file);
+		}
+	}
+
+failed:
+	g_free (old_file);
+
+	return retval;
+}
+
+#define GLADE_RCDIR "/.glade"
+#define SESSION_FILE "/session"
+
+void
+glade_session_save (void)
+{
+	FILE *file = NULL;
+	char *tmp_file = NULL;
+	char *glade_rcdir = NULL;
+	char *session_file = NULL;
+	int ret;
+
+	glade_rcdir = g_strconcat (g_get_home_dir (), GLADE_RCDIR, NULL);
+	session_file = g_strconcat (glade_rcdir, SESSION_FILE, NULL);
+	tmp_file = g_strconcat (session_file, ".tmp", NULL);
+
+	if (!g_file_test (glade_rcdir, G_FILE_TEST_EXISTS)) 
+	{
+		if (mkdir (glade_rcdir, 0777) == -1)
+			goto out;
+	}
+
+	file = fopen (tmp_file, "w");
+	if (!file) 
+        {
+		g_warning ("Failed to create temporary file: %s",
+			   tmp_file);
+		goto out;
+	}
+
+	fprintf (file, 
+		 "<?xml version=\"1.0\"?>\n"
+		 "<session>\n");
+
+	/* save positions and size of gui elements */
+	ret = glade_session_write_geometry (file);
+	if (ret < 0) 
+        {
+		g_warning ("Failed to write session information.");
+		goto out;
+	}
+
+	fprintf (file, "</session>\n");
+
+	if (ret >= 0)
+		switch_temp_file (session_file, tmp_file);
+
+out:
+	if (file)
+		fclose (file);
+	unlink (tmp_file);
+	g_free (tmp_file);
+	g_free (session_file);
+
+	return;
+}
+
+/* 
+   returns TRUE if the window should be visible, FALSE if not
+   and -1 if 'window' is not a GtkWindow
+*/
+static gboolean
+restore_window_geometry (xmlNodePtr child, GtkWidget *window)
+{
+	xmlChar *tmp;
+	int x = -1;
+	int y = -1;
+	int width = -1;
+	int height = -1;
+	gint visible = 1;
+
+	g_return_val_if_fail (GTK_IS_WINDOW (window), -1);
+
+	tmp = xmlGetProp (child, "x");
+	if (tmp)
+	{
+		sscanf (tmp, "%d", &x);
+		g_free (tmp);
+	}
+	
+	tmp = xmlGetProp (child, "y");
+	if (tmp)
+	{
+        	sscanf (tmp, "%d", &y);
+        	g_free (tmp);
+	}
+	
+	if (x >= 0 && y >= 0)
+		gtk_window_move (GTK_WINDOW (window), x, y);
+	
+	tmp = xmlGetProp (child, "width");
+	if (tmp)
+	{
+        	sscanf (tmp, "%d", &width);
+        	g_free (tmp);
+	}
+	
+	tmp = xmlGetProp (child, "height");
+	if (tmp)
+	{
+        	sscanf (tmp, "%d", &height);
+        	g_free (tmp);
+	}
+	
+	if (width >= 0 && height >= 0)
+		gtk_window_resize (GTK_WINDOW (window), width, height);
+	
+	tmp = xmlGetProp (child, "visible");
+	if (tmp)
+	{
+        	sscanf (tmp, "%d", &visible);
+        	g_free (tmp);
+	}
+	
+	return visible;
+}
+
+void
+glade_session_restore (void)
+{
+	GladeProjectWindow *gpw;
+	xmlDocPtr doc;
+        xmlNodePtr child;
+	char *session_file;
+
+	gpw = glade_project_window_get ();
+
+	session_file = g_strconcat (g_get_home_dir (), GLADE_RCDIR, 
+				    SESSION_FILE, NULL);
+	doc = xmlParseFile (session_file);
+	g_free (session_file);
+
+	/*
+	  Show the palette and the editor at the first time the user runs
+	  glade or if the session file is unreadable
+	*/
+	if (!doc)
+	{
+		GtkWidget *item;
+
+		item = gtk_item_factory_get_item (gpw->item_factory, 
+						  "<main>/View/Palette");
+		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+		item = gtk_item_factory_get_item (gpw->item_factory, 
+						  "<main>/View/Property Editor");
+		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+		return;
+	}
+
+	child = xmlDocGetRootElement (doc);
+
+	for (child = child->children; child; child = child->next)
+	{
+		xmlChar *id;
+		gboolean visible;
+
+		if (!xmlStrEqual (child->name, "window"))
+			continue;
+
+		id = xmlGetProp (child, "id");
+
+		if (id && xmlStrEqual ("project-window", id))
+			restore_window_geometry (child, gpw->window);
+		else if (id && xmlStrEqual ("palette", id))
+		{
+			GtkWidget *palette_item;
+
+			palette_item = gtk_item_factory_get_item (gpw->item_factory, 
+								  "<main>/View/Palette");
+			visible = restore_window_geometry (child, 
+							   GTK_WIDGET(gpw->palette_window));
+			if (visible != -1)
+				gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (palette_item), 
+								visible);
+		}
+		else if (id && xmlStrEqual ("editor", id))
+		{
+			GtkWidget *editor_item;
+
+			editor_item = gtk_item_factory_get_item (gpw->item_factory, 
+								 "<main>/View/Property Editor");
+			visible = restore_window_geometry (child, 
+							   GTK_WIDGET(gpw->editor_window));
+			if (visible != -1)
+				gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (editor_item), 
+								visible);
+		}
+		else if (id && xmlStrEqual ("widget-tree", id))
+		{
+			GtkWidget *widget_tree_item;
+
+			widget_tree_item = gtk_item_factory_get_item (gpw->item_factory,
+								      "<main>/View/Widget Tree");
+
+			visible = restore_window_geometry (child, gpw->widget_tree);
+			if (visible != -1)
+				gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget_tree_item),
+								visible);
+		}
+		else if (id && xmlStrEqual ("clipboard", id))
+		{
+			GtkWidget *clipboard_item;
+
+			clipboard_item = gtk_item_factory_get_item (gpw->item_factory,
+								    "<main>/View/Clipboard");
+
+			visible = restore_window_geometry (child, gpw->clipboard->view);
+			if (visible != -1)
+				gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (clipboard_item),
+								visible);
+		}
+	}
+
+	xmlFreeDoc (doc);
+}
+
diff -urN glade3/src/glade-session.h glade3-session/src/glade-session.h
--- glade3/src/glade-session.h	1969-12-31 21:00:00.000000000 -0300
+++ glade3-session/src/glade-session.h	2004-05-11 21:27:36.000000000 -0300
@@ -0,0 +1,15 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef __GLADE_SESSION_H__
+#define __GLADE_SESSION_H__
+
+G_BEGIN_DECLS
+
+
+void glade_session_save (void);
+
+void glade_session_restore (void);
+
+
+G_END_DECLS
+
+#endif /* __GLADE_SESSION_H__ */
diff -urN glade3/src/Makefile.am glade3-session/src/Makefile.am
--- glade3/src/Makefile.am	2004-04-22 19:17:19.000000000 -0300
+++ glade3-session/src/Makefile.am	2004-05-11 21:28:19.000000000 -0300
@@ -35,6 +35,7 @@
 	glade-placeholder.c \
 	glade-project-view.c \
 	glade-project-window.c \
+	glade-session.c \
 	glade-widget-class.c \
 	glade-xml-utils.c \
 	glade-palette.c \
@@ -70,6 +71,7 @@
 	glade-palette.h \
 	glade-cursor.h \
 	glade-project-window.h \
+	glade-session.h \
 	glade-types.h \
 	glade-widget.h \
 	glade-widget-class.h \
