]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
13 #include "moveresize.h"
17 #include "extensions.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
;
55 gboolean ob_sm_use
= TRUE
;
57 gboolean ob_replace_wm
;
60 static gboolean xsync
;
61 static gboolean shutdown
;
62 static gboolean restart
;
63 static char *restart_path
;
64 static Cursor cursors
[OB_NUM_CURSORS
];
65 static KeyCode keys
[OB_NUM_KEYS
];
66 static gchar
*sm_save_file
;
68 static void signal_handler(int signal
);
69 static void parse_args(int argc
, char **argv
);
71 int main(int argc
, char **argv
)
73 struct sigaction action
;
80 ob_debug_show_output(TRUE
);
83 state
= OB_STATE_STARTING
;
85 /* initialize the locale */
86 if (!setlocale(LC_ALL
, ""))
87 g_warning("Couldn't set locale from environment.\n");
88 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
89 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
90 textdomain(PACKAGE_NAME
);
92 /* set up signal handler */
94 action
.sa_handler
= signal_handler
;
95 action
.sa_mask
= sigset
;
96 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
97 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
98 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
99 /* sigaction(SIGSEGV, &action, (struct sigaction *) NULL);*/
100 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
101 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
102 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
103 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
105 /* create the ~/.openbox dir */
106 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
107 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
108 S_IROTH
| S_IWOTH
| S_IXOTH
));
110 /* create the ~/.openbox/themes dir */
111 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
112 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
113 S_IROTH
| S_IWOTH
| S_IXOTH
));
115 /* create the ~/.openbox/sessions dir */
116 path
= g_build_filename(g_get_home_dir(), ".openbox", "sessions", NULL
);
117 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
118 S_IROTH
| S_IWOTH
| S_IXOTH
));
121 g_set_prgname(argv
[0]);
123 /* parse out command line args */
124 parse_args(argc
, argv
);
126 ob_display
= XOpenDisplay(NULL
);
127 if (ob_display
== NULL
)
128 ob_exit_with_error("Failed to open the display.");
129 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1)
130 ob_exit_with_error("Failed to set display as close-on-exec.");
133 session_load(sm_save_file
);
134 session_startup(argc
, argv
);
137 ob_sn_display
= sn_display_new(ob_display
, NULL
, NULL
);
140 ob_screen
= DefaultScreen(ob_display
);
142 ob_rr_inst
= RrInstanceNew(ob_display
, ob_screen
);
143 if (ob_rr_inst
== NULL
)
144 ob_exit_with_error("Failed to initialize the render library.");
146 /* XXX fork self onto other screens */
148 XSynchronize(ob_display
, xsync
);
150 /* check for locale support */
151 if (!XSupportsLocale())
152 g_warning("X server does not support locale.");
153 if (!XSetLocaleModifiers(""))
154 g_warning("Cannot set locale modifiers for the X server.");
156 /* set our error handler */
157 XSetErrorHandler(xerror_handler
);
159 /* set the DISPLAY environment variable for any lauched children, to the
160 display we're using, so they open in the right place. */
161 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
163 /* create available cursors */
164 cursors
[OB_CURSOR_POINTER
] =
165 XCreateFontCursor(ob_display
, XC_left_ptr
);
166 cursors
[OB_CURSOR_BUSY
] =
167 XCreateFontCursor(ob_display
, XC_watch
);
168 cursors
[OB_CURSOR_MOVE
] =
169 XCreateFontCursor(ob_display
, XC_fleur
);
170 cursors
[OB_CURSOR_NORTH
] =
171 XCreateFontCursor(ob_display
, XC_top_side
);
172 cursors
[OB_CURSOR_NORTHEAST
] =
173 XCreateFontCursor(ob_display
, XC_top_right_corner
);
174 cursors
[OB_CURSOR_EAST
] =
175 XCreateFontCursor(ob_display
, XC_right_side
);
176 cursors
[OB_CURSOR_SOUTHEAST
] =
177 XCreateFontCursor(ob_display
, XC_bottom_right_corner
);
178 cursors
[OB_CURSOR_SOUTH
] =
179 XCreateFontCursor(ob_display
, XC_bottom_side
);
180 cursors
[OB_CURSOR_SOUTHWEST
] =
181 XCreateFontCursor(ob_display
, XC_bottom_left_corner
);
182 cursors
[OB_CURSOR_WEST
] =
183 XCreateFontCursor(ob_display
, XC_left_side
);
184 cursors
[OB_CURSOR_NORTHWEST
] =
185 XCreateFontCursor(ob_display
, XC_top_left_corner
);
187 /* create available keycodes */
188 keys
[OB_KEY_RETURN
] =
189 XKeysymToKeycode(ob_display
, XStringToKeysym("Return"));
190 keys
[OB_KEY_ESCAPE
] =
191 XKeysymToKeycode(ob_display
, XStringToKeysym("Escape"));
193 XKeysymToKeycode(ob_display
, XStringToKeysym("Left"));
195 XKeysymToKeycode(ob_display
, XStringToKeysym("Right"));
197 XKeysymToKeycode(ob_display
, XStringToKeysym("Up"));
199 XKeysymToKeycode(ob_display
, XStringToKeysym("Down"));
201 prop_startup(); /* get atoms values for the display */
202 extensions_query_all(); /* find which extensions are present */
204 /* save stuff that we can use to restore state */
207 if (screen_annex()) { /* it will be ours! */
210 /* startup the parsing so everything can register sections of the rc */
213 /* anything that is going to read data from the rc file needs to be
218 /* focus_backup is used for stacking, so this needs to come before
219 anything that calls stacking_add */
223 /* load the plugins specified in the pluginrc */
226 /* set up the kernel config shit */
229 /* parse/load user options */
230 if (parse_load_rc(&doc
, &node
))
231 parse_tree(i
, doc
, node
->xmlChildrenNode
);
232 /* we're done with parsing now, kill it */
238 /* load the theme specified in the rc file */
239 ob_rr_theme
= RrThemeNew(ob_rr_inst
, config_theme
);
240 if (ob_rr_theme
== NULL
)
241 ob_exit_with_error("Unable to load a theme.");
243 moveresize_startup();
251 /* call startup for all the plugins */
254 /* get all the existing windows */
257 state
= OB_STATE_RUNNING
;
260 state
= OB_STATE_EXITING
;
263 client_unmanage_all();
265 plugin_shutdown(); /* calls all the plugins' shutdown functions */
274 moveresize_shutdown();
282 RrThemeFree(ob_rr_theme
);
283 RrInstanceFree(ob_rr_inst
);
289 sn_display_unref(ob_sn_display
);
292 XCloseDisplay(ob_display
);
295 if (restart_path
!= NULL
) {
301 if (g_shell_parse_argv(restart_path
, &argcp
, &argvp
, &err
)) {
302 execvp(argvp
[0], argvp
);
305 g_warning("failed to execute '%s': %s", restart_path
,
311 execvp(argv
[0], argv
); /* try how we were run */
317 static void signal_handler(int sig
)
321 fprintf(stderr
, "Caught SIGUSR1 signal. Restarting.");
329 fprintf(stderr
, "Caught signal %d. Exiting.", sig
);
335 fprintf(stderr
, "Caught signal %d. Aborting and dumping core.", sig
);
340 static void print_version()
342 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
343 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
344 g_print("This is free software, and you are welcome to redistribute it\n");
345 g_print("under certain conditions. See the file COPYING for details.\n\n");
348 static void print_help()
351 g_print("Syntax: openbox [options]\n\n");
352 g_print("Options:\n\n");
354 g_print(" --sm-disable Disable connection to session manager\n");
355 g_print(" --sm-client-id ID Specify session management ID\n");
356 g_print(" --sm-save-file FILE Specify file to load a saved session\n"
359 g_print(" --replace Replace the currently running window "
361 g_print(" --help Display this help and exit\n");
362 g_print(" --version Display the version and exit\n");
363 g_print(" --sync Run in synchronous mode (this is slow and\n"
364 " meant for debugging X routines)\n");
365 g_print(" --debug Display debugging output\n");
366 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
369 static void parse_args(int argc
, char **argv
)
373 for (i
= 1; i
< argc
; ++i
) {
374 if (!strcmp(argv
[i
], "--version")) {
377 } else if (!strcmp(argv
[i
], "--help")) {
380 } else if (!strcmp(argv
[i
], "--g-fatal-warnings")) {
381 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL
);
382 } else if (!strcmp(argv
[i
], "--replace")) {
383 ob_replace_wm
= TRUE
;
384 } else if (!strcmp(argv
[i
], "--sync")) {
386 } else if (!strcmp(argv
[i
], "--debug")) {
387 ob_debug_show_output(TRUE
);
389 } else if (!strcmp(argv
[i
], "--sm-client-id")) {
390 if (i
== argc
- 1) /* no args left */
391 g_printerr(_("--sm-client-id requires an argument\n"));
393 ob_sm_id
= g_strdup(argv
[++i
]);
394 } else if (!strcmp(argv
[i
], "--sm-save-file")) {
395 if (i
== argc
- 1) /* no args left */
396 g_printerr(_("--sm-save-file requires an argument\n"));
398 sm_save_file
= argv
[++i
];
399 } else if (!strcmp(argv
[i
], "--sm-disable")) {
403 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
410 void ob_exit_with_error(gchar
*msg
)
417 void ob_restart_other(const gchar
*path
)
419 restart_path
= g_strdup(path
);
434 Cursor
ob_cursor(ObCursor cursor
)
436 g_assert(cursor
< OB_NUM_CURSORS
);
437 return cursors
[cursor
];
440 KeyCode
ob_keycode(ObKey key
)
442 g_assert(key
< OB_NUM_KEYS
);
This page took 0.051009 seconds and 4 git commands to generate.