1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
11 #include "otk/property.hh"
12 #include "otk/display.hh"
13 #include "otk/assassin.hh"
14 #include "otk/util.hh" // TEMPORARY
17 #include <X11/cursorfont.h>
21 #endif // HAVE_STDIO_H
25 #endif // HAVE_STDLIB_H
29 #endif // HAVE_SIGNAL_H
33 #endif // HAVE_FCNTL_H
36 # include <sys/types.h>
38 #endif // HAVE_UNISTD_H
40 #ifdef HAVE_SYS_SELECT_H
41 # include <sys/select.h>
42 #endif // HAVE_SYS_SELECT_H
45 #define _(str) gettext(str)
52 Openbox *Openbox::instance = (Openbox *) 0;
55 void Openbox::signalHandler(int signal)
59 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
60 // down and hangs-up on us.
65 printf("Caught signal %d. Exiting.\n", signal);
71 printf("Caught signal %d. Aborting and dumping core.\n", signal);
77 Openbox::Openbox(int argc, char **argv)
78 : otk::OtkEventDispatcher(),
79 otk::OtkEventHandler()
81 struct sigaction action;
83 _state = State_Starting; // initializing everything
85 Openbox::instance = this;
87 _displayreq = (char*) 0;
90 _rcfilepath = otk::expandTilde("~/.openbox/rc3");
92 parseCommandLine(argc, argv);
94 // TEMPORARY: using the xrdb rc3
95 _config.setFile(_rcfilepath);
96 if (!_config.load()) {
97 printf("failed to load rc file %s\n", _config.file().c_str());
101 _config.getValue("session.styleFile", s);
103 if (!_config.load()) {
104 printf("failed to load style %s\n", _config.file().c_str());
108 // open the X display (and gets some info about it, and its screens)
109 otk::OBDisplay::initialize(_displayreq);
110 assert(otk::OBDisplay::display);
112 // set up the signal handler
113 action.sa_handler = Openbox::signalHandler;
114 action.sa_mask = sigset_t();
115 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
116 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
117 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
118 sigaction(SIGFPE, &action, (struct sigaction *) 0);
119 sigaction(SIGTERM, &action, (struct sigaction *) 0);
120 sigaction(SIGINT, &action, (struct sigaction *) 0);
121 sigaction(SIGHUP, &action, (struct sigaction *) 0);
123 _property = new otk::OBProperty();
125 // create the mouse cursors we'll use
126 _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
127 _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
128 _cursors.ll_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ll_angle);
129 _cursors.lr_angle = XCreateFontCursor(otk::OBDisplay::display, XC_lr_angle);
130 _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle);
131 _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle);
133 // initialize all the screens
135 screen = new OBScreen(0, _config);
136 if (screen->managed()) {
137 _screens.push_back(screen);
138 _screens[0]->manageExisting();
139 // XXX: "change to" the first workspace on the screen to initialize stuff
143 if (_screens.empty()) {
144 printf(_("No screens were found without a window manager. Exiting.\n"));
148 _state = State_Normal; // done starting
154 _state = State_Exiting; // time to kill everything
156 std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
158 // close the X display
159 otk::OBDisplay::destroy();
163 void Openbox::parseCommandLine(int argc, char **argv)
167 for (int i = 1; i < argc; ++i) {
168 std::string arg(argv[i]);
170 if (arg == "-display") {
174 _displayreq = argv[i];
175 } else if (arg == "-rc") {
179 _rcfilepath = argv[i];
180 } else if (arg == "-menu") {
184 _menufilepath = argv[i];
185 } else if (arg == "-version") {
188 } else if (arg == "-help") {
202 void Openbox::showVersion()
204 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
205 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
209 void Openbox::showHelp()
211 showVersion(); // show the version string and copyright
213 // print program usage and command line options
214 printf(_("Usage: %s [OPTIONS...]\n\
216 -display <string> use display connection.\n\
217 -rc <string> use alternate resource file.\n\
218 -menu <string> use alternate menu file.\n\
219 -version display version and exit.\n\
220 -help display this help text and exit.\n\n"), _argv0);
222 printf(_("Compile time options:\n\
247 void Openbox::eventLoop()
249 while (!_doshutdown) {
250 dispatchEvents(); // from OtkEventDispatcher
251 _timermanager.fire();
256 void Openbox::addClient(Window window, OBClient *client)
258 _clients[window] = client;
262 void Openbox::removeClient(Window window)
264 _clients[window] = 0;
265 ClientMap::iterator it = _clients.find(window);
266 if (it != _clients.end())
271 OBClient *Openbox::findClient(Window window)
274 NOTE: we dont use _clients[] to find the value because that will insert
275 a new null into the hash, which really sucks when we want to clean up the
278 ClientMap::iterator it = _clients.find(window);
279 if (it != _clients.end())
282 return (OBClient*) 0;