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