Merging upstream version 0.4.0.
[debian/lxappearance.git] / src / main.c
CommitLineData
08024023
DB
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
c93a68c7
DB
10#include <libintl.h>
11
08024023
DB
12#include <gtk/gtk.h>
13#include <string.h>
14#include <unistd.h>
c93a68c7 15#include <stdlib.h>
08024023
DB
16
17#include <X11/X.h>
18#include <X11/Xatom.h>
19#include <X11/Xlib.h>
20#include <gdk/gdkx.h>
21
c93a68c7 22#include "main-dlg.h"
08024023 23#include "demo.h"
08024023
DB
24
25char tmp_rc_file[] = "/tmp/gtkrc-2.0-XXXXXX";
26GtkWidget* main_dlg = NULL;
27
8df2f63a 28gboolean under_lxsession = FALSE; /* wether lxsession-xsettings daemon is active */
08024023 29
8df2f63a
DB
30Atom lxsession_atom = 0;
31
32static void check_lxsession()
08024023 33{
8df2f63a
DB
34 lxsession_atom = XInternAtom( GDK_DISPLAY(), "_LXSESSION", True );
35 if( lxsession_atom != None )
08024023
DB
36 {
37 XGrabServer( GDK_DISPLAY() );
8df2f63a
DB
38 if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
39 under_lxsession = TRUE;
08024023
DB
40 XUngrabServer( GDK_DISPLAY() );
41 }
42}
43
44int 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
8df2f63a
DB
60 check_lxsession();
61 if( under_lxsession )
08024023
DB
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
8df2f63a
DB
72 /* Dirty hack: check if we are under lxsession */
73 check_lxsession();
08024023 74
8df2f63a 75 if( ! under_lxsession )
08024023
DB
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
c93a68c7
DB
81 main_dlg = main_dlg_new();
82 gtk_window_set_icon_name( (GtkWindow*)main_dlg, "preferences-desktop-theme" );
08024023
DB
83
84 gtk_main ();
85
8df2f63a 86 if( ! under_lxsession )
08024023
DB
87 unlink( tmp_rc_file );
88
89 return 0;
90}
91