]> Dogcows Code - chaz/openbox/blob - openbox/openbox.c
merge the C branch into HEAD
[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 themerc_startup();
133 engine_startup(themerc_engine);
134 python_startup();
135 openboxwrap_startup();
136 clientwrap_startup();
137 hooks_startup();
138 event_startup();
139 screen_startup();
140 focus_startup();
141 client_startup();
142 keyboard_startup();
143 pointer_startup();
144
145 /* load the user's settings */
146 if (!python_import("rc"))
147 g_warning("ERROR LOADING RC FILE");
148
149 HOOKFIRE(startup, "()");
150
151 /* get all the existing windows */
152 client_manage_all();
153
154 ob_state = State_Running;
155 while (!ob_shutdown) {
156 event_loop();
157 }
158 ob_state = State_Exiting;
159
160 client_unmanage_all();
161
162 HOOKFIRE(shutdown, "()");
163
164 pointer_shutdown();
165 keyboard_shutdown();
166 client_shutdown();
167 screen_shutdown();
168 event_shutdown();
169 hooks_shutdown();
170 clientwrap_shutdown();
171 openboxwrap_shutdown();
172 python_shutdown();
173 engine_shutdown();
174 themerc_shutdown();
175 render_shutdown();
176 timer_shutdown();
177 }
178
179 XCloseDisplay(ob_display);
180
181 /* XXX if (ob_restart) */
182
183 return 0;
184 }
185
186 void signal_handler(int signal)
187 {
188 switch (signal) {
189 case SIGUSR1:
190 g_message("Caught SIGUSR1 signal. Restarting.");
191 ob_shutdown = ob_restart = TRUE;
192 break;
193
194 case SIGCHLD:
195 wait(NULL);
196 break;
197
198 case SIGHUP:
199 case SIGINT:
200 case SIGTERM:
201 case SIGPIPE:
202 g_message("Caught signal %d. Exiting.", signal);
203 ob_shutdown = TRUE;
204 break;
205
206 case SIGFPE:
207 case SIGSEGV:
208 g_error("Caught signal %d. Aborting and dumping core.", signal);
209 }
210 }
This page took 0.044589 seconds and 4 git commands to generate.