]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
8 #include "extensions.h"
15 #include "clientwrap.h"
16 #include "openboxwrap.h"
17 #include "configwrap.h"
20 #include "../render/render.h"
21 #include "../render/font.h"
26 #ifdef HAVE_SYS_SELECT_H
27 # include <sys/select.h>
35 #ifdef HAVE_SYS_WAIT_H
36 # include <sys/types.h>
37 # include <sys/wait.h>
43 #include <X11/cursorfont.h>
45 Display
*ob_display
= NULL
;
49 gboolean ob_shutdown
= FALSE
;
50 gboolean ob_restart
= FALSE
;
51 char *ob_restart_path
= NULL
;
52 gboolean ob_remote
= FALSE
;
53 gboolean ob_sync
= TRUE
;
56 void signal_handler(int signal
);
58 int main(int argc
, char **argv
)
60 struct sigaction action
;
63 ob_state
= State_Starting
;
65 /* initialize the locale */
66 if (!setlocale(LC_ALL
, ""))
67 g_warning("Couldn't set locale from environment.\n");
68 bindtextdomain(PACKAGE
, LOCALEDIR
);
69 bind_textdomain_codeset(PACKAGE
, "UTF-8");
72 /* set up signal handler */
74 action
.sa_handler
= signal_handler
;
75 action
.sa_mask
= sigset
;
76 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
77 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
78 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
79 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
80 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
81 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
82 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
83 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
84 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
86 /* anything that died while we were restarting won't give us a SIGCHLD */
87 while (waitpid(-1, NULL
, WNOHANG
) > 0);
89 /* XXX parse out command line args */
90 (void)argc
;(void)argv
;
92 ob_display
= XOpenDisplay(NULL
);
93 if (ob_display
== NULL
) {
94 /* print a message and exit */
95 g_critical("Failed to open the display.");
98 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
99 /* print a message and exit */
100 g_critical("Failed to set display as close-on-exec.");
104 ob_screen
= DefaultScreen(ob_display
);
105 ob_root
= RootWindow(ob_display
, ob_screen
);
107 /* XXX fork self onto other screens */
109 XSynchronize(ob_display
, ob_sync
);
111 /* check for locale support */
112 if (!XSupportsLocale())
113 g_warning("X server does not support locale.");
114 if (!XSetLocaleModifiers(""))
115 g_warning("Cannot set locale modifiers for the X server.");
117 /* set our error handler */
118 XSetErrorHandler(xerror_handler
);
120 /* set the DISPLAY environment variable for any lauched children, to the
121 display we're using, so they open in the right place. */
122 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
124 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
125 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
126 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
128 prop_startup(); /* get atoms values for the display */
129 extensions_query_all(); /* find which extensions are present */
131 if (screen_annex()) { /* it will be ours! */
136 engine_startup(themerc_engine
);
138 configwrap_startup();
139 openboxwrap_startup();
140 clientwrap_startup();
149 /* load the user's settings */
150 if (!python_import("rc"))
151 g_warning("ERROR LOADING RC FILE");
153 HOOKFIRE(startup
, "()");
155 /* get all the existing windows */
158 ob_state
= State_Running
;
159 while (!ob_shutdown
) {
162 ob_state
= State_Exiting
;
164 client_unmanage_all();
166 HOOKFIRE(shutdown
, "()");
174 clientwrap_shutdown();
175 openboxwrap_shutdown();
176 configwrap_shutdown();
184 XCloseDisplay(ob_display
);
186 /* XXX if (ob_restart) */
191 void signal_handler(int signal
)
195 g_message("Caught SIGUSR1 signal. Restarting.");
196 ob_shutdown
= ob_restart
= TRUE
;
207 g_message("Caught signal %d. Exiting.", signal
);
213 g_error("Caught signal %d. Aborting and dumping core.", signal
);
This page took 0.044882 seconds and 4 git commands to generate.