]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
9 #include "extensions.h"
17 #include "../render/render.h"
18 #include "../render/font.h"
29 #ifdef HAVE_SYS_WAIT_H
30 # include <sys/types.h>
31 # include <sys/wait.h>
39 #ifdef HAVE_SYS_STAT_H
40 # include <sys/stat.h>
41 # include <sys/types.h>
44 #include <X11/cursorfont.h>
46 Display
*ob_display
= NULL
;
50 gboolean ob_shutdown
= FALSE
;
51 gboolean ob_restart
= FALSE
;
52 char *ob_restart_path
= NULL
;
53 gboolean ob_remote
= TRUE
;
54 gboolean ob_sync
= FALSE
;
56 char *ob_rc_path
= NULL
;
58 void signal_handler(const ObEvent
*e
, void *data
);
59 void parse_args(int argc
, char **argv
);
61 int main(int argc
, char **argv
)
63 struct sigaction action
;
67 ob_state
= State_Starting
;
69 /* initialize the locale */
70 if (!setlocale(LC_ALL
, ""))
71 g_warning("Couldn't set locale from environment.\n");
72 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
73 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
74 textdomain(PACKAGE_NAME
);
76 /* start our event dispatcher and register for signals */
78 dispatch_register(Event_Signal
, signal_handler
, NULL
);
80 /* set up signal handler */
82 action
.sa_handler
= dispatch_signal
;
83 action
.sa_mask
= sigset
;
84 action
.sa_flags
= SA_NOCLDSTOP
;
85 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
86 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
87 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
88 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
89 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
90 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
91 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
92 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
94 /* anything that died while we were restarting won't give us a SIGCHLD */
95 while (waitpid(-1, NULL
, WNOHANG
) > 0);
97 /* create the ~/.openbox dir */
98 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
99 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
100 S_IROTH
| S_IWOTH
| S_IXOTH
));
102 /* create the ~/.openbox/themes dir */
103 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
104 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
105 S_IROTH
| S_IWOTH
| S_IXOTH
));
108 /* parse out command line args */
109 parse_args(argc
, argv
);
111 ob_display
= XOpenDisplay(NULL
);
112 if (ob_display
== NULL
) {
113 /* print a message and exit */
114 g_critical("Failed to open the display.");
117 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
118 /* print a message and exit */
119 g_critical("Failed to set display as close-on-exec.");
123 ob_screen
= DefaultScreen(ob_display
);
124 ob_root
= RootWindow(ob_display
, ob_screen
);
126 /* XXX fork self onto other screens */
128 XSynchronize(ob_display
, ob_sync
);
130 /* check for locale support */
131 if (!XSupportsLocale())
132 g_warning("X server does not support locale.");
133 if (!XSetLocaleModifiers(""))
134 g_warning("Cannot set locale modifiers for the X server.");
136 /* set our error handler */
137 XSetErrorHandler(xerror_handler
);
139 /* set the DISPLAY environment variable for any lauched children, to the
140 display we're using, so they open in the right place. */
141 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
143 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
144 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
145 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
147 prop_startup(); /* get atoms values for the display */
148 extensions_query_all(); /* find which extensions are present */
150 if (screen_annex()) { /* it will be ours! */
157 /* startup the parsing so plugins can register sections of the rc */
160 /* load the plugins specified in the pluginrc */
162 /* parse/load user options */
165 /* we're done with parsing now, kill it */
175 /* call startup for all the plugins */
178 /* get all the existing windows */
181 ob_state
= State_Running
;
184 ob_state
= State_Exiting
;
186 client_unmanage_all();
188 plugin_shutdown(); /* calls all the plugins' shutdown functions */
202 XCloseDisplay(ob_display
);
205 if (ob_restart_path
!= NULL
) {
211 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
212 execvp(argvp
[0], argvp
);
215 g_warning("failed to execute '%s': %s", ob_restart_path
,
221 execvp(argv
[0], argv
); /* try how we were run */
222 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
228 void signal_handler(const ObEvent
*e
, void *data
)
232 s
= e
->data
.s
.signal
;
235 g_message("Caught SIGUSR1 signal. Restarting.");
236 ob_shutdown
= ob_restart
= TRUE
;
247 g_message("Caught signal %d. Exiting.", s
);
253 g_error("Caught signal %d. Aborting and dumping core.", s
);
259 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
260 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
261 g_print("This is free software, and you are welcome to redistribute it\n");
262 g_print("under certain conditions. See the file COPYING for details.\n\n");
268 g_print("Syntax: %s [options]\n\n", BINARY
);
269 g_print("Options:\n\n");
270 g_print(" -rc PATH Specify the path to the rc file to use\n");
271 g_print(" -help Display this help and exit\n");
272 g_print(" -version Display the version and exit\n");
273 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
274 " for debugging X routines)\n");
275 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
278 void parse_args(int argc
, char **argv
)
282 for (i
= 1; i
< argc
; ++i
) {
283 if (!strcmp(argv
[i
], "-version")) {
286 } else if (!strcmp(argv
[i
], "-help")) {
289 } else if (!strcmp(argv
[i
], "-sync")) {
291 } else if (!strcmp(argv
[i
], "-rc")) {
292 if (i
== argc
- 1) /* no args left */
293 g_printerr("-rc requires an argument\n");
295 ob_rc_path
= argv
[++i
];
297 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
This page took 0.051625 seconds and 4 git commands to generate.