X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fopenbox;a=blobdiff_plain;f=openbox%2Fopenbox.c;h=cba0499533573ddfc777497e79cd5bc6d8c0e41c;hp=b2cdc8efded4e8cb9d465af61042828c077c0912;hb=HEAD;hpb=fd77a0a7b3f892925f203287b8b46c6ec9be94ea diff --git a/openbox/openbox.c b/openbox/openbox.c index b2cdc8ef..cba04995 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -47,6 +47,7 @@ #include "obrender/theme.h" #include "obt/display.h" #include "obt/xqueue.h" +#include "obt/signal.h" #include "obt/prop.h" #include "obt/keyboard.h" #include "obt/xml.h" @@ -117,6 +118,8 @@ gint main(gint argc, gchar **argv) { gchar *program_name; + obt_signal_listen(); + ob_set_state(OB_STATE_STARTING); ob_debug_startup(); @@ -160,16 +163,17 @@ gint main(gint argc, gchar **argv) ob_main_loop = g_main_loop_new(NULL, FALSE); - /* set up signal handler */ -// obt_main_loop_signal_add(ob_main_loop, SIGUSR1, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGUSR2, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGTERM, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGINT, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGHUP, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGPIPE, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGCHLD, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGTTIN, signal_handler, NULL,NULL); -// obt_main_loop_signal_add(ob_main_loop, SIGTTOU, signal_handler, NULL,NULL); + /* set up signal handlers, they are called from the mainloop + in the main program's thread */ + obt_signal_add_callback(SIGUSR1, signal_handler, NULL); + obt_signal_add_callback(SIGUSR2, signal_handler, NULL); + obt_signal_add_callback(SIGTERM, signal_handler, NULL); + obt_signal_add_callback(SIGINT, signal_handler, NULL); + obt_signal_add_callback(SIGHUP, signal_handler, NULL); + obt_signal_add_callback(SIGPIPE, signal_handler, NULL); + obt_signal_add_callback(SIGCHLD, signal_handler, NULL); + obt_signal_add_callback(SIGTTIN, signal_handler, NULL); + obt_signal_add_callback(SIGTTOU, signal_handler, NULL); ob_screen = DefaultScreen(obt_display); @@ -192,7 +196,7 @@ gint main(gint argc, gchar **argv) /* set the DISPLAY environment variable for any lauched children, to the display we're using, so they open in the right place. */ - setenv("DISPLAY", DisplayString(obt_display), TRUE); + g_setenv("DISPLAY", DisplayString(obt_display), TRUE); /* create available cursors */ cursors[OB_CURSOR_NONE] = None; @@ -220,6 +224,7 @@ gint main(gint argc, gchar **argv) event_reset_time(); do { + gchar *xml_error_string = NULL; ObPrompt *xmlprompt = NULL; if (reconfigure) obt_keyboard_reload(); @@ -254,13 +259,20 @@ gint main(gint argc, gchar **argv) gchar *p = g_filename_to_utf8(config_file, -1, NULL, NULL, NULL); if (p) - OBT_PROP_SETS(obt_root(ob_screen), OB_CONFIG_FILE, - utf8, p); + OBT_PROP_SETS(obt_root(ob_screen), OB_CONFIG_FILE, p); g_free(p); } else OBT_PROP_ERASE(obt_root(ob_screen), OB_CONFIG_FILE); + if (obt_xml_last_error(i)) { + xml_error_string = g_strdup_printf( + _("One or more XML syntax errors were found while parsing the Openbox configuration files. See stdout for more information. The last error seen was in file \"%s\" line %d, with message: %s"), + obt_xml_last_error_file(i), + obt_xml_last_error_line(i), + obt_xml_last_error_message(i)); + } + /* we're done with parsing now, kill it */ obt_xml_instance_unref(i); } @@ -282,8 +294,8 @@ gint main(gint argc, gchar **argv) if (ob_rr_theme == NULL) ob_exit_with_error(_("Unable to load a theme.")); - OBT_PROP_SETS(obt_root(ob_screen), - OB_THEME, utf8, ob_rr_theme->name); + OBT_PROP_SETS(obt_root(ob_screen), OB_THEME, + ob_rr_theme->name); } if (reconfigure) { @@ -352,24 +364,19 @@ gint main(gint argc, gchar **argv) } } - reconfigure = FALSE; - ob_set_state(OB_STATE_RUNNING); - if (startup_cmd) run_startup_cmd(); + if (!reconfigure && startup_cmd) run_startup_cmd(); + + reconfigure = FALSE; /* look for parsing errors */ - { - xmlErrorPtr e = xmlGetLastError(); - if (e) { - gchar *m; - - m = g_strdup_printf(_("One or more XML syntax errors were found while parsing the Openbox configuration files. See stdout for more information. The last error seen was in file \"%s\" line %d, with message: %s"), e->file, e->line, e->message); - xmlprompt = - prompt_show_message(m, _("Openbox Syntax Error"), _("Close")); - g_free(m); - xmlResetError(e); - } + if (xml_error_string) { + xmlprompt = prompt_show_message(xml_error_string, + _("Openbox Syntax Error"), + _("Close")); + g_free(xml_error_string); + xml_error_string = NULL; } g_main_loop_run(ob_main_loop); @@ -420,6 +427,7 @@ gint main(gint argc, gchar **argv) if (restart) { ob_debug_shutdown(); + obt_signal_stop(); if (restart_path != NULL) { gint argcp; gchar **argvp; @@ -473,8 +481,10 @@ gint main(gint argc, gchar **argv) g_free(ob_sm_id); g_free(program_name); - if (!restart) + if (!restart) { ob_debug_shutdown(); + obt_signal_stop(); + } return exitcode; } @@ -509,9 +519,9 @@ static void print_version(void) { g_print("Openbox %s\n", PACKAGE_VERSION); g_print(_("Copyright (c)")); - g_print(" 2008 Mikael Magnusson\n"); + g_print(" 2004 Mikael Magnusson\n"); g_print(_("Copyright (c)")); - g_print(" 2003-2006 Dana Jansens\n\n"); + g_print(" 2002 Dana Jansens\n\n"); g_print("This program comes with ABSOLUTELY NO WARRANTY.\n"); g_print("This is free software, and you are welcome to redistribute it\n"); g_print("under certain conditions. See the file COPYING for details.\n\n"); @@ -570,7 +580,7 @@ static void run_startup_cmd(void) G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, NULL, &e); - if (!g_shell_parse_argv(startup_cmd, NULL, &argv, &e)) { + if (!ok) { g_message("Error launching startup command: %s", e->message); g_error_free(e); @@ -583,12 +593,12 @@ static void parse_env(void) const gchar *id; /* unset this so we don't pass it on unknowingly */ - unsetenv("DESKTOP_STARTUP_ID"); + g_unsetenv("DESKTOP_STARTUP_ID"); /* this is how gnome-session passes in a session client id */ id = g_getenv("DESKTOP_AUTOSTART_ID"); if (id) { - unsetenv("DESKTOP_AUTOSTART_ID"); + g_unsetenv("DESKTOP_AUTOSTART_ID"); if (ob_sm_id) g_free(ob_sm_id); ob_sm_id = g_strdup(id); ob_debug_type(OB_DEBUG_SM, @@ -623,7 +633,7 @@ static void parse_args(gint *argc, gchar **argv) } else if (!strcmp(argv[i], "--startup")) { if (i == *argc - 1) /* no args left */ - g_printerr(_("--startup requires an argument\n")); + g_printerr(_("%s requires an argument\n"), "--startup"); else { /* this will be in the current locale encoding, which is what we want */ @@ -657,7 +667,7 @@ static void parse_args(gint *argc, gchar **argv) } else if (!strcmp(argv[i], "--config-file")) { if (i == *argc - 1) /* no args left */ - g_printerr(_("--config-file requires an argument\n")); + g_printerr(_("%s requires an argument\n"), "--config-file"); else { /* this will be in the current locale encoding, which is what we want */