8 #include "extensions.h"
15 #include "clientwrap.h"
16 #include "openboxwrap.h"
17 #include "configwrap.h"
20 #include "../render/render.h"
25 #ifdef HAVE_SYS_SELECT_H
26 # include <sys/select.h>
34 #ifdef HAVE_SYS_WAIT_H
35 # include <sys/types.h>
36 # include <sys/wait.h>
42 #include <X11/cursorfont.h>
44 Display *ob_display = NULL;
48 gboolean ob_shutdown = FALSE;
49 gboolean ob_restart = FALSE;
50 char *ob_restart_path = NULL;
51 gboolean ob_remote = FALSE;
52 gboolean ob_sync = TRUE;
55 void signal_handler(int signal);
57 int main(int argc, char **argv)
59 struct sigaction action;
62 ob_state = State_Starting;
64 /* initialize the locale */
65 if (!setlocale(LC_ALL, ""))
66 g_warning("Couldn't set locale from environment.\n");
67 bindtextdomain(PACKAGE, LOCALEDIR);
68 bind_textdomain_codeset(PACKAGE, "UTF-8");
71 /* set up signal handler */
73 action.sa_handler = signal_handler;
74 action.sa_mask = sigset;
75 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
76 sigaction(SIGUSR1, &action, (struct sigaction *) NULL);
77 sigaction(SIGPIPE, &action, (struct sigaction *) NULL);
78 sigaction(SIGSEGV, &action, (struct sigaction *) NULL);
79 sigaction(SIGFPE, &action, (struct sigaction *) NULL);
80 sigaction(SIGTERM, &action, (struct sigaction *) NULL);
81 sigaction(SIGINT, &action, (struct sigaction *) NULL);
82 sigaction(SIGHUP, &action, (struct sigaction *) NULL);
83 sigaction(SIGCHLD, &action, (struct sigaction *) NULL);
85 /* anything that died while we were restarting won't give us a SIGCHLD */
86 while (waitpid(-1, NULL, WNOHANG) > 0);
88 /* XXX parse out command line args */
89 (void)argc;(void)argv;
91 ob_display = XOpenDisplay(NULL);
92 if (ob_display == NULL) {
93 /* print a message and exit */
94 g_critical("Failed to open the display.");
97 if (fcntl(ConnectionNumber(ob_display), F_SETFD, 1) == -1) {
98 /* print a message and exit */
99 g_critical("Failed to set display as close-on-exec.");
103 ob_screen = DefaultScreen(ob_display);
104 ob_root = RootWindow(ob_display, ob_screen);
106 /* XXX fork self onto other screens */
108 XSynchronize(ob_display, ob_sync);
110 /* check for locale support */
111 if (!XSupportsLocale())
112 g_warning("X server does not support locale.");
113 if (!XSetLocaleModifiers(""))
114 g_warning("Cannot set locale modifiers for the X server.");
116 /* set our error handler */
117 XSetErrorHandler(xerror_handler);
119 /* set the DISPLAY environment variable for any lauched children, to the
120 display we're using, so they open in the right place. */
121 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display)));
123 ob_cursors.left_ptr = XCreateFontCursor(ob_display, XC_left_ptr);
124 ob_cursors.ll_angle = XCreateFontCursor(ob_display, XC_ll_angle);
125 ob_cursors.lr_angle = XCreateFontCursor(ob_display, XC_lr_angle);
127 prop_startup(); /* get atoms values for the display */
128 extensions_query_all(); /* find which extensions are present */
130 if (screen_annex()) { /* it will be ours! */
135 engine_startup(themerc_engine);
137 configwrap_startup();
138 openboxwrap_startup();
139 clientwrap_startup();
148 /* load the user's settings */
149 if (!python_import("rc"))
150 g_warning("ERROR LOADING RC FILE");
152 HOOKFIRE(startup, "()");
154 /* get all the existing windows */
157 ob_state = State_Running;
158 while (!ob_shutdown) {
161 ob_state = State_Exiting;
163 client_unmanage_all();
165 HOOKFIRE(shutdown, "()");
173 clientwrap_shutdown();
174 openboxwrap_shutdown();
175 configwrap_shutdown();
183 XCloseDisplay(ob_display);
185 /* XXX if (ob_restart) */
190 void signal_handler(int signal)
194 g_message("Caught SIGUSR1 signal. Restarting.");
195 ob_shutdown = ob_restart = TRUE;
206 g_message("Caught signal %d. Exiting.", signal);
212 g_error("Caught signal %d. Aborting and dumping core.", signal);