]> icculus.org git repositories - dana/obconf.git/blob - src/main.c
add obconf.gladep tht glade makes
[dana/obconf.git] / src / main.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    main.c for ObConf, the configuration tool for Openbox
4    Copyright (c) 2003-2007   Dana Jansens
5    Copyright (c) 2003        Tim Riley
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "main.h"
21 #include "handlers.h"
22
23 #include <gdk/gdkx.h>
24 #define SN_API_NOT_YET_FROZEN
25 #include <libsn/sn.h>
26 #undef SN_API_NOT_YET_FROZEN
27
28 static GtkWidget *mainwin;
29
30 GladeXML *glade;
31 xmlDocPtr doc;
32 xmlNodePtr root;
33
34 void obconf_error(gchar *msg)
35 {
36     GtkWidget *d;
37
38     d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
39                                GTK_DIALOG_DESTROY_WITH_PARENT,
40                                GTK_MESSAGE_ERROR,
41                                GTK_BUTTONS_CLOSE,
42                                "%s", msg);
43     g_signal_connect_swapped(GTK_OBJECT(d), "response",
44                              G_CALLBACK(gtk_widget_destroy),
45                              GTK_OBJECT(d));
46     gtk_widget_show(d);
47 }
48
49 int main(int argc, char **argv)
50 {
51     SnDisplay *sn_d;
52     SnLauncheeContext *sn_cx;
53     gchar *p;
54
55     parse_paths_startup();
56
57     gtk_init(&argc, &argv);
58
59     p = g_build_filename(GLADEDIR, "obconf.glade", NULL);
60     glade = glade_xml_new(p, NULL, NULL);
61     g_free(p);
62
63     if (!glade) {
64         obconf_error("Failed to load the obconf.glade interface file. You "
65                      "have probably failed to install ObConf properly.");
66         return 1;
67     }
68
69     xmlIndentTreeOutput = 1;
70     if (!parse_load_rc(NULL, &doc, &root)) {
71         obconf_error("Failed to load an rc.xml. You have probably failed to "
72                      "install Openbox properly.");
73         return 1;
74     }
75
76     glade_xml_signal_autoconnect(glade);
77
78     {
79         gchar *s = g_strdup_printf
80             ("<span weight=\"bold\" size=\"xx-large\">ObConf %s</span>",
81              PACKAGE_VERSION);
82         gtk_label_set_markup(GTK_LABEL
83                              (glade_xml_get_widget(glade, "title_label")), s);
84         g_free(s);
85     }
86
87     setup_behavior_tab();
88     setup_dock_tab();
89     setup_focus_mouse(glade_xml_get_widget(glade, "focus_mouse"));
90     setup_focus_raise(glade_xml_get_widget(glade, "focus_raise"));
91     setup_focus_delay(glade_xml_get_widget(glade, "focus_delay"));
92     setup_focus_new(glade_xml_get_widget(glade, "focus_new"));
93     setup_place_mouse(glade_xml_get_widget(glade, "place_mouse"));
94     setup_resist_window(glade_xml_get_widget(glade, "resist_window"));
95     setup_resist_edge(glade_xml_get_widget(glade, "resist_edge"));
96     setup_resize_contents(glade_xml_get_widget(glade, "resize_contents"));
97     setup_dock_position(glade_xml_get_widget(glade, "dock_position"));
98     setup_dock_float_x(glade_xml_get_widget(glade, "dock_float_x"));
99     setup_dock_float_y(glade_xml_get_widget(glade, "dock_float_y"));
100     setup_dock_stacking(glade_xml_get_widget(glade, "dock_stack_top"),
101                         glade_xml_get_widget(glade, "dock_stack_normal"),
102                         glade_xml_get_widget(glade, "dock_stack_bottom"));
103     setup_dock_direction(glade_xml_get_widget(glade, "dock_direction"));
104     setup_dock_hide(glade_xml_get_widget(glade, "dock_hide"));
105     setup_dock_hide_delay(glade_xml_get_widget(glade, "dock_hide_delay"));
106     setup_theme_names(glade_xml_get_widget(glade, "theme_names"));
107     setup_title_layout(glade_xml_get_widget(glade, "title_layout"));
108     setup_desktop_num(glade_xml_get_widget(glade, "desktop_num"));
109     setup_desktop_names(glade_xml_get_widget(glade, "desktop_names"));
110     setup_window_border(glade_xml_get_widget(glade, "window_border"));
111     setup_font_active(glade_xml_get_widget(glade, "font_active"));
112     setup_font_inactive(glade_xml_get_widget(glade, "font_inactive"));
113     setup_font_menu_header(glade_xml_get_widget(glade, "font_menu_header"));
114     setup_font_menu_item(glade_xml_get_widget(glade, "font_menu_item"));
115     setup_font_display(glade_xml_get_widget(glade, "font_display"));
116
117     mainwin = glade_xml_get_widget(glade, "main_window");
118
119     sn_d = sn_display_new(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
120                           NULL, NULL);
121
122     sn_cx = sn_launchee_context_new_from_environment
123         (sn_d, gdk_screen_get_number(gdk_display_get_default_screen
124                                      (gdk_display_get_default())));
125
126     if (sn_cx)
127         sn_launchee_context_setup_window
128             (sn_cx, GDK_WINDOW_XWINDOW(GDK_WINDOW(mainwin->window)));
129
130     gtk_widget_show_all(mainwin);
131
132     if (sn_cx)
133         sn_launchee_context_complete(sn_cx);
134
135     if (sn_cx)
136         sn_launchee_context_unref(sn_cx);
137     sn_display_unref(sn_d);
138
139     gtk_main();
140
141     parse_paths_shutdown();
142
143     xmlFreeDoc(doc);
144     return 0;
145 }