]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
10 #include "extensions.h"
18 #include "render/render.h"
19 #include "render/font.h"
20 #include "render/theme.h"
31 #ifdef HAVE_SYS_WAIT_H
32 # include <sys/types.h>
33 # include <sys/wait.h>
41 #ifdef HAVE_SYS_STAT_H
42 # include <sys/stat.h>
43 # include <sys/types.h>
46 #include <X11/cursorfont.h>
48 Display
*ob_display
= NULL
;
52 gboolean ob_shutdown
= FALSE
;
53 gboolean ob_restart
= FALSE
;
54 char *ob_restart_path
= NULL
;
55 gboolean ob_remote
= TRUE
;
56 gboolean ob_sync
= FALSE
;
58 char *ob_rc_path
= NULL
;
60 void signal_handler(const ObEvent
*e
, void *data
);
61 void parse_args(int argc
, char **argv
);
63 int main(int argc
, char **argv
)
65 struct sigaction action
;
70 ob_state
= State_Starting
;
72 /* initialize the locale */
73 if (!setlocale(LC_ALL
, ""))
74 g_warning("Couldn't set locale from environment.\n");
75 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
76 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
77 textdomain(PACKAGE_NAME
);
79 /* start our event dispatcher and register for signals */
81 dispatch_register(Event_Signal
, signal_handler
, NULL
);
83 /* set up signal handler */
85 action
.sa_handler
= dispatch_signal
;
86 action
.sa_mask
= sigset
;
87 action
.sa_flags
= SA_NOCLDSTOP
;
88 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
89 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
90 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
91 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
92 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
93 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
94 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
95 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
97 /* anything that died while we were restarting won't give us a SIGCHLD */
98 while (waitpid(-1, NULL
, WNOHANG
) > 0);
100 /* create the ~/.openbox dir */
101 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
102 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
103 S_IROTH
| S_IWOTH
| S_IXOTH
));
105 /* create the ~/.openbox/themes dir */
106 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
107 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
108 S_IROTH
| S_IWOTH
| S_IXOTH
));
111 /* parse out command line args */
112 parse_args(argc
, argv
);
114 ob_display
= XOpenDisplay(NULL
);
115 if (ob_display
== NULL
) {
116 /* print a message and exit */
117 g_critical("Failed to open the display.");
120 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
121 /* print a message and exit */
122 g_critical("Failed to set display as close-on-exec.");
126 ob_screen
= DefaultScreen(ob_display
);
127 ob_root
= RootWindow(ob_display
, ob_screen
);
129 /* XXX fork self onto other screens */
131 XSynchronize(ob_display
, ob_sync
);
133 /* check for locale support */
134 if (!XSupportsLocale())
135 g_warning("X server does not support locale.");
136 if (!XSetLocaleModifiers(""))
137 g_warning("Cannot set locale modifiers for the X server.");
139 /* set our error handler */
140 XSetErrorHandler(xerror_handler
);
142 /* set the DISPLAY environment variable for any lauched children, to the
143 display we're using, so they open in the right place. */
144 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
146 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
147 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
148 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
150 prop_startup(); /* get atoms values for the display */
151 extensions_query_all(); /* find which extensions are present */
153 if (screen_annex()) { /* it will be ours! */
154 /* startup the parsing so everything can register sections of the rc */
157 /* anything that is going to read data from the rc file needs to be
166 /* load the plugins specified in the pluginrc */
169 /* set up the kernel config shit */
171 /* parse/load user options */
173 /* we're done with parsing now, kill it */
176 /* load the theme specified in the rc file */
177 theme
= theme_load(config_theme
);
179 if (!theme
) return 1;
187 /* call startup for all the plugins */
190 /* get all the existing windows */
193 ob_state
= State_Running
;
196 ob_state
= State_Exiting
;
198 client_unmanage_all();
200 plugin_shutdown(); /* calls all the plugins' shutdown functions */
216 XCloseDisplay(ob_display
);
219 if (ob_restart_path
!= NULL
) {
225 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
226 execvp(argvp
[0], argvp
);
229 g_warning("failed to execute '%s': %s", ob_restart_path
,
235 execvp(argv
[0], argv
); /* try how we were run */
236 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
242 void signal_handler(const ObEvent
*e
, void *data
)
246 s
= e
->data
.s
.signal
;
249 g_message("Caught SIGUSR1 signal. Restarting.");
250 ob_shutdown
= ob_restart
= TRUE
;
261 g_message("Caught signal %d. Exiting.", s
);
267 g_error("Caught signal %d. Aborting and dumping core.", s
);
273 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
274 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
275 g_print("This is free software, and you are welcome to redistribute it\n");
276 g_print("under certain conditions. See the file COPYING for details.\n\n");
282 g_print("Syntax: %s [options]\n\n", BINARY
);
283 g_print("Options:\n\n");
284 g_print(" -rc PATH Specify the path to the rc file to use\n");
285 g_print(" -help Display this help and exit\n");
286 g_print(" -version Display the version and exit\n");
287 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
288 " for debugging X routines)\n");
289 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
292 void parse_args(int argc
, char **argv
)
296 for (i
= 1; i
< argc
; ++i
) {
297 if (!strcmp(argv
[i
], "-version")) {
300 } else if (!strcmp(argv
[i
], "-help")) {
303 } else if (!strcmp(argv
[i
], "-sync")) {
305 } else if (!strcmp(argv
[i
], "-rc")) {
306 if (i
== argc
- 1) /* no args left */
307 g_printerr("-rc requires an argument\n");
309 ob_rc_path
= argv
[++i
];
311 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
This page took 0.052635 seconds and 4 git commands to generate.