]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
9 #include "extensions.h"
16 #include "../render/render.h"
17 #include "../render/font.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 char *ob_restart_path
= NULL
;
48 gboolean ob_remote
= FALSE
;
49 gboolean ob_sync
= TRUE
;
52 void signal_handler(const ObEvent
*e
, void *data
);
54 int main(int argc
, char **argv
)
56 struct sigaction action
;
59 ob_state
= State_Starting
;
61 /* initialize the locale */
62 if (!setlocale(LC_ALL
, ""))
63 g_warning("Couldn't set locale from environment.\n");
64 bindtextdomain(PACKAGE
, LOCALEDIR
);
65 bind_textdomain_codeset(PACKAGE
, "UTF-8");
68 /* start our event dispatcher and register for signals */
70 dispatch_register(Event_Signal
, signal_handler
, NULL
);
72 /* set up signal handler */
74 action
.sa_handler
= dispatch_signal
;
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
);
144 /* XXX load all plugins!! */
145 plugin_open("focus");
146 plugin_open("keyboard");
147 plugin_open("mouse");
149 /* get all the existing windows */
152 ob_state
= State_Running
;
153 while (!ob_shutdown
) {
156 ob_state
= State_Exiting
;
158 client_unmanage_all();
160 plugin_shutdown(); /* calls all the plugins' shutdown functions */
172 XCloseDisplay(ob_display
);
176 /* XXX if (ob_restart) */
181 void signal_handler(const ObEvent
*e
, void *data
)
185 s
= e
->data
.s
.signal
;
188 g_message("Caught SIGUSR1 signal. Restarting.");
189 ob_shutdown
= ob_restart
= TRUE
;
200 g_message("Caught signal %d. Exiting.", s
);
206 g_error("Caught signal %d. Aborting and dumping core.", s
);
This page took 0.040397 seconds and 4 git commands to generate.