]>
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>
39 #include <X11/cursorfont.h>
41 Display
*ob_display
= NULL
;
45 gboolean ob_shutdown
= FALSE
;
46 gboolean ob_restart
= FALSE
;
47 char *ob_restart_path
= NULL
;
48 gboolean ob_remote
= FALSE
;
49 gboolean ob_sync
= FALSE
;
51 char *ob_rc_path
= NULL
;
53 void signal_handler(const ObEvent
*e
, void *data
);
54 void parse_args(int argc
, char **argv
);
56 int main(int argc
, char **argv
)
58 struct sigaction action
;
61 ob_state
= State_Starting
;
63 /* initialize the locale */
64 if (!setlocale(LC_ALL
, ""))
65 g_warning("Couldn't set locale from environment.\n");
66 bindtextdomain(PACKAGE
, LOCALEDIR
);
67 bind_textdomain_codeset(PACKAGE
, "UTF-8");
70 /* start our event dispatcher and register for signals */
72 dispatch_register(Event_Signal
, signal_handler
, NULL
);
74 /* set up signal handler */
76 action
.sa_handler
= dispatch_signal
;
77 action
.sa_mask
= sigset
;
78 action
.sa_flags
= SA_NOCLDSTOP
;
79 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
80 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
81 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
82 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
83 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
84 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
85 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
86 sigaction(SIGCHLD
, &action
, (struct sigaction
*) NULL
);
88 /* anything that died while we were restarting won't give us a SIGCHLD */
89 while (waitpid(-1, NULL
, WNOHANG
) > 0);
91 /* parse out command line args */
92 parse_args(argc
, argv
);
94 ob_display
= XOpenDisplay(NULL
);
95 if (ob_display
== NULL
) {
96 /* print a message and exit */
97 g_critical("Failed to open the display.");
100 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
101 /* print a message and exit */
102 g_critical("Failed to set display as close-on-exec.");
106 ob_screen
= DefaultScreen(ob_display
);
107 ob_root
= RootWindow(ob_display
, ob_screen
);
109 /* XXX fork self onto other screens */
111 XSynchronize(ob_display
, ob_sync
);
113 /* check for locale support */
114 if (!XSupportsLocale())
115 g_warning("X server does not support locale.");
116 if (!XSetLocaleModifiers(""))
117 g_warning("Cannot set locale modifiers for the X server.");
119 /* set our error handler */
120 XSetErrorHandler(xerror_handler
);
122 /* set the DISPLAY environment variable for any lauched children, to the
123 display we're using, so they open in the right place. */
124 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
126 ob_cursors
.left_ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
127 ob_cursors
.ll_angle
= XCreateFontCursor(ob_display
, XC_ll_angle
);
128 ob_cursors
.lr_angle
= XCreateFontCursor(ob_display
, XC_lr_angle
);
130 prop_startup(); /* get atoms values for the display */
131 extensions_query_all(); /* find which extensions are present */
133 if (screen_annex()) { /* it will be ours! */
138 engine_startup(themerc_engine
);
146 /* XXX load all plugins!! */
147 plugin_open("focus");
148 plugin_open("keyboard");
149 plugin_open("mouse");
150 plugin_open("placement");
151 plugin_open("resistance");
153 /* get all the existing windows */
156 ob_state
= State_Running
;
159 ob_state
= State_Exiting
;
161 client_unmanage_all();
163 plugin_shutdown(); /* calls all the plugins' shutdown functions */
177 XCloseDisplay(ob_display
);
180 if (ob_restart_path
!= NULL
) {
186 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
187 execvp(argvp
[0], argvp
);
190 g_warning("failed to execute '%s': %s", ob_restart_path
,
196 execvp(argv
[0], argv
); /* try how we were run */
197 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
203 void signal_handler(const ObEvent
*e
, void *data
)
207 s
= e
->data
.s
.signal
;
210 g_message("Caught SIGUSR1 signal. Restarting.");
211 ob_shutdown
= ob_restart
= TRUE
;
222 g_message("Caught signal %d. Exiting.", s
);
228 g_error("Caught signal %d. Aborting and dumping core.", s
);
234 g_print("Openbox %s\n\n", VERSION
);
235 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
236 g_print("This is free software, and you are welcome to redistribute it\n");
237 g_print("under certain conditions. See the file COPYING for details.\n\n");
243 g_print("Syntax: %s [options]\n\n", BINARY
);
244 g_print("Options:\n\n");
245 g_print(" -rc PATH Specify the path to the rc file to use\n");
246 g_print(" -help Display this help and exit\n");
247 g_print(" -version Display the version and exit\n");
248 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
249 " for debugging X routines)\n");
250 g_print("\nPlease report bugs at %s\n", BUGURL
);
253 void parse_args(int argc
, char **argv
)
257 for (i
= 1; i
< argc
; ++i
) {
258 if (!strcmp(argv
[i
], "-version")) {
261 } else if (!strcmp(argv
[i
], "-help")) {
264 } else if (!strcmp(argv
[i
], "-sync")) {
266 } else if (!strcmp(argv
[i
], "-rc")) {
267 if (i
== argc
- 1) /* no args left */
268 g_printerr("-rc requires an argument\n");
270 ob_rc_path
= argv
[++i
];
272 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
This page took 0.046262 seconds and 5 git commands to generate.