]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
9 #include "extensions.h"
18 #include "../render/render.h"
19 #include "../render/font.h"
30 #ifdef HAVE_SYS_WAIT_H
31 # include <sys/types.h>
32 # include <sys/wait.h>
40 #ifdef HAVE_SYS_STAT_H
41 # include <sys/stat.h>
42 # include <sys/types.h>
45 #include <X11/cursorfont.h>
47 Display
*ob_display
= NULL
;
51 gboolean ob_shutdown
= FALSE
;
52 gboolean ob_restart
= FALSE
;
53 char *ob_restart_path
= NULL
;
54 gboolean ob_remote
= TRUE
;
55 gboolean ob_sync
= FALSE
;
57 char *ob_rc_path
= NULL
;
59 void signal_handler(const ObEvent
*e
, void *data
);
60 void parse_args(int argc
, char **argv
);
62 int main(int argc
, char **argv
)
64 struct sigaction action
;
68 ob_state
= State_Starting
;
70 /* initialize the locale */
71 if (!setlocale(LC_ALL
, ""))
72 g_warning("Couldn't set locale from environment.\n");
73 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
74 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
75 textdomain(PACKAGE_NAME
);
77 /* start our event dispatcher and register for signals */
79 dispatch_register(Event_Signal
, signal_handler
, NULL
);
81 /* set up signal handler */
83 action
.sa_handler
= dispatch_signal
;
84 action
.sa_mask
= sigset
;
85 action
.sa_flags
= SA_NOCLDSTOP
;
86 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
87 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
88 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
89 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
90 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
91 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
92 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
93 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
95 /* anything that died while we were restarting won't give us a SIGCHLD */
96 while (waitpid(-1, NULL
, WNOHANG
) > 0);
98 /* create the ~/.openbox dir */
99 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
100 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
101 S_IROTH
| S_IWOTH
| S_IXOTH
));
103 /* create the ~/.openbox/themes dir */
104 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
105 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
106 S_IROTH
| S_IWOTH
| S_IXOTH
));
109 /* parse out command line args */
110 parse_args(argc
, argv
);
112 ob_display
= XOpenDisplay(NULL
);
113 if (ob_display
== NULL
) {
114 /* print a message and exit */
115 g_critical("Failed to open the display.");
118 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
119 /* print a message and exit */
120 g_critical("Failed to set display as close-on-exec.");
124 ob_screen
= DefaultScreen(ob_display
);
125 ob_root
= RootWindow(ob_display
, ob_screen
);
127 /* XXX fork self onto other screens */
129 XSynchronize(ob_display
, ob_sync
);
131 /* check for locale support */
132 if (!XSupportsLocale())
133 g_warning("X server does not support locale.");
134 if (!XSetLocaleModifiers(""))
135 g_warning("Cannot set locale modifiers for the X server.");
137 /* set our error handler */
138 XSetErrorHandler(xerror_handler
);
140 /* set the DISPLAY environment variable for any lauched children, to the
141 display we're using, so they open in the right place. */
142 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
144 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
145 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
146 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
148 prop_startup(); /* get atoms values for the display */
149 extensions_query_all(); /* find which extensions are present */
151 if (screen_annex()) { /* it will be ours! */
152 /* startup the parsing so everything can register sections of the rc */
155 /* anything that is going to read data from the rc file needs to be
164 /* load the plugins specified in the pluginrc */
167 /* set up the kernel config shit */
169 /* parse/load user options */
171 /* we're done with parsing now, kill it */
174 /* load the engine specified in the rc */
182 /* call startup for all the plugins */
185 /* get all the existing windows */
188 ob_state
= State_Running
;
191 ob_state
= State_Exiting
;
193 client_unmanage_all();
195 plugin_shutdown(); /* calls all the plugins' shutdown functions */
210 XCloseDisplay(ob_display
);
213 if (ob_restart_path
!= NULL
) {
219 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
220 execvp(argvp
[0], argvp
);
223 g_warning("failed to execute '%s': %s", ob_restart_path
,
229 execvp(argv
[0], argv
); /* try how we were run */
230 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
236 void signal_handler(const ObEvent
*e
, void *data
)
240 s
= e
->data
.s
.signal
;
243 g_message("Caught SIGUSR1 signal. Restarting.");
244 ob_shutdown
= ob_restart
= TRUE
;
255 g_message("Caught signal %d. Exiting.", s
);
261 g_error("Caught signal %d. Aborting and dumping core.", s
);
267 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
268 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
269 g_print("This is free software, and you are welcome to redistribute it\n");
270 g_print("under certain conditions. See the file COPYING for details.\n\n");
276 g_print("Syntax: %s [options]\n\n", BINARY
);
277 g_print("Options:\n\n");
278 g_print(" -rc PATH Specify the path to the rc file to use\n");
279 g_print(" -help Display this help and exit\n");
280 g_print(" -version Display the version and exit\n");
281 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
282 " for debugging X routines)\n");
283 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
286 void parse_args(int argc
, char **argv
)
290 for (i
= 1; i
< argc
; ++i
) {
291 if (!strcmp(argv
[i
], "-version")) {
294 } else if (!strcmp(argv
[i
], "-help")) {
297 } else if (!strcmp(argv
[i
], "-sync")) {
299 } else if (!strcmp(argv
[i
], "-rc")) {
300 if (i
== argc
- 1) /* no args left */
301 g_printerr("-rc requires an argument\n");
303 ob_rc_path
= argv
[++i
];
305 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
This page took 0.048058 seconds and 4 git commands to generate.