]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
9 #include "extensions.h"
14 #include "../render/render.h"
15 #include "../render/font.h"
20 #ifdef HAVE_SYS_SELECT_H
21 # include <sys/select.h>
29 #ifdef HAVE_SYS_WAIT_H
30 # include <sys/types.h>
31 # include <sys/wait.h>
37 #include <X11/cursorfont.h>
39 Display
*ob_display
= NULL
;
43 gboolean ob_shutdown
= FALSE
;
44 gboolean ob_restart
= FALSE
;
45 char *ob_restart_path
= NULL
;
46 gboolean ob_remote
= FALSE
;
47 gboolean ob_sync
= TRUE
;
50 void signal_handler(int signal
);
52 int main(int argc
, char **argv
)
54 struct sigaction action
;
57 ob_state
= State_Starting
;
59 /* initialize the locale */
60 if (!setlocale(LC_ALL
, ""))
61 g_warning("Couldn't set locale from environment.\n");
62 bindtextdomain(PACKAGE
, LOCALEDIR
);
63 bind_textdomain_codeset(PACKAGE
, "UTF-8");
66 /* set up signal handler */
68 action
.sa_handler
= signal_handler
;
69 action
.sa_mask
= sigset
;
70 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
71 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
72 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
73 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
74 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
75 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
76 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
77 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
78 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
80 /* anything that died while we were restarting won't give us a SIGCHLD */
81 while (waitpid(-1, NULL
, WNOHANG
) > 0);
83 /* XXX parse out command line args */
84 (void)argc
;(void)argv
;
86 ob_display
= XOpenDisplay(NULL
);
87 if (ob_display
== NULL
) {
88 /* print a message and exit */
89 g_critical("Failed to open the display.");
92 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
93 /* print a message and exit */
94 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_startup(); /* get atoms values for the display */
123 extensions_query_all(); /* find which extensions are present */
125 if (screen_annex()) { /* it will be ours! */
131 engine_startup(themerc_engine
);
137 /*HOOKFIRE(startup, "()");XXX*/
139 /* get all the existing windows */
142 ob_state
= State_Running
;
143 while (!ob_shutdown
) {
146 ob_state
= State_Exiting
;
148 client_unmanage_all();
150 /*HOOKFIRE(shutdown, "()");XXX*/
162 XCloseDisplay(ob_display
);
164 /* XXX if (ob_restart) */
169 void signal_handler(int signal
)
173 g_message("Caught SIGUSR1 signal. Restarting.");
174 ob_shutdown
= ob_restart
= TRUE
;
185 g_message("Caught signal %d. Exiting.", signal
);
191 g_error("Caught signal %d. Aborting and dumping core.", signal
);
This page took 0.039933 seconds and 4 git commands to generate.