8 #include "extensions.h"
11 #include "eventdata.h"
13 #include "clientwrap.h"
14 #include "screenwrap.h"
22 #ifdef HAVE_SYS_SELECT_H
23 # include <sys/select.h>
31 #ifdef HAVE_SYS_WAIT_H
32 # include <sys/types.h>
33 # include <sys/wait.h>
39 #include <X11/cursorfont.h>
41 Display *ob_display = NULL;
45 gboolean ob_shutdown = FALSE;
46 gboolean ob_restart = FALSE;
47 gboolean ob_remote = FALSE;
48 gboolean ob_sync = TRUE;
51 void signal_handler(int signal);
53 int main(int argc, char **argv)
55 struct sigaction action;
58 ob_state = State_Starting;
60 /* initialize the locale */
61 if (!setlocale(LC_ALL, ""))
62 g_warning("Couldn't set locale from environment.\n");
63 bindtextdomain(PACKAGE, LOCALEDIR);
64 bind_textdomain_codeset(PACKAGE, "UTF-8");
67 /* set up signal handler */
69 action.sa_handler = signal_handler;
70 action.sa_mask = sigset;
71 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
72 sigaction(SIGUSR1, &action, (struct sigaction *) NULL);
73 sigaction(SIGPIPE, &action, (struct sigaction *) NULL);
74 sigaction(SIGSEGV, &action, (struct sigaction *) NULL);
75 sigaction(SIGFPE, &action, (struct sigaction *) NULL);
76 sigaction(SIGTERM, &action, (struct sigaction *) NULL);
77 sigaction(SIGINT, &action, (struct sigaction *) NULL);
78 sigaction(SIGHUP, &action, (struct sigaction *) NULL);
79 sigaction(SIGCHLD, &action, (struct sigaction *) NULL);
81 /* anything that died while we were restarting won't give us a SIGCHLD */
82 while (waitpid(-1, NULL, WNOHANG) > 0);
84 /* XXX parse out command line args */
85 (void)argc;(void)argv;
87 /* critical warnings will exit the program */
88 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
90 ob_display = XOpenDisplay(NULL);
91 if (ob_display == NULL)
92 /* print a message and exit */
93 g_critical("Failed to open the display.");
94 if (fcntl(ConnectionNumber(ob_display), F_SETFD, 1) == -1)
95 /* print a message and exit */
96 g_critical("Failed to set display as close-on-exec.");
98 ob_screen = DefaultScreen(ob_display);
99 ob_root = RootWindow(ob_display, ob_screen);
101 /* XXX fork self onto other screens */
103 XSynchronize(ob_display, ob_sync);
105 /* check for locale support */
106 if (!XSupportsLocale())
107 g_warning("X server does not support locale.");
108 if (!XSetLocaleModifiers(""))
109 g_warning("Cannot set locale modifiers for the X server.");
111 /* set our error handler */
112 XSetErrorHandler(xerror_handler);
114 /* set the DISPLAY environment variable for any lauched children, to the
115 display we're using, so they open in the right place. */
116 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display)));
118 ob_cursors.left_ptr = XCreateFontCursor(ob_display, XC_left_ptr);
119 ob_cursors.ll_angle = XCreateFontCursor(ob_display, XC_ll_angle);
120 ob_cursors.lr_angle = XCreateFontCursor(ob_display, XC_lr_angle);
122 prop_init(); /* get atoms values for the display */
123 extensions_query_all(); /* find which extensions are present */
125 if (screen_annex()) { /* it will be ours! */
130 screenwrap_startup();
131 clientwrap_startup();
140 /* load the user's settings */
141 if (!python_import("rc"))
142 g_warning("ERROR LOADING RC FILE");
144 LOGICALHOOK(Startup, g_quark_try_string("none"), NULL);
146 /* get all the existing windows */
149 ob_state = State_Running;
150 while (!ob_shutdown) {
153 ob_state = State_Exiting;
155 client_unmanage_all();
157 LOGICALHOOK(Shutdown, g_quark_try_string("none"), NULL);
164 eventdata_shutdown();
165 clientwrap_shutdown();
166 screenwrap_shutdown();
172 XCloseDisplay(ob_display);
174 /* XXX if (ob_restart) */
179 void signal_handler(int signal)
183 g_message("Caught SIGUSR1 signal. Restarting.");
184 ob_shutdown = ob_restart = TRUE;
195 g_message("Caught signal %d. Exiting.", signal);
201 g_error("Caught signal %d. Aborting and dumping core.", signal);