]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
11 #include "startupnotify.h"
13 #include "moveresize.h"
17 #include "extensions.h"
18 #include "menuframe.h"
24 #include "parser/parse.h"
25 #include "render/render.h"
26 #include "render/theme.h"
41 #ifdef HAVE_SYS_STAT_H
42 # include <sys/stat.h>
43 # include <sys/types.h>
49 #include <X11/cursorfont.h>
51 RrInstance
*ob_rr_inst
;
53 ObMainLoop
*ob_main_loop
;
56 gboolean ob_sm_use
= TRUE
;
58 gboolean ob_replace_wm
;
61 static gboolean xsync
;
62 static gboolean reconfigure
;
63 static gboolean restart
;
64 static char *restart_path
;
65 static Cursor cursors
[OB_NUM_CURSORS
];
66 static KeyCode keys
[OB_NUM_KEYS
];
67 static gchar
*sm_save_file
;
69 static void signal_handler(int signal
, gpointer data
);
70 static void parse_args(int argc
, char **argv
);
72 int main(int argc
, char **argv
)
77 ob_debug_show_output(TRUE
);
80 state
= OB_STATE_STARTING
;
82 /* initialize the locale */
83 if (!setlocale(LC_ALL
, ""))
84 g_warning("Couldn't set locale from environment.\n");
85 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
86 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
87 textdomain(PACKAGE_NAME
);
89 /* create the ~/.openbox dir */
90 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
91 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
92 S_IROTH
| S_IWOTH
| S_IXOTH
));
94 /* create the ~/.openbox/themes dir */
95 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
96 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
97 S_IROTH
| S_IWOTH
| S_IXOTH
));
99 /* create the ~/.openbox/sessions dir */
100 path
= g_build_filename(g_get_home_dir(), ".openbox", "sessions", NULL
);
101 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
102 S_IROTH
| S_IWOTH
| S_IXOTH
));
105 g_set_prgname(argv
[0]);
107 /* parse out command line args */
108 parse_args(argc
, argv
);
110 ob_display
= XOpenDisplay(NULL
);
111 if (ob_display
== NULL
)
112 ob_exit_with_error("Failed to open the display.");
113 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1)
114 ob_exit_with_error("Failed to set display as close-on-exec.");
116 ob_main_loop
= ob_main_loop_new(ob_display
);
118 /* set up signal handler */
119 ob_main_loop_signal_add(ob_main_loop
, SIGUSR1
, signal_handler
, NULL
, NULL
);
120 ob_main_loop_signal_add(ob_main_loop
, SIGUSR2
, signal_handler
, NULL
, NULL
);
121 ob_main_loop_signal_add(ob_main_loop
, SIGTERM
, signal_handler
, NULL
, NULL
);
122 ob_main_loop_signal_add(ob_main_loop
, SIGINT
, signal_handler
, NULL
, NULL
);
123 ob_main_loop_signal_add(ob_main_loop
, SIGHUP
, signal_handler
, NULL
, NULL
);
124 ob_main_loop_signal_add(ob_main_loop
, SIGPIPE
, signal_handler
, NULL
, NULL
);
127 session_load(sm_save_file
);
128 session_startup(argc
, argv
);
130 ob_screen
= DefaultScreen(ob_display
);
132 ob_rr_inst
= RrInstanceNew(ob_display
, ob_screen
);
133 if (ob_rr_inst
== NULL
)
134 ob_exit_with_error("Failed to initialize the render library.");
136 /* XXX fork self onto other screens */
138 XSynchronize(ob_display
, xsync
);
140 /* check for locale support */
141 if (!XSupportsLocale())
142 g_warning("X server does not support locale.");
143 if (!XSetLocaleModifiers(""))
144 g_warning("Cannot set locale modifiers for the X server.");
146 /* set our error handler */
147 XSetErrorHandler(xerror_handler
);
149 /* set the DISPLAY environment variable for any lauched children, to the
150 display we're using, so they open in the right place. */
151 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
153 /* create available cursors */
154 cursors
[OB_CURSOR_NONE
] = None
;
155 cursors
[OB_CURSOR_POINTER
] =
156 XCreateFontCursor(ob_display
, XC_left_ptr
);
157 cursors
[OB_CURSOR_BUSY
] =
158 XCreateFontCursor(ob_display
, XC_watch
);
159 cursors
[OB_CURSOR_MOVE
] =
160 XCreateFontCursor(ob_display
, XC_fleur
);
161 cursors
[OB_CURSOR_NORTH
] =
162 XCreateFontCursor(ob_display
, XC_top_side
);
163 cursors
[OB_CURSOR_NORTHEAST
] =
164 XCreateFontCursor(ob_display
, XC_top_right_corner
);
165 cursors
[OB_CURSOR_EAST
] =
166 XCreateFontCursor(ob_display
, XC_right_side
);
167 cursors
[OB_CURSOR_SOUTHEAST
] =
168 XCreateFontCursor(ob_display
, XC_bottom_right_corner
);
169 cursors
[OB_CURSOR_SOUTH
] =
170 XCreateFontCursor(ob_display
, XC_bottom_side
);
171 cursors
[OB_CURSOR_SOUTHWEST
] =
172 XCreateFontCursor(ob_display
, XC_bottom_left_corner
);
173 cursors
[OB_CURSOR_WEST
] =
174 XCreateFontCursor(ob_display
, XC_left_side
);
175 cursors
[OB_CURSOR_NORTHWEST
] =
176 XCreateFontCursor(ob_display
, XC_top_left_corner
);
178 /* create available keycodes */
179 keys
[OB_KEY_RETURN
] =
180 XKeysymToKeycode(ob_display
, XStringToKeysym("Return"));
181 keys
[OB_KEY_ESCAPE
] =
182 XKeysymToKeycode(ob_display
, XStringToKeysym("Escape"));
184 XKeysymToKeycode(ob_display
, XStringToKeysym("Left"));
186 XKeysymToKeycode(ob_display
, XStringToKeysym("Right"));
188 XKeysymToKeycode(ob_display
, XStringToKeysym("Up"));
190 XKeysymToKeycode(ob_display
, XStringToKeysym("Down"));
192 prop_startup(); /* get atoms values for the display */
193 extensions_query_all(); /* find which extensions are present */
195 if (screen_annex()) { /* it will be ours! */
197 event_startup(reconfigure
);
198 grab_startup(reconfigure
);
199 /* focus_backup is used for stacking, so this needs to come before
200 anything that calls stacking_add */
201 focus_startup(reconfigure
);
202 window_startup(reconfigure
);
203 sn_startup(reconfigure
);
210 /* startup the parsing so everything can register sections
215 /* parse/load user options */
216 if (parse_load_rc(&doc
, &node
))
217 parse_tree(i
, doc
, node
->xmlChildrenNode
);
218 /* we're done with parsing now, kill it */
223 /* load the theme specified in the rc file */
226 if ((theme
= RrThemeNew(ob_rr_inst
, config_theme
)))
228 if (ob_rr_theme
== NULL
)
229 ob_exit_with_error("Unable to load a theme.");
232 moveresize_startup(reconfigure
);
233 screen_startup(reconfigure
);
234 group_startup(reconfigure
);
235 client_startup(reconfigure
);
236 dock_startup(reconfigure
);
237 keyboard_startup(reconfigure
);
238 mouse_startup(reconfigure
);
239 menu_startup(reconfigure
);
242 /* get all the existing windows */
247 /* redecorate all existing windows */
248 for (it
= client_list
; it
; it
= g_list_next(it
)) {
249 ObClient
*c
= it
->data
;
250 frame_adjust_theme(c
->frame
);
256 state
= OB_STATE_RUNNING
;
257 ob_main_loop_run(ob_main_loop
);
258 state
= OB_STATE_EXITING
;
262 client_unmanage_all();
265 menu_shutdown(reconfigure
);
266 mouse_shutdown(reconfigure
);
267 keyboard_shutdown(reconfigure
);
268 dock_shutdown(reconfigure
);
269 client_shutdown(reconfigure
);
270 group_shutdown(reconfigure
);
271 screen_shutdown(reconfigure
);
272 focus_shutdown(reconfigure
);
273 moveresize_shutdown(reconfigure
);
274 sn_shutdown(reconfigure
);
275 window_shutdown(reconfigure
);
276 grab_shutdown(reconfigure
);
277 event_shutdown(reconfigure
);
279 } while (reconfigure
);
282 RrThemeFree(ob_rr_theme
);
283 RrInstanceFree(ob_rr_inst
);
288 XCloseDisplay(ob_display
);
291 if (restart_path
!= NULL
) {
297 if (g_shell_parse_argv(restart_path
, &argcp
, &argvp
, &err
)) {
298 execvp(argvp
[0], argvp
);
301 g_warning("failed to execute '%s': %s", restart_path
,
307 execvp(argv
[0], argv
); /* try how we were run */
313 static void signal_handler(int signal
, gpointer data
)
315 if (signal
== SIGUSR1
) {
316 fprintf(stderr
, "Caught signal %d. Restarting.\n", signal
);
318 } else if (signal
== SIGUSR2
) {
319 fprintf(stderr
, "Caught signal %d. Reconfiguring.\n", signal
);
322 fprintf(stderr
, "Caught signal %d. Exiting.\n", signal
);
327 static void print_version()
329 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
330 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
331 g_print("This is free software, and you are welcome to redistribute it\n");
332 g_print("under certain conditions. See the file COPYING for details.\n\n");
335 static void print_help()
338 g_print("Syntax: openbox [options]\n\n");
339 g_print("Options:\n\n");
341 g_print(" --sm-disable Disable connection to session manager\n");
342 g_print(" --sm-client-id ID Specify session management ID\n");
343 g_print(" --sm-save-file FILE Specify file to load a saved session\n"
346 g_print(" --replace Replace the currently running window "
348 g_print(" --help Display this help and exit\n");
349 g_print(" --version Display the version and exit\n");
350 g_print(" --sync Run in synchronous mode (this is slow and\n"
351 " meant for debugging X routines)\n");
352 g_print(" --debug Display debugging output\n");
353 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
356 static void parse_args(int argc
, char **argv
)
360 for (i
= 1; i
< argc
; ++i
) {
361 if (!strcmp(argv
[i
], "--version")) {
364 } else if (!strcmp(argv
[i
], "--help")) {
367 } else if (!strcmp(argv
[i
], "--g-fatal-warnings")) {
368 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL
);
369 } else if (!strcmp(argv
[i
], "--replace")) {
370 ob_replace_wm
= TRUE
;
371 } else if (!strcmp(argv
[i
], "--sync")) {
373 } else if (!strcmp(argv
[i
], "--debug")) {
374 ob_debug_show_output(TRUE
);
376 } else if (!strcmp(argv
[i
], "--sm-client-id")) {
377 if (i
== argc
- 1) /* no args left */
378 g_printerr(_("--sm-client-id requires an argument\n"));
380 ob_sm_id
= g_strdup(argv
[++i
]);
381 } else if (!strcmp(argv
[i
], "--sm-save-file")) {
382 if (i
== argc
- 1) /* no args left */
383 g_printerr(_("--sm-save-file requires an argument\n"));
385 sm_save_file
= argv
[++i
];
386 } else if (!strcmp(argv
[i
], "--sm-disable")) {
390 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
397 void ob_exit_with_error(gchar
*msg
)
404 void ob_restart_other(const gchar
*path
)
406 restart_path
= g_strdup(path
);
418 ob_main_loop_exit(ob_main_loop
);
421 Cursor
ob_cursor(ObCursor cursor
)
423 g_assert(cursor
< OB_NUM_CURSORS
);
424 return cursors
[cursor
];
427 KeyCode
ob_keycode(ObKey key
)
429 g_assert(key
< OB_NUM_KEYS
);
438 gchar
*ob_expand_tilde(const gchar
*f
)
445 spl
= g_strsplit(f
, "~", 0);
446 mid
= g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S
, NULL
);
447 ret
= g_strjoinv(mid
, spl
);
453 void ob_reconfigure()
This page took 0.052972 seconds and 5 git commands to generate.