cd714cfe3db0c85409f203f7387639098e91018f
[debian/lxappearance.git] / src / main.c
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
10 #include <gtk/gtk.h>
11 #include <string.h>
12 #include <unistd.h>
13
14 #include <X11/X.h>
15 #include <X11/Xatom.h>
16 #include <X11/Xlib.h>
17 #include <gdk/gdkx.h>
18
19 #include "main-dlg-ui.h"
20 #include "demo.h"
21 #include "glade-support.h"
22
23 char tmp_rc_file[] = "/tmp/gtkrc-2.0-XXXXXX";
24 GtkWidget* main_dlg = NULL;
25
26 gboolean under_lxsession = FALSE; /* wether lxsession-xsettings daemon is active */
27
28 Atom lxsession_atom = 0;
29
30 static void check_lxsession()
31 {
32 lxsession_atom = XInternAtom( GDK_DISPLAY(), "_LXSESSION", True );
33 if( lxsession_atom != None )
34 {
35 XGrabServer( GDK_DISPLAY() );
36 if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
37 under_lxsession = TRUE;
38 XUngrabServer( GDK_DISPLAY() );
39 }
40 }
41
42 int main (int argc, char *argv[])
43 {
44 #ifdef ENABLE_NLS
45 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
46 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
47 textdomain (GETTEXT_PACKAGE);
48 #endif
49
50 if( argc >= 3 && strcmp( argv[1], "demo" ) == 0 )
51 {
52 char* files[] = { argv[3], NULL };
53 gtk_rc_set_default_files(files);
54
55 gtk_set_locale ();
56 gtk_init (&argc, &argv);
57
58 check_lxsession();
59 if( under_lxsession )
60 return 1;
61
62 show_demo( (GdkNativeWindow)atoi( argv[2] ) );
63 gtk_main();
64 return 0;
65 }
66
67 gtk_set_locale ();
68 gtk_init (&argc, &argv);
69
70 /* Dirty hack: check if we are under lxsession */
71 check_lxsession();
72
73 if( ! under_lxsession )
74 mkstemp( tmp_rc_file );
75
76 /* Dirty hack: "gtk-toolbar-style" is installed in class_init of GtkToolbar */
77 gtk_widget_destroy( gtk_toolbar_new() );
78
79 main_dlg = create_dlg ();
80 main_dlg_init( main_dlg );
81 gtk_window_set_icon_name( (GtkWindow*)main_dlg, GTK_STOCK_PREFERENCES );
82
83 gtk_main ();
84
85 if( ! under_lxsession )
86 unlink( tmp_rc_file );
87
88 return 0;
89 }
90