]> Dogcows Code - chaz/openbox/blob - openbox/openbox.c
7a0cfbb9e39a5db6c448210f41536c29d2347c65
[chaz/openbox] / openbox / openbox.c
1 #include "openbox.h"
2 #include "event.h"
3 #include "client.h"
4 #include "xerror.h"
5 #include "prop.h"
6 #include "screen.h"
7 #include "focus.h"
8 #include "extensions.h"
9 #include "gettext.h"
10 #include "keyboard.h"
11 #include "pointer.h"
12 #include "engine.h"
13 #include "python.h"
14 #include "hooks.h"
15 #include "clientwrap.h"
16 #include "openboxwrap.h"
17 #include "themerc.h"
18 #include "timer.h"
19 #include "../render/render.h"
20
21 #ifdef HAVE_FCNTL_H
22 # include <fcntl.h>
23 #endif
24 #ifdef HAVE_SYS_SELECT_H
25 # include <sys/select.h>
26 #endif
27 #ifdef HAVE_SIGNAL_H
28 # include <signal.h>
29 #endif
30 #ifdef HAVE_STDLIB_H
31 # include <stdlib.h>
32 #endif
33 #ifdef HAVE_SYS_WAIT_H
34 # include <sys/types.h>
35 # include <sys/wait.h>
36 #endif
37 #ifdef HAVE_LOCALE_H
38 # include <locale.h>
39 #endif
40
41 #include <X11/cursorfont.h>
42
43 Display *ob_display = NULL;
44 int ob_screen;
45 Window ob_root;
46 State ob_state;
47 gboolean ob_shutdown = FALSE;
48 gboolean ob_restart = FALSE;
49 char *ob_restart_path = NULL;
50 gboolean ob_remote = FALSE;
51 gboolean ob_sync = TRUE;
52 Cursors ob_cursors;
53
54 void signal_handler(int signal);
55
56 int main(int argc, char **argv)
57 {
58 struct sigaction action;
59 sigset_t sigset;
60
61 ob_state = State_Starting;
62
63 /* initialize the locale */
64 if (!setlocale(LC_ALL, ""))
65 g_warning("Couldn't set locale from environment.\n");
66 bindtextdomain(PACKAGE, LOCALEDIR);
67 bind_textdomain_codeset(PACKAGE, "UTF-8");
68 textdomain(PACKAGE);
69
70 /* set up signal handler */
71 sigemptyset(&sigset);
72 action.sa_handler = signal_handler;
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);
83
84 /* anything that died while we were restarting won't give us a SIGCHLD */
85 while (waitpid(-1, NULL, WNOHANG) > 0);
86
87 /* XXX parse out command line args */
88 (void)argc;(void)argv;
89
90 ob_display = XOpenDisplay(NULL);
91 if (ob_display == NULL) {
92 /* print a message and exit */
93 g_critical("Failed to open the display.");
94 exit(1);
95 }
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.");
99 exit(1);
100 }
101
102 ob_screen = DefaultScreen(ob_display);
103 ob_root = RootWindow(ob_display, ob_screen);
104
105 /* XXX fork self onto other screens */
106
107 XSynchronize(ob_display, ob_sync);
108
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.");
114
115 /* set our error handler */
116 XSetErrorHandler(xerror_handler);
117
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)));
121
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);
125
126 prop_startup(); /* get atoms values for the display */
127 extensions_query_all(); /* find which extensions are present */
128
129 if (screen_annex()) { /* it will be ours! */
130 timer_startup();
131 render_startup();
132 font_startup();
133 themerc_startup();
134 engine_startup(themerc_engine);
135 python_startup();
136 openboxwrap_startup();
137 clientwrap_startup();
138 hooks_startup();
139 event_startup();
140 screen_startup();
141 focus_startup();
142 client_startup();
143 keyboard_startup();
144 pointer_startup();
145
146 /* load the user's settings */
147 if (!python_import("rc"))
148 g_warning("ERROR LOADING RC FILE");
149
150 HOOKFIRE(startup, "()");
151
152 /* get all the existing windows */
153 client_manage_all();
154
155 ob_state = State_Running;
156 while (!ob_shutdown) {
157 event_loop();
158 }
159 ob_state = State_Exiting;
160
161 client_unmanage_all();
162
163 HOOKFIRE(shutdown, "()");
164
165 pointer_shutdown();
166 keyboard_shutdown();
167 client_shutdown();
168 screen_shutdown();
169 event_shutdown();
170 hooks_shutdown();
171 clientwrap_shutdown();
172 openboxwrap_shutdown();
173 python_shutdown();
174 engine_shutdown();
175 themerc_shutdown();
176 render_shutdown();
177 timer_shutdown();
178 }
179
180 XCloseDisplay(ob_display);
181
182 /* XXX if (ob_restart) */
183
184 return 0;
185 }
186
187 void signal_handler(int signal)
188 {
189 switch (signal) {
190 case SIGUSR1:
191 g_message("Caught SIGUSR1 signal. Restarting.");
192 ob_shutdown = ob_restart = TRUE;
193 break;
194
195 case SIGCHLD:
196 wait(NULL);
197 break;
198
199 case SIGHUP:
200 case SIGINT:
201 case SIGTERM:
202 case SIGPIPE:
203 g_message("Caught signal %d. Exiting.", signal);
204 ob_shutdown = TRUE;
205 break;
206
207 case SIGFPE:
208 case SIGSEGV:
209 g_error("Caught signal %d. Aborting and dumping core.", signal);
210 }
211 }
This page took 0.039415 seconds and 3 git commands to generate.