]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
304d52c6f27abe3c7332458bdec5a82bd509af0b
11 #include "moveresize.h"
13 #include "extensions.h"
21 #include "render/render.h"
22 #include "render/font.h"
23 #include "render/theme.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
;
69 ob_state
= State_Starting
;
71 /* initialize the locale */
72 if (!setlocale(LC_ALL
, ""))
73 g_warning("Couldn't set locale from environment.\n");
74 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
75 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
76 textdomain(PACKAGE_NAME
);
78 /* start our event dispatcher and register for signals */
80 dispatch_register(Event_Signal
, signal_handler
, NULL
);
82 /* set up signal handler */
84 action
.sa_handler
= dispatch_signal
;
85 action
.sa_mask
= sigset
;
86 action
.sa_flags
= SA_NOCLDSTOP
;
87 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
88 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
89 sigaction(SIGSEGV
, &action
, (struct sigaction
*) NULL
);
90 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
91 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
92 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
93 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
95 /* create the ~/.openbox dir */
96 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
97 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
98 S_IROTH
| S_IWOTH
| S_IXOTH
));
100 /* create the ~/.openbox/themes dir */
101 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
102 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
103 S_IROTH
| S_IWOTH
| S_IXOTH
));
106 /* parse out command line args */
107 parse_args(argc
, argv
);
109 ob_display
= XOpenDisplay(NULL
);
110 if (ob_display
== NULL
) {
111 /* print a message and exit */
112 g_critical("Failed to open the display.");
115 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1) {
116 /* print a message and exit */
117 g_critical("Failed to set display as close-on-exec.");
121 ob_screen
= DefaultScreen(ob_display
);
122 ob_root
= RootWindow(ob_display
, ob_screen
);
124 /* XXX fork self onto other screens */
126 XSynchronize(ob_display
, ob_sync
);
128 /* check for locale support */
129 if (!XSupportsLocale())
130 g_warning("X server does not support locale.");
131 if (!XSetLocaleModifiers(""))
132 g_warning("Cannot set locale modifiers for the X server.");
134 /* set our error handler */
135 XSetErrorHandler(xerror_handler
);
137 /* set the DISPLAY environment variable for any lauched children, to the
138 display we're using, so they open in the right place. */
139 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
141 ob_cursors
.ptr
= XCreateFontCursor(ob_display
, XC_left_ptr
);
142 ob_cursors
.move
= XCreateFontCursor(ob_display
, XC_fleur
);
143 ob_cursors
.tl
= XCreateFontCursor(ob_display
, XC_top_left_corner
);
144 ob_cursors
.tr
= XCreateFontCursor(ob_display
, XC_top_right_corner
);
145 ob_cursors
.bl
= XCreateFontCursor(ob_display
, XC_bottom_left_corner
);
146 ob_cursors
.br
= XCreateFontCursor(ob_display
, XC_bottom_right_corner
);
147 ob_cursors
.t
= XCreateFontCursor(ob_display
, XC_top_side
);
148 ob_cursors
.r
= XCreateFontCursor(ob_display
, XC_right_side
);
149 ob_cursors
.b
= XCreateFontCursor(ob_display
, XC_bottom_side
);
150 ob_cursors
.l
= XCreateFontCursor(ob_display
, XC_left_side
);
152 prop_startup(); /* get atoms values for the display */
153 extensions_query_all(); /* find which extensions are present */
155 /* save stuff that we can use to restore state */
158 if (screen_annex()) { /* it will be ours! */
159 /* startup the parsing so everything can register sections of the rc */
162 /* anything that is going to read data from the rc file needs to be
171 /* load the plugins specified in the pluginrc */
174 /* set up the kernel config shit */
176 /* parse/load user options */
178 /* we're done with parsing now, kill it */
181 /* load the theme specified in the rc file */
182 theme
= theme_load(config_theme
);
184 if (!theme
) return 1;
189 moveresize_startup();
195 /* call startup for all the plugins */
198 /* get all the existing windows */
201 ob_state
= State_Running
;
204 ob_state
= State_Exiting
;
206 client_unmanage_all();
208 plugin_shutdown(); /* calls all the plugins' shutdown functions */
213 moveresize_shutdown();
227 XCloseDisplay(ob_display
);
230 if (ob_restart_path
!= NULL
) {
236 if (g_shell_parse_argv(ob_restart_path
, &argcp
, &argvp
, &err
)) {
237 execvp(argvp
[0], argvp
);
240 g_warning("failed to execute '%s': %s", ob_restart_path
,
246 execvp(argv
[0], argv
); /* try how we were run */
247 execlp(BINARY
, BINARY
, NULL
); /* try this as a last resort */
253 void signal_handler(const ObEvent
*e
, void *data
)
257 s
= e
->data
.s
.signal
;
260 g_message("Caught SIGUSR1 signal. Restarting.");
261 ob_shutdown
= ob_restart
= TRUE
;
268 g_message("Caught signal %d. Exiting.", s
);
274 g_error("Caught signal %d. Aborting and dumping core.", s
);
280 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
281 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
282 g_print("This is free software, and you are welcome to redistribute it\n");
283 g_print("under certain conditions. See the file COPYING for details.\n\n");
289 g_print("Syntax: %s [options]\n\n", BINARY
);
290 g_print("Options:\n\n");
291 g_print(" -rc PATH Specify the path to the rc file to use\n");
292 g_print(" -help Display this help and exit\n");
293 g_print(" -version Display the version and exit\n");
294 g_print(" -sync Run in synchronous mode (this is slow and meant\n"
295 " for debugging X routines)\n");
296 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
299 void parse_args(int argc
, char **argv
)
303 for (i
= 1; i
< argc
; ++i
) {
304 if (!strcmp(argv
[i
], "-version")) {
307 } else if (!strcmp(argv
[i
], "-help")) {
310 } else if (!strcmp(argv
[i
], "-sync")) {
312 } else if (!strcmp(argv
[i
], "-rc")) {
313 if (i
== argc
- 1) /* no args left */
314 g_printerr("-rc requires an argument\n");
316 ob_rc_path
= argv
[++i
];
318 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
325 gboolean
ob_pointer_pos(int *x
, int *y
)
331 return !!XQueryPointer(ob_display
, ob_root
, &w
, &w
, x
, y
, &i
, &i
, &u
);
This page took 0.048896 seconds and 3 git commands to generate.