1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 main.c for ObConf, the configuration tool for Openbox
4 Copyright (c) 2003-2007 Dana Jansens
5 Copyright (c) 2003 Tim Riley
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
23 #include "appearance.h"
27 #include "preview_update.h"
31 #define SN_API_NOT_YET_FROZEN
33 #undef SN_API_NOT_YET_FROZEN
36 GtkWidget *mainwin = NULL;
43 static gchar *obc_theme_install = NULL;
44 static gchar *obc_theme_archive = NULL;
46 void obconf_error(gchar *msg)
50 d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
51 GTK_DIALOG_DESTROY_WITH_PARENT,
55 g_signal_connect_swapped(GTK_OBJECT(d), "response",
56 G_CALLBACK(gtk_widget_destroy),
61 static void print_version()
63 g_print("ObConf %s\n", PACKAGE_VERSION);
64 g_print(_("Copyright (c)"));
65 g_print(" 2003-2007 Dana Jansens\n");
66 g_print(_("Copyright (c)"));
67 g_print(" 2003 Tim Riley\n\n");
68 g_print(" 2007 Javeed Shaikh\n\n");
69 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
70 g_print("This is free software, and you are welcome to redistribute it\n");
71 g_print("under certain conditions. See the file COPYING for details.\n\n");
76 static void print_help()
78 g_print(_("Syntax: obconf [options] [ARCHIVE.obt]\n"));
79 g_print(_("\nOptions:\n"));
80 g_print(_(" --help Display this help and exit\n"));
81 g_print(_(" --version Display the version and exit\n"));
82 g_print(_(" --install ARCHIVE.obt Install the given theme archive and select it\n"));
83 g_print(_(" --archive THEME Create a theme archive from the given theme directory\n"));
84 g_print(_("\nPlease report bugs at %s\n\n"), PACKAGE_BUGREPORT);
89 static void parse_args(int argc, char **argv)
93 for (i = 1; i < argc; ++i) {
94 if (!strcmp(argv[i], "--help"))
96 if (!strcmp(argv[i], "--version"))
98 else if (!strcmp(argv[i], "--install")) {
99 if (i == argc - 1) /* no args left */
100 g_printerr(_("--install requires an argument\n"));
102 obc_theme_install = argv[++i];
104 else if (!strcmp(argv[i], "--archive")) {
105 if (i == argc - 1) /* no args left */
106 g_printerr(_("--archive requires an argument\n"));
108 obc_theme_archive = argv[++i];
110 obc_theme_install = argv[i];
114 int main(int argc, char **argv)
117 SnLauncheeContext *sn_cx;
120 gtk_init(&argc, &argv);
121 parse_args(argc, argv);
123 if (obc_theme_archive) {
124 archive_create(obc_theme_archive);
128 p = g_build_filename(GLADEDIR, "obconf.glade", NULL);
129 glade = glade_xml_new(p, NULL, NULL);
133 obconf_error("Failed to load the obconf.glade interface file. You "
134 "have probably failed to install ObConf properly.");
138 parse_paths_startup();
139 rrinst = RrInstanceNew(GDK_DISPLAY(), gdk_x11_get_default_screen());
141 xmlIndentTreeOutput = 1;
142 if (!parse_load_rc(NULL, &doc, &root)) {
143 obconf_error("Failed to load an rc.xml. You have probably failed to "
144 "install Openbox properly.");
148 glade_xml_signal_autoconnect(glade);
151 gchar *s = g_strdup_printf
152 ("<span weight=\"bold\" size=\"xx-large\">ObConf %s</span>",
154 gtk_label_set_markup(GTK_LABEL
155 (glade_xml_get_widget(glade, "title_label")), s);
159 theme_setup_names(get_widget("theme_names"));
161 appearance_setup_tab();
163 behavior_setup_tab();
164 behavior_setup_focus_mouse(get_widget("focus_mouse"));
165 behavior_setup_focus_raise(get_widget("focus_raise"));
166 behavior_setup_focus_last(get_widget("focus_raise"));
167 behavior_setup_focus_delay(get_widget("focus_delay"));
168 behavior_setup_focus_new(get_widget("focus_new"));
169 behavior_setup_place_mouse(get_widget("place_mouse"));
170 behavior_setup_resist_window(get_widget("resist_window"));
171 behavior_setup_resist_edge(get_widget("resist_edge"));
172 behavior_setup_resize_contents(get_widget("resize_contents"));
174 desktops_setup_num(get_widget("desktop_num"));
175 desktops_setup_names(get_widget("desktop_names"));
178 dock_setup_position(get_widget("dock_position"));
179 dock_setup_float_x(get_widget("dock_float_x"));
180 dock_setup_float_y(get_widget("dock_float_y"));
181 dock_setup_stacking(get_widget("dock_stack_top"),
182 get_widget("dock_stack_normal"),
183 get_widget("dock_stack_bottom"));
184 dock_setup_direction(get_widget("dock_direction"));
185 dock_setup_hide(get_widget("dock_hide"));
186 dock_setup_hide_delay(get_widget("dock_hide_delay"));
188 mainwin = get_widget("main_window");
190 sn_d = sn_display_new(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
193 sn_cx = sn_launchee_context_new_from_environment
194 (sn_d, gdk_screen_get_number(gdk_display_get_default_screen
195 (gdk_display_get_default())));
198 sn_launchee_context_setup_window
199 (sn_cx, GDK_WINDOW_XWINDOW(GDK_WINDOW(mainwin->window)));
201 gtk_widget_show_all(mainwin);
204 sn_launchee_context_complete(sn_cx);
207 sn_launchee_context_unref(sn_cx);
208 sn_display_unref(sn_d);
210 if (obc_theme_install)
211 theme_install(obc_theme_install);
215 preview_update_set_list_store(NULL);
216 preview_update_set_active_font(NULL);
217 preview_update_set_inactive_font(NULL);
218 preview_update_set_menu_header_font(NULL);
219 preview_update_set_menu_item_font(NULL);
220 preview_update_set_osd_font(NULL);
221 preview_update_set_title_layout(NULL);
223 RrInstanceFree(rrinst);
224 parse_paths_shutdown();
230 gboolean on_main_window_delete_event(GtkWidget *w, GdkEvent *e, gpointer d)
236 void on_close_clicked()