]>
Dogcows Code - chaz/openbox/blob - openbox/openbox.c
14 #include "moveresize.h"
16 #include "extensions.h"
23 #include "parser/parse.h"
24 #include "render/render.h"
25 #include "render/theme.h"
40 #ifdef HAVE_SYS_STAT_H
41 # include <sys/stat.h>
42 # include <sys/types.h>
48 #include <X11/cursorfont.h>
50 RrInstance
*ob_rr_inst
;
54 gboolean ob_sm_use
= TRUE
;
56 gboolean ob_replace_wm
;
59 static gboolean xsync
;
60 static gboolean shutdown
;
61 static gboolean restart
;
62 static char *restart_path
;
63 static Cursor cursors
[OB_NUM_CURSORS
];
64 static KeyCode keys
[OB_NUM_KEYS
];
65 static gchar
*sm_save_file
;
67 static void signal_handler(const ObEvent
*e
, void *data
);
68 static void parse_args(int argc
, char **argv
);
70 int main(int argc
, char **argv
)
72 struct sigaction action
;
79 ob_debug_show_output(TRUE
);
82 state
= OB_STATE_STARTING
;
84 /* initialize the locale */
85 if (!setlocale(LC_ALL
, ""))
86 g_warning("Couldn't set locale from environment.\n");
87 bindtextdomain(PACKAGE_NAME
, LOCALEDIR
);
88 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8");
89 textdomain(PACKAGE_NAME
);
91 /* start our event dispatcher and register for signals */
93 dispatch_register(Event_Signal
, signal_handler
, NULL
);
95 /* set up signal handler */
97 action
.sa_handler
= dispatch_signal
;
98 action
.sa_mask
= sigset
;
99 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
100 sigaction(SIGUSR1
, &action
, (struct sigaction
*) NULL
);
101 sigaction(SIGPIPE
, &action
, (struct sigaction
*) NULL
);
102 /* sigaction(SIGSEGV, &action, (struct sigaction *) NULL);*/
103 sigaction(SIGFPE
, &action
, (struct sigaction
*) NULL
);
104 sigaction(SIGTERM
, &action
, (struct sigaction
*) NULL
);
105 sigaction(SIGINT
, &action
, (struct sigaction
*) NULL
);
106 sigaction(SIGHUP
, &action
, (struct sigaction
*) NULL
);
108 /* create the ~/.openbox dir */
109 path
= g_build_filename(g_get_home_dir(), ".openbox", NULL
);
110 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
111 S_IROTH
| S_IWOTH
| S_IXOTH
));
113 /* create the ~/.openbox/themes dir */
114 path
= g_build_filename(g_get_home_dir(), ".openbox", "themes", NULL
);
115 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
116 S_IROTH
| S_IWOTH
| S_IXOTH
));
118 /* create the ~/.openbox/sessions dir */
119 path
= g_build_filename(g_get_home_dir(), ".openbox", "sessions", NULL
);
120 mkdir(path
, (S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
|
121 S_IROTH
| S_IWOTH
| S_IXOTH
));
124 g_set_prgname(argv
[0]);
126 /* parse out command line args */
127 parse_args(argc
, argv
);
129 ob_display
= XOpenDisplay(NULL
);
130 if (ob_display
== NULL
)
131 ob_exit_with_error("Failed to open the display.");
132 if (fcntl(ConnectionNumber(ob_display
), F_SETFD
, 1) == -1)
133 ob_exit_with_error("Failed to set display as close-on-exec.");
136 session_load(sm_save_file
);
137 session_startup(argc
, argv
);
140 ob_sn_display
= sn_display_new(ob_display
, NULL
, NULL
);
143 ob_screen
= DefaultScreen(ob_display
);
145 ob_rr_inst
= RrInstanceNew(ob_display
, ob_screen
);
146 if (ob_rr_inst
== NULL
)
147 ob_exit_with_error("Failed to initialize the render library.");
149 /* XXX fork self onto other screens */
151 XSynchronize(ob_display
, xsync
);
153 /* check for locale support */
154 if (!XSupportsLocale())
155 g_warning("X server does not support locale.");
156 if (!XSetLocaleModifiers(""))
157 g_warning("Cannot set locale modifiers for the X server.");
159 /* set our error handler */
160 XSetErrorHandler(xerror_handler
);
162 /* set the DISPLAY environment variable for any lauched children, to the
163 display we're using, so they open in the right place. */
164 putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display
)));
166 /* create available cursors */
167 cursors
[OB_CURSOR_POINTER
] =
168 XCreateFontCursor(ob_display
, XC_left_ptr
);
169 cursors
[OB_CURSOR_BUSY
] =
170 XCreateFontCursor(ob_display
, XC_watch
);
171 cursors
[OB_CURSOR_MOVE
] =
172 XCreateFontCursor(ob_display
, XC_fleur
);
173 cursors
[OB_CURSOR_NORTH
] =
174 XCreateFontCursor(ob_display
, XC_top_side
);
175 cursors
[OB_CURSOR_NORTHEAST
] =
176 XCreateFontCursor(ob_display
, XC_top_right_corner
);
177 cursors
[OB_CURSOR_EAST
] =
178 XCreateFontCursor(ob_display
, XC_right_side
);
179 cursors
[OB_CURSOR_SOUTHEAST
] =
180 XCreateFontCursor(ob_display
, XC_bottom_right_corner
);
181 cursors
[OB_CURSOR_SOUTH
] =
182 XCreateFontCursor(ob_display
, XC_bottom_side
);
183 cursors
[OB_CURSOR_SOUTHWEST
] =
184 XCreateFontCursor(ob_display
, XC_bottom_left_corner
);
185 cursors
[OB_CURSOR_WEST
] =
186 XCreateFontCursor(ob_display
, XC_left_side
);
187 cursors
[OB_CURSOR_NORTHWEST
] =
188 XCreateFontCursor(ob_display
, XC_top_left_corner
);
190 /* create available keycodes */
191 keys
[OB_KEY_RETURN
] =
192 XKeysymToKeycode(ob_display
, XStringToKeysym("Return"));
193 keys
[OB_KEY_ESCAPE
] =
194 XKeysymToKeycode(ob_display
, XStringToKeysym("Escape"));
196 XKeysymToKeycode(ob_display
, XStringToKeysym("Left"));
198 XKeysymToKeycode(ob_display
, XStringToKeysym("Right"));
200 XKeysymToKeycode(ob_display
, XStringToKeysym("Up"));
202 XKeysymToKeycode(ob_display
, XStringToKeysym("Down"));
204 prop_startup(); /* get atoms values for the display */
205 extensions_query_all(); /* find which extensions are present */
207 /* save stuff that we can use to restore state */
210 if (screen_annex()) { /* it will be ours! */
211 /* startup the parsing so everything can register sections of the rc */
214 /* anything that is going to read data from the rc file needs to be
219 /* focus_backup is used for stacking, so this needs to come before
220 anything that calls stacking_add */
224 /* load the plugins specified in the pluginrc */
227 /* set up the kernel config shit */
230 /* parse/load user options */
231 if (parse_load_rc(&doc
, &node
))
232 parse_tree(doc
, node
->xmlChildrenNode
, NULL
);
233 /* we're done with parsing now, kill it */
236 /* load the theme specified in the rc file */
237 ob_rr_theme
= RrThemeNew(ob_rr_inst
, config_theme
);
238 if (ob_rr_theme
== NULL
)
239 ob_exit_with_error("Unable to load a theme.");
241 moveresize_startup();
247 /* call startup for all the plugins */
250 /* get all the existing windows */
253 state
= OB_STATE_RUNNING
;
256 state
= OB_STATE_EXITING
;
259 client_unmanage_all();
261 plugin_shutdown(); /* calls all the plugins' shutdown functions */
267 moveresize_shutdown();
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(const ObEvent
*e
, void *data
)
313 s
= e
->data
.s
.signal
;
316 fprintf(stderr
, "Caught SIGUSR1 signal. Restarting.");
324 fprintf(stderr
, "Caught signal %d. Exiting.", s
);
330 fprintf(stderr
, "Caught signal %d. Aborting and dumping core.", s
);
335 static void print_version()
337 g_print("Openbox %s\n\n", PACKAGE_VERSION
);
338 g_print("This program comes with ABSOLUTELY NO WARRANTY.\n");
339 g_print("This is free software, and you are welcome to redistribute it\n");
340 g_print("under certain conditions. See the file COPYING for details.\n\n");
343 static void print_help()
346 g_print("Syntax: openbox [options]\n\n");
347 g_print("Options:\n\n");
349 g_print(" --sm-disable Disable connection to session manager\n");
350 g_print(" --sm-client-id ID Specify session management ID\n");
351 g_print(" --sm-save-file FILE Specify file to load a saved session\n"
354 g_print(" --replace Replace the currently running window "
356 g_print(" --help Display this help and exit\n");
357 g_print(" --version Display the version and exit\n");
358 g_print(" --sync Run in synchronous mode (this is slow and\n"
359 " meant for debugging X routines)\n");
360 g_print(" --debug Display debugging output\n");
361 g_print("\nPlease report bugs at %s\n", PACKAGE_BUGREPORT
);
364 static void parse_args(int argc
, char **argv
)
368 for (i
= 1; i
< argc
; ++i
) {
369 if (!strcmp(argv
[i
], "--version")) {
372 } else if (!strcmp(argv
[i
], "--help")) {
375 } else if (!strcmp(argv
[i
], "--g-fatal-warnings")) {
376 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL
);
377 } else if (!strcmp(argv
[i
], "--replace")) {
378 ob_replace_wm
= TRUE
;
379 } else if (!strcmp(argv
[i
], "--sync")) {
381 } else if (!strcmp(argv
[i
], "--debug")) {
382 ob_debug_show_output(TRUE
);
384 } else if (!strcmp(argv
[i
], "--sm-client-id")) {
385 if (i
== argc
- 1) /* no args left */
386 g_printerr(_("--sm-client-id requires an argument\n"));
388 ob_sm_id
= g_strdup(argv
[++i
]);
389 } else if (!strcmp(argv
[i
], "--sm-save-file")) {
390 if (i
== argc
- 1) /* no args left */
391 g_printerr(_("--sm-save-file requires an argument\n"));
393 sm_save_file
= argv
[++i
];
394 } else if (!strcmp(argv
[i
], "--sm-disable")) {
398 g_printerr("Invalid option: '%s'\n\n", argv
[i
]);
405 void ob_exit_with_error(gchar
*msg
)
412 void ob_restart_other(const gchar
*path
)
414 restart_path
= g_strdup(path
);
429 Cursor
ob_cursor(ObCursor cursor
)
431 g_assert(cursor
< OB_NUM_CURSORS
);
432 return cursors
[cursor
];
435 KeyCode
ob_keycode(ObKey key
)
437 g_assert(key
< OB_NUM_KEYS
);
This page took 0.053935 seconds and 4 git commands to generate.