]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
9 #include "extensions.h"
16 #include "../render/render.h"
17 #include "../render/font.h"
28 #ifdef HAVE_SYS_WAIT_H
29 # include <sys/types.h>
30 # include <sys/wait.h>
38 #ifdef HAVE_SYS_STAT_H
39 # include <sys/stat.h>
40 # include <sys/types.h>
43 #include <X11/cursorfont.h>
45 Display
*ob_display
= NULL
;
49 gboolean ob_shutdown
= FALSE
;
50 gboolean ob_restart
= FALSE
;
51 char *ob_restart_path
= NULL
;
52 gboolean ob_remote
= FALSE
;
53 gboolean ob_sync
= FALSE
;
55 char *ob_rc_path
= NULL
;
57 void signal_handler(const ObEvent
*e
, void *data
);
58 void parse_args(int argc
, char **argv
);
60 int main(int argc
, char **argv
)
62 struct sigaction action
;
66 ob_state
= State_Starting
;
68 /* initialize the locale */
69 if (!setlocale(LC_ALL
, ""))
70 g_warning("Couldn't set locale from environment.\n");
71 bindtextdomain(PACKAGE
, LOCALEDIR
);
72 bind_textdomain_codeset(PACKAGE
, "UTF-8");
75 /* start our event dispatcher and register for signals */
77 dispatch_register(Event_Signal
, signal_handler
, NULL
);
79 /* set up signal handler */
81 action
.sa_handler
= dispatch_signal
;
82 action
.sa_mask
= sigset
;
83 action
.sa_flags
= SA_NOCLDSTOP
;
84 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
85 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
86 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
87 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
88 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
89 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
90 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
91 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
93 /* anything that died while we were restarting won't give us a SIGCHLD */
94 while (waitpid(-1, NULL
, WNOHANG
) > 0);
96 /* create the ~/.openbox dir */
97 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
98 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
99 S_IROTH
| S_IWOTH
| S_IXOTH
));
102 /* parse out command line args */
103 parse_args(argc
, argv
);
105 ob_display
= XOpenDisplay(NULL
);
106 if (ob_display
== NULL
) {
107 /* print a message and exit */
108 g_critical("Failed to open the display.");
111 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
112 /* print a message and exit */
113 g_critical("Failed to set display as close-on-exec.");
117 ob_screen
= DefaultScreen(ob_display
);
118 ob_root
= RootWindow(ob_display
, ob_screen
);
120 /* XXX fork self onto other screens */
122 XSynchronize(ob_display
, ob_sync
);
124 /* check for locale support */
125 if (!XSupportsLocale())
126 g_warning("X server does not support locale.");
127 if (!XSetLocaleModifiers(""))
128 g_warning("Cannot set locale modifiers for the X server.");
130 /* set our error handler */
131 XSetErrorHandler(xerror_handler
);
133 /* set the DISPLAY environment variable for any lauched children, to the
134 display we're using, so they open in the right place. */
135 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
137 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
138 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
139 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
141 prop_startup(); /* get atoms values for the display */
142 extensions_query_all(); /* find which extensions are present */
144 if (screen_annex()) { /* it will be ours! */
149 engine_startup(themerc_engine
);
157 /* XXX load all plugins!! */
158 plugin_open("focus");
159 plugin_open("keyboard");
160 plugin_open("mouse");
161 plugin_open("placement");
162 plugin_open("resistance");
164 /* get all the existing windows */
167 ob_state
= State_Running
;
170 ob_state
= State_Exiting
;
172 client_unmanage_all();
174 plugin_shutdown(); /* calls all the plugins' shutdown functions */
188 XCloseDisplay(ob_display
);
191 if (ob_restart_path
!= NULL
) {
197 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
198 execvp(argvp
[0], argvp
);
201 g_warning("failed to execute '%s': %s", ob_restart_path
,
207 execvp(argv
[0], argv
); /* try how we were run */
208 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
214 void signal_handler(const ObEvent
*e
, void *data
)
218 s
= e
->data
.s
.signal
;
221 g_message("Caught SIGUSR1 signal. Restarting.");
222 ob_shutdown
= ob_restart
= TRUE
;
233 g_message("Caught signal %d. Exiting.", s
);
239 g_error("Caught signal %d. Aborting and dumping core.", s
);
245 g_print("Openbox %s\n\n", VERSION
);
246 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
247 g_print("This is free software, and you are welcome to redistribute it\n");
248 g_print("under certain conditions. See the file COPYING for details.\n\n");
254 g_print("Syntax: %s [options]\n\n", BINARY
);
255 g_print("Options:\n\n");
256 g_print(" -rc PATH Specify the path to the rc file to use\n");
257 g_print(" -help Display this help and exit\n");
258 g_print(" -version Display the version and exit\n");
259 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
260 " for debugging X routines)\n");
261 g_print("\nPlease report bugs at %s\n", BUGURL
);
264 void parse_args(int argc
, char **argv
)
268 for (i
= 1; i
< argc
; ++i
) {
269 if (!strcmp(argv
[i
], "-version")) {
272 } else if (!strcmp(argv
[i
], "-help")) {
275 } else if (!strcmp(argv
[i
], "-sync")) {
277 } else if (!strcmp(argv
[i
], "-rc")) {
278 if (i
== argc
- 1) /* no args left */
279 g_printerr("-rc requires an argument\n");
281 ob_rc_path
= argv
[++i
];
283 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
This page took 0.047309 seconds and 4 git commands to generate.