]>
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(const ObEvent
*e
);
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 /* start our event dispatcher and register for signals */
68 dispatch_register(signal_handler
, Event_Signal
);
70 /* set up signal handler */
72 action
.sa_handler
= dispatch_signal
;
73 action
.sa_mask
= sigset
;
74 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
75 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
76 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
77 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
78 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
79 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
80 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
81 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
82 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
84 /* anything that died while we were restarting won't give us a SIGCHLD */
85 while (waitpid(-1, NULL
, WNOHANG
) > 0);
87 /* XXX parse out command line args */
88 (void)argc
;(void)argv
;
90 ob_display
= XOpenDisplay(NULL
);
91 if (ob_display
== NULL
) {
92 /* print a message and exit */
93 g_critical("Failed to open the display.");
96 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
97 /* print a message and exit */
98 g_critical("Failed to set display as close-on-exec.");
102 ob_screen
= DefaultScreen(ob_display
);
103 ob_root
= RootWindow(ob_display
, ob_screen
);
105 /* XXX fork self onto other screens */
107 XSynchronize(ob_display
, ob_sync
);
109 /* check for locale support */
110 if (!XSupportsLocale())
111 g_warning("X server does not support locale.");
112 if (!XSetLocaleModifiers(""))
113 g_warning("Cannot set locale modifiers for the X server.");
115 /* set our error handler */
116 XSetErrorHandler(xerror_handler
);
118 /* set the DISPLAY environment variable for any lauched children, to the
119 display we're using, so they open in the right place. */
120 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
122 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
123 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
124 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
126 prop_startup(); /* get atoms values for the display */
127 extensions_query_all(); /* find which extensions are present */
129 if (screen_annex()) { /* it will be ours! */
134 engine_startup(themerc_engine
);
140 dispatch_ob(Event_Ob_Startup
);
142 /* get all the existing windows */
145 ob_state
= State_Running
;
146 while (!ob_shutdown
) {
149 ob_state
= State_Exiting
;
151 client_unmanage_all();
153 dispatch_ob(Event_Ob_Shutdown
);
164 XCloseDisplay(ob_display
);
168 /* XXX if (ob_restart) */
173 void signal_handler(const ObEvent
*e
)
175 switch (e
->data
.signal
) {
177 g_message("Caught SIGUSR1 signal. Restarting.");
178 ob_shutdown
= ob_restart
= TRUE
;
189 g_message("Caught signal %d. Exiting.", e
->data
.signal
);
195 g_error("Caught signal %d. Aborting and dumping core.",e
->data
.signal
);
This page took 0.039781 seconds and 4 git commands to generate.