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