]>
Dogcows Code - chaz/openbox/blob - openbox.c
611094ad5e05efe809d838e291744b51c09ef273
11 #include "extensions.h"
19 #include "render/render.h"
20 #include "render/font.h"
21 #include "render/theme.h"
32 #ifdef HAVE_SYS_WAIT_H
33 # include <sys/types.h>
34 # include <sys/wait.h>
42 #ifdef HAVE_SYS_STAT_H
43 # include <sys/stat.h>
44 # include <sys/types.h>
47 #include <X11/cursorfont.h>
49 Display
*ob_display
= NULL
;
53 gboolean ob_shutdown
= FALSE
;
54 gboolean ob_restart
= FALSE
;
55 char *ob_restart_path
= NULL
;
56 gboolean ob_remote
= TRUE
;
57 gboolean ob_sync
= FALSE
;
59 char *ob_rc_path
= NULL
;
61 void signal_handler(const ObEvent
*e
, void *data
);
62 void parse_args(int argc
, char **argv
);
64 int main(int argc
, char **argv
)
66 struct sigaction action
;
71 ob_state
= State_Starting
;
73 /* initialize the locale */
74 if (!setlocale(LC_ALL
, ""))
75 g_warning("Couldn't set locale from environment.\n");
76 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
77 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
78 textdomain(PACKAGE_NAME
);
80 /* start our event dispatcher and register for signals */
82 dispatch_register(Event_Signal
, signal_handler
, NULL
);
84 /* set up signal handler */
86 action
.sa_handler
= dispatch_signal
;
87 action
.sa_mask
= sigset
;
88 action
.sa_flags
= SA_NOCLDSTOP
;
89 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
90 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
91 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
92 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
93 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
94 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
95 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
96 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
98 /* anything that died while we were restarting won't give us a SIGCHLD */
99 while (waitpid(-1, NULL
, WNOHANG
) > 0);
101 /* create the ~/.openbox dir */
102 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
103 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
104 S_IROTH
| S_IWOTH
| S_IXOTH
));
106 /* create the ~/.openbox/themes dir */
107 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
108 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
109 S_IROTH
| S_IWOTH
| S_IXOTH
));
112 /* parse out command line args */
113 parse_args(argc
, argv
);
115 ob_display
= XOpenDisplay(NULL
);
116 if (ob_display
== NULL
) {
117 /* print a message and exit */
118 g_critical("Failed to open the display.");
121 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
122 /* print a message and exit */
123 g_critical("Failed to set display as close-on-exec.");
127 ob_screen
= DefaultScreen(ob_display
);
128 ob_root
= RootWindow(ob_display
, ob_screen
);
130 /* XXX fork self onto other screens */
132 XSynchronize(ob_display
, ob_sync
);
134 /* check for locale support */
135 if (!XSupportsLocale())
136 g_warning("X server does not support locale.");
137 if (!XSetLocaleModifiers(""))
138 g_warning("Cannot set locale modifiers for the X server.");
140 /* set our error handler */
141 XSetErrorHandler(xerror_handler
);
143 /* set the DISPLAY environment variable for any lauched children, to the
144 display we're using, so they open in the right place. */
145 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
147 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
148 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
149 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
151 prop_startup(); /* get atoms values for the display */
152 extensions_query_all(); /* find which extensions are present */
154 if (screen_annex()) { /* it will be ours! */
155 /* startup the parsing so everything can register sections of the rc */
158 /* anything that is going to read data from the rc file needs to be
167 /* load the plugins specified in the pluginrc */
170 /* set up the kernel config shit */
172 /* parse/load user options */
174 /* we're done with parsing now, kill it */
177 /* load the theme specified in the rc file */
178 theme
= theme_load(config_theme
);
180 if (!theme
) return 1;
189 /* call startup for all the plugins */
192 /* get all the existing windows */
195 ob_state
= State_Running
;
198 ob_state
= State_Exiting
;
200 client_unmanage_all();
202 plugin_shutdown(); /* calls all the plugins' shutdown functions */
219 XCloseDisplay(ob_display
);
222 if (ob_restart_path
!= NULL
) {
228 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
229 execvp(argvp
[0], argvp
);
232 g_warning("failed to execute '%s': %s", ob_restart_path
,
238 execvp(argv
[0], argv
); /* try how we were run */
239 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
245 void signal_handler(const ObEvent
*e
, void *data
)
249 s
= e
->data
.s
.signal
;
252 g_message("Caught SIGUSR1 signal. Restarting.");
253 ob_shutdown
= ob_restart
= TRUE
;
264 g_message("Caught signal %d. Exiting.", s
);
270 g_error("Caught signal %d. Aborting and dumping core.", s
);
276 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
277 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
278 g_print("This is free software, and you are welcome to redistribute it\n");
279 g_print("under certain conditions. See the file COPYING for details.\n\n");
285 g_print("Syntax: %s [options]\n\n", BINARY
);
286 g_print("Options:\n\n");
287 g_print(" -rc PATH Specify the path to the rc file to use\n");
288 g_print(" -help Display this help and exit\n");
289 g_print(" -version Display the version and exit\n");
290 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
291 " for debugging X routines)\n");
292 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
295 void parse_args(int argc
, char **argv
)
299 for (i
= 1; i
< argc
; ++i
) {
300 if (!strcmp(argv
[i
], "-version")) {
303 } else if (!strcmp(argv
[i
], "-help")) {
306 } else if (!strcmp(argv
[i
], "-sync")) {
308 } else if (!strcmp(argv
[i
], "-rc")) {
309 if (i
== argc
- 1) /* no args left */
310 g_printerr("-rc requires an argument\n");
312 ob_rc_path
= argv
[++i
];
314 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
This page took 0.048155 seconds and 3 git commands to generate.