]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
444dc29fc30eef38f958eb0d3ec00cdc01a0a2e4
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 */
224 ob_rr_theme
= RrThemeNew(ob_rr_inst
, config_theme
);
225 if (ob_rr_theme
== NULL
)
226 ob_exit_with_error("Unable to load a theme.");
228 moveresize_startup(reconfigure
);
229 screen_startup(reconfigure
);
230 group_startup(reconfigure
);
231 client_startup(reconfigure
);
232 dock_startup(reconfigure
);
233 keyboard_startup(reconfigure
);
234 mouse_startup(reconfigure
);
235 menu_startup(reconfigure
);
238 /* get all the existing windows */
243 /* redecorate all existing windows */
244 for (it
= client_list
; it
; it
= g_list_next(it
)) {
245 ObClient
*c
= it
->data
;
246 frame_adjust_theme(c
->frame
);
252 state
= OB_STATE_RUNNING
;
253 ob_main_loop_run(ob_main_loop
);
254 state
= OB_STATE_EXITING
;
258 client_unmanage_all();
261 menu_shutdown(reconfigure
);
262 mouse_shutdown(reconfigure
);
263 keyboard_shutdown(reconfigure
);
264 dock_shutdown(reconfigure
);
265 client_shutdown(reconfigure
);
266 group_shutdown(reconfigure
);
267 screen_shutdown(reconfigure
);
268 focus_shutdown(reconfigure
);
269 moveresize_shutdown(reconfigure
);
270 sn_shutdown(reconfigure
);
271 window_shutdown(reconfigure
);
272 grab_shutdown(reconfigure
);
273 event_shutdown(reconfigure
);
275 } while (reconfigure
);
278 RrThemeFree(ob_rr_theme
);
279 RrInstanceFree(ob_rr_inst
);
284 XCloseDisplay(ob_display
);
287 if (restart_path
!= NULL
) {
293 if (g_shell_parse_argv(restart_path
, &argcp
, &argvp
, &err
)) {
294 execvp(argvp
[0], argvp
);
297 g_warning("failed to execute '%s': %s", restart_path
,
303 execvp(argv
[0], argv
); /* try how we were run */
309 static void signal_handler(int signal
, gpointer data
)
311 if (signal
== SIGUSR1
) {
312 fprintf(stderr
, "Caught signal %d. Restarting.\n", signal
);
314 } else if (signal
== SIGUSR2
) {
315 fprintf(stderr
, "Caught signal %d. Reconfiguring.\n", signal
);
318 fprintf(stderr
, "Caught signal %d. Exiting.\n", signal
);
323 static void print_version()
325 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
326 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
327 g_print("This is free software, and you are welcome to redistribute it\n");
328 g_print("under certain conditions. See the file COPYING for details.\n\n");
331 static void print_help()
334 g_print("Syntax: openbox [options]\n\n");
335 g_print("Options:\n\n");
337 g_print(" --sm-disable Disable connection to session manager\n");
338 g_print(" --sm-client-id ID Specify session management ID\n");
339 g_print(" --sm-save-file FILE Specify file to load a saved session\n"
342 g_print(" --replace Replace the currently running window "
344 g_print(" --help Display this help and exit\n");
345 g_print(" --version Display the version and exit\n");
346 g_print(" --sync Run in synchronous mode (this is slow and\n"
347 " meant for debugging X routines)\n");
348 g_print(" --debug Display debugging output\n");
349 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
352 static void parse_args(int argc
, char **argv
)
356 for (i
= 1; i
< argc
; ++i
) {
357 if (!strcmp(argv
[i
], "--version")) {
360 } else if (!strcmp(argv
[i
], "--help")) {
363 } else if (!strcmp(argv
[i
], "--g-fatal-warnings")) {
364 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL
);
365 } else if (!strcmp(argv
[i
], "--replace")) {
366 ob_replace_wm
= TRUE
;
367 } else if (!strcmp(argv
[i
], "--sync")) {
369 } else if (!strcmp(argv
[i
], "--debug")) {
370 ob_debug_show_output(TRUE
);
372 } else if (!strcmp(argv
[i
], "--sm-client-id")) {
373 if (i
== argc
- 1) /* no args left */
374 g_printerr(_("--sm-client-id requires an argument\n"));
376 ob_sm_id
= g_strdup(argv
[++i
]);
377 } else if (!strcmp(argv
[i
], "--sm-save-file")) {
378 if (i
== argc
- 1) /* no args left */
379 g_printerr(_("--sm-save-file requires an argument\n"));
381 sm_save_file
= argv
[++i
];
382 } else if (!strcmp(argv
[i
], "--sm-disable")) {
386 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
393 void ob_exit_with_error(gchar
*msg
)
400 void ob_restart_other(const gchar
*path
)
402 restart_path
= g_strdup(path
);
414 ob_main_loop_exit(ob_main_loop
);
417 Cursor
ob_cursor(ObCursor cursor
)
419 g_assert(cursor
< OB_NUM_CURSORS
);
420 return cursors
[cursor
];
423 KeyCode
ob_keycode(ObKey key
)
425 g_assert(key
< OB_NUM_KEYS
);
434 gchar
*ob_expand_tilde(const gchar
*f
)
441 spl
= g_strsplit(f
, "~", 0);
442 mid
= g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S
, NULL
);
443 ret
= g_strjoinv(mid
, spl
);
449 void ob_reconfigure()
This page took 0.060118 seconds and 4 git commands to generate.