+ do {
+ if (reconfigure) obt_keyboard_reload();
+
+ /* get the keycodes for keys we use */
+ keys[OB_KEY_RETURN] = obt_keyboard_keysym_to_keycode(XK_Return);
+ keys[OB_KEY_ESCAPE] = obt_keyboard_keysym_to_keycode(XK_Escape);
+ keys[OB_KEY_LEFT] = obt_keyboard_keysym_to_keycode(XK_Left);
+ keys[OB_KEY_RIGHT] = obt_keyboard_keysym_to_keycode(XK_Right);
+ keys[OB_KEY_UP] = obt_keyboard_keysym_to_keycode(XK_Up);
+ keys[OB_KEY_DOWN] = obt_keyboard_keysym_to_keycode(XK_Down);
+
+ {
+ ObtParseInst *i;
+
+ /* startup the parsing so everything can register sections
+ of the rc */
+ i = obt_parse_instance_new();
+
+ /* register all the available actions */
+ actions_startup(reconfigure);
+ /* start up config which sets up with the parser */
+ config_startup(i);
+
+ /* parse/load user options */
+ if (obt_parse_load_config_file(i, "openbox", "rc.xml",
+ "openbox_config"))
+ {
+ obt_parse_tree_from_root(i);
+ obt_parse_close(i);
+ } else
+ g_message(_("Unable to find a valid config file, using some simple defaults"));
+
+/*
+ if (config_type != NULL)
+ PROP_SETS(RootWindow(obt_display, ob_screen),
+ ob_config, config_type);
+*/
+
+ /* we're done with parsing now, kill it */
+ obt_parse_instance_unref(i);
+ }
+
+ /* load the theme specified in the rc file */
+ {
+ RrTheme *theme;
+ if ((theme = RrThemeNew(ob_rr_inst, config_theme, TRUE,
+ config_font_activewindow,
+ config_font_inactivewindow,
+ config_font_menutitle,
+ config_font_menuitem,
+ config_font_osd)))
+ {
+ RrThemeFree(ob_rr_theme);
+ ob_rr_theme = theme;
+ }
+ if (ob_rr_theme == NULL)
+ ob_exit_with_error(_("Unable to load a theme."));
+
+ OBT_PROP_SETS(RootWindow(obt_display, ob_screen),
+ OB_THEME, utf8, ob_rr_theme->name);
+ }
+
+ if (reconfigure) {
+ GList *it;
+
+ /* update all existing windows for the new theme */
+ for (it = client_list; it; it = g_list_next(it)) {
+ ObClient *c = it->data;
+ frame_adjust_theme(c->frame);
+ }
+ }
+ event_startup(reconfigure);
+ /* focus_backup is used for stacking, so this needs to come before
+ anything that calls stacking_add */
+ sn_startup(reconfigure);
+ window_startup(reconfigure);
+ focus_startup(reconfigure);
+ focus_cycle_startup(reconfigure);
+ focus_cycle_indicator_startup(reconfigure);
+ focus_cycle_popup_startup(reconfigure);
+ screen_startup(reconfigure);
+ grab_startup(reconfigure);
+ group_startup(reconfigure);
+ ping_startup(reconfigure);
+ client_startup(reconfigure);
+ dock_startup(reconfigure);
+ moveresize_startup(reconfigure);
+ keyboard_startup(reconfigure);
+ mouse_startup(reconfigure);
+ menu_frame_startup(reconfigure);
+ menu_startup(reconfigure);
+
+ if (!reconfigure) {
+ guint32 xid;
+ ObWindow *w;
+
+ /* get all the existing windows */
+ client_manage_all();
+ focus_nothing();
+
+ /* focus what was focused if a wm was already running */
+ if (OBT_PROP_GET32(RootWindow(obt_display, ob_screen),
+ NET_ACTIVE_WINDOW, WINDOW, &xid) &&
+ (w = g_hash_table_lookup(window_map, &xid)) &&
+ WINDOW_IS_CLIENT(w))
+ {
+ client_focus(WINDOW_AS_CLIENT(w));
+ }
+ } else {
+ GList *it;
+
+ /* redecorate all existing windows */
+ for (it = client_list; it; it = g_list_next(it)) {
+ ObClient *c = it->data;
+
+ /* the new config can change the window's decorations */
+ client_setup_decor_and_functions(c, FALSE);
+ /* redraw the frames */
+ frame_adjust_area(c->frame, TRUE, TRUE, FALSE);
+ /* the decor sizes may have changed, so the windows may
+ end up in new positions */
+ client_reconfigure(c, FALSE);
+ }
+ }
+
+ reconfigure = FALSE;
+
+ state = OB_STATE_RUNNING;
+ obt_main_loop_run(ob_main_loop);
+ state = OB_STATE_EXITING;
+
+ if (!reconfigure) {
+ dock_remove_all();
+ client_unmanage_all();
+ }
+
+ menu_shutdown(reconfigure);
+ menu_frame_shutdown(reconfigure);
+ mouse_shutdown(reconfigure);
+ keyboard_shutdown(reconfigure);
+ moveresize_shutdown(reconfigure);
+ dock_shutdown(reconfigure);
+ client_shutdown(reconfigure);
+ ping_shutdown(reconfigure);
+ group_shutdown(reconfigure);
+ grab_shutdown(reconfigure);
+ screen_shutdown(reconfigure);
+ focus_cycle_popup_shutdown(reconfigure);
+ focus_cycle_indicator_shutdown(reconfigure);
+ focus_cycle_shutdown(reconfigure);
+ focus_shutdown(reconfigure);
+ window_shutdown(reconfigure);
+ sn_shutdown(reconfigure);
+ event_shutdown(reconfigure);
+ config_shutdown();
+ actions_shutdown(reconfigure);
+ } while (reconfigure);
+ }
+
+ XSync(obt_display, FALSE);
+
+ RrThemeFree(ob_rr_theme);
+ RrInstanceFree(ob_rr_inst);
+
+ session_shutdown(being_replaced);
+
+ obt_display_close(obt_display);
+
+ if (restart) {
+ if (restart_path != NULL) {
+ gint argcp;
+ gchar **argvp;
+ GError *err = NULL;
+
+ /* run other window manager */
+ if (g_shell_parse_argv(restart_path, &argcp, &argvp, &err)) {
+ execvp(argvp[0], argvp);
+ g_strfreev(argvp);
+ } else {
+ g_message(
+ _("Restart failed to execute new executable '%s': %s"),
+ restart_path, err->message);
+ g_error_free(err);
+ }
+ }
+
+ /* we remove the session arguments from argv, so put them back,
+ also don't restore the session on restart */
+ if (ob_sm_save_file != NULL || ob_sm_id != NULL) {
+ gchar **nargv;
+ gint i, l;
+
+ l = argc + 1 +
+ (ob_sm_save_file != NULL ? 2 : 0) +
+ (ob_sm_id != NULL ? 2 : 0);
+ nargv = g_new0(gchar*, l+1);
+ for (i = 0; i < argc; ++i)
+ nargv[i] = argv[i];
+
+ if (ob_sm_save_file != NULL) {
+ nargv[i++] = g_strdup("--sm-save-file");
+ nargv[i++] = ob_sm_save_file;
+ }
+ if (ob_sm_id != NULL) {
+ nargv[i++] = g_strdup("--sm-client-id");
+ nargv[i++] = ob_sm_id;
+ }
+ nargv[i++] = g_strdup("--sm-no-load");
+ g_assert(i == l);
+ argv = nargv;
+ }
+
+ /* re-run me */
+ execvp(argv[0], argv); /* try how we were run */
+ execlp(argv[0], program_name, (gchar*)NULL); /* last resort */