9 #include "extensions.h"
15 #include "../render/render.h"
16 #include "../render/font.h"
21 #ifdef HAVE_SYS_SELECT_H
22 # include <sys/select.h>
30 #ifdef HAVE_SYS_WAIT_H
31 # include <sys/types.h>
32 # include <sys/wait.h>
38 #include <X11/cursorfont.h>
40 Display *ob_display = NULL;
44 gboolean ob_shutdown = FALSE;
45 gboolean ob_restart = FALSE;
46 char *ob_restart_path = NULL;
47 gboolean ob_remote = FALSE;
48 gboolean ob_sync = TRUE;
51 void signal_handler(const ObEvent *e, void *data);
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 /* start our event dispatcher and register for signals */
69 dispatch_register(Event_Signal, signal_handler, NULL);
71 /* set up signal handler */
73 action.sa_handler = dispatch_signal;
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);
142 /* XXX load all plugins!! */
143 plugin_open("focus");
144 plugin_open("keyboard");
146 /* get all the existing windows */
149 ob_state = State_Running;
150 while (!ob_shutdown) {
153 ob_state = State_Exiting;
155 client_unmanage_all();
167 XCloseDisplay(ob_display);
171 /* XXX if (ob_restart) */
176 void signal_handler(const ObEvent *e, void *data)
180 s = e->data.s.signal;
183 g_message("Caught SIGUSR1 signal. Restarting.");
184 ob_shutdown = ob_restart = TRUE;
195 g_message("Caught signal %d. Exiting.", s);
201 g_error("Caught signal %d. Aborting and dumping core.", s);