1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
9 #include "otk/display.hh"
14 #endif // HAVE_STDIO_H
18 #endif // HAVE_STDLIB_H
22 #endif // HAVE_SIGNAL_H
26 #endif // HAVE_FCNTL_H
29 # include <sys/types.h>
31 #endif // HAVE_UNISTD_H
33 #ifdef HAVE_SYS_SELECT_H
34 # include <sys/select.h>
35 #endif // HAVE_SYS_SELECT_H
38 #define _(str) gettext(str)
44 Openbox *Openbox::instance = (Openbox *) 0;
47 int Openbox::xerrorHandler(Display *d, XErrorEvent *e)
52 XGetErrorText(d, e->error_code, errtxt, 128);
53 printf("X Error: %s\n", errtxt);
63 void Openbox::signalHandler(int signal)
67 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
68 // down and hangs-up on us.
73 printf("Caught signal %d. Exiting.", signal);
79 printf("Caught signal %d. Aborting and dumping core.", signal);
85 Openbox::Openbox(int argc, char **argv)
87 struct sigaction action;
89 _state = State_Starting;
91 Openbox::instance = this;
93 _displayreq = (char*) 0;
96 parseCommandLine(argc, argv);
98 // open the X display (and gets some info about it, and its screens)
99 otk::OBDisplay::initialize(_displayreq);
100 assert(otk::OBDisplay::display);
102 // set up the signal handler
103 action.sa_handler = Openbox::signalHandler;
104 action.sa_mask = sigset_t();
105 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
106 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
107 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
108 sigaction(SIGFPE, &action, (struct sigaction *) 0);
109 sigaction(SIGTERM, &action, (struct sigaction *) 0);
110 sigaction(SIGINT, &action, (struct sigaction *) 0);
111 sigaction(SIGHUP, &action, (struct sigaction *) 0);
115 _state = State_Normal; // done starting
121 // close the X display
122 otk::OBDisplay::destroy();
126 void Openbox::parseCommandLine(int argc, char **argv)
130 for (int i = 1; i < argc; ++i) {
131 std::string arg(argv[i]);
133 if (arg == "-display") {
137 _displayreq = argv[i];
138 } else if (arg == "-rc") {
142 _rcfilepath = argv[i];
143 } else if (arg == "-menu") {
147 _menufilepath = argv[i];
148 } else if (arg == "-version") {
151 } else if (arg == "-help") {
165 void Openbox::showVersion()
167 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
168 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
172 void Openbox::showHelp()
174 showVersion(); // show the version string and copyright
176 // print program usage and command line options
177 printf(_("Usage: %s [OPTIONS...]\n\
179 -display <string> use display connection.\n\
180 -rc <string> use alternate resource file.\n\
181 -menu <string> use alternate menu file.\n\
182 -version display version and exit.\n\
183 -help display this help text and exit.\n\n"), _argv0);
185 printf(_("Compile time options:\n\
210 void Openbox::eventLoop()
212 while (_state == State_Normal) {
213 if (XPending(otk::OBDisplay::display)) {
215 XNextEvent(otk::OBDisplay::display, &e);
218 _timermanager.fire();