Fix memory leaks and compiler warnings.
[lxde/lxappearance.git] / src / main.c
CommitLineData
f57233d5
HJYP
1/*
2 * Initial main.c file generated by Glade. Edit as required.
3 * Glade will not overwrite this file.
4 */
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9
850bd787
HJYP
10#include <libintl.h>
11
f57233d5 12#include <gtk/gtk.h>
a0647843 13#include <string.h>
da434a12 14#include <unistd.h>
850bd787 15#include <stdlib.h>
f57233d5 16
6b1f0c67
HJYP
17#include <X11/X.h>
18#include <X11/Xatom.h>
19#include <X11/Xlib.h>
20#include <gdk/gdkx.h>
21
850bd787 22#include "main-dlg.h"
a0647843 23#include "demo.h"
f57233d5 24
da434a12 25char tmp_rc_file[] = "/tmp/gtkrc-2.0-XXXXXX";
684d617e 26GtkWidget* main_dlg = NULL;
da434a12 27
bf6886d5 28gboolean under_lxsession = FALSE; /* wether lxsession-xsettings daemon is active */
6b1f0c67 29
bf6886d5
HJYP
30Atom lxsession_atom = 0;
31
32static void check_lxsession()
6b1f0c67 33{
bf6886d5
HJYP
34 lxsession_atom = XInternAtom( GDK_DISPLAY(), "_LXSESSION", True );
35 if( lxsession_atom != None )
6b1f0c67
HJYP
36 {
37 XGrabServer( GDK_DISPLAY() );
bf6886d5
HJYP
38 if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
39 under_lxsession = TRUE;
6b1f0c67
HJYP
40 XUngrabServer( GDK_DISPLAY() );
41 }
42}
43
a0647843
HJYP
44int main (int argc, char *argv[])
45{
f57233d5 46#ifdef ENABLE_NLS
a0647843
HJYP
47 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
48 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
49 textdomain (GETTEXT_PACKAGE);
f57233d5
HJYP
50#endif
51
a0647843
HJYP
52 if( argc >= 3 && strcmp( argv[1], "demo" ) == 0 )
53 {
8c98cd54
HJYP
54 char* files[] = { argv[3], NULL };
55 gtk_rc_set_default_files(files);
56
57 gtk_set_locale ();
58 gtk_init (&argc, &argv);
6b1f0c67 59
bf6886d5
HJYP
60 check_lxsession();
61 if( under_lxsession )
6b1f0c67
HJYP
62 return 1;
63
a0647843
HJYP
64 show_demo( (GdkNativeWindow)atoi( argv[2] ) );
65 gtk_main();
66 return 0;
67 }
f57233d5 68
8c98cd54
HJYP
69 gtk_set_locale ();
70 gtk_init (&argc, &argv);
71
bf6886d5
HJYP
72 /* Dirty hack: check if we are under lxsession */
73 check_lxsession();
6b1f0c67 74
bf6886d5 75 if( ! under_lxsession )
6b1f0c67
HJYP
76 mkstemp( tmp_rc_file );
77
a7477b61
HJYP
78 /* Dirty hack: "gtk-toolbar-style" is installed in class_init of GtkToolbar */
79 gtk_widget_destroy( gtk_toolbar_new() );
80
5ef7a66e 81 main_dlg = main_dlg_new();
129d4788 82 gtk_window_set_icon_name( (GtkWindow*)main_dlg, "preferences-desktop-theme" );
f57233d5 83
a0647843 84 gtk_main ();
da434a12 85
bf6886d5 86 if( ! under_lxsession )
6b1f0c67
HJYP
87 unlink( tmp_rc_file );
88
a0647843 89 return 0;
f57233d5
HJYP
90}
91