/* xfce4-session-quit
 *
 * Copyright (c) 2004 Brian Tarricone, <bjt23@cornell.edu>
 *
 * You are hereby granted the right to do with this source code as you please,
 * provided that this copyright notice remains intact in any distribution
 * of the source code contained herein, in whole or in part.  This software is
 * distributed WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Furthermore, this software is distributed without any support whatsoever.
 * Any emails relating to it will be deleted, unless said email is simply
 * a thank-you for the quick crappy code I've written.
 */

/* to compile, run:
 * gcc -g -O2 -o xfce4-session-quit xfce4-session-quit.c `pkg-config libxfcegui4-1.0 --cflags --libs`
 * if it fails, it's your fault, not mine.
 */

#include <stdio.h>
#include <libxfcegui4/session-client.h>

static gboolean
quit(gpointer data)
{
	logout_session((SessionClient *)data);
	if(gtk_main_level())
		gtk_main_quit();
	return FALSE;
}

static void
die(gpointer client_data)
{
	if(gtk_main_level())
		gtk_main_quit();
} 

int
main(int argc, char **argv)
{
	SessionClient *sclient = NULL;
	gboolean is_managed = FALSE;

	gtk_init(&argc, &argv);
	
	sclient = client_session_new(argc, argv, NULL, SESSION_RESTART_NEVER, 40);
	sclient->die = die;
	is_managed = session_init(sclient);

	if(is_managed) {
		g_timeout_add(1000, (GSourceFunc)quit, sclient);
		gtk_main();
	} else
		fprintf(stderr, "X session is not session-managed\n");
	
	return 0;
}
