1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
12 #include "otk/property.hh"
13 #include "otk/display.hh"
14 #include "otk/assassin.hh"
15 #include "otk/util.hh" // TEMPORARY
18 #include <X11/cursorfont.h>
22 #endif // HAVE_STDIO_H
26 #endif // HAVE_STDLIB_H
30 #endif // HAVE_SIGNAL_H
34 #endif // HAVE_FCNTL_H
37 # include <sys/types.h>
39 #endif // HAVE_UNISTD_H
41 #ifdef HAVE_SYS_SELECT_H
42 # include <sys/select.h>
43 #endif // HAVE_SYS_SELECT_H
46 #define _(str) gettext(str)
53 Openbox *Openbox::instance = (Openbox *) 0;
54 OBActions *Openbox::actions = (OBActions *) 0;
57 void Openbox::signalHandler(int signal)
61 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
62 // down and hangs-up on us.
67 printf("Caught signal %d. Exiting.\n", signal);
73 printf("Caught signal %d. Aborting and dumping core.\n", signal);
79 Openbox::Openbox(int argc, char **argv)
80 : otk::OtkEventDispatcher(),
81 otk::OtkEventHandler()
83 struct sigaction action;
85 _state = State_Starting; // initializing everything
87 Openbox::instance = this;
89 _displayreq = (char*) 0;
92 _rcfilepath = otk::expandTilde("~/.openbox/rc3");
94 parseCommandLine(argc, argv);
96 // TEMPORARY: using the xrdb rc3
97 _config.setFile(_rcfilepath);
98 if (!_config.load()) {
99 printf("failed to load rc file %s\n", _config.file().c_str());
103 _config.getValue("session.styleFile", s);
105 if (!_config.load()) {
106 printf("failed to load style %s\n", _config.file().c_str());
110 // open the X display (and gets some info about it, and its screens)
111 otk::OBDisplay::initialize(_displayreq);
112 assert(otk::OBDisplay::display);
114 // set up the signal handler
115 action.sa_handler = Openbox::signalHandler;
116 action.sa_mask = sigset_t();
117 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
118 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
119 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
120 sigaction(SIGFPE, &action, (struct sigaction *) 0);
121 sigaction(SIGTERM, &action, (struct sigaction *) 0);
122 sigaction(SIGINT, &action, (struct sigaction *) 0);
123 sigaction(SIGHUP, &action, (struct sigaction *) 0);
125 _property = new otk::OBProperty();
127 Openbox::actions = new OBActions();
129 // create the mouse cursors we'll use
130 _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
131 _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
132 _cursors.ll_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ll_angle);
133 _cursors.lr_angle = XCreateFontCursor(otk::OBDisplay::display, XC_lr_angle);
134 _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle);
135 _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle);
137 // initialize all the screens
139 screen = new OBScreen(0, _config);
140 if (screen->managed()) {
141 _screens.push_back(screen);
142 _screens[0]->manageExisting();
143 // XXX: "change to" the first workspace on the screen to initialize stuff
147 if (_screens.empty()) {
148 printf(_("No screens were found without a window manager. Exiting.\n"));
152 _state = State_Normal; // done starting
158 _state = State_Exiting; // time to kill everything
160 std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
162 // close the X display
163 otk::OBDisplay::destroy();
167 void Openbox::parseCommandLine(int argc, char **argv)
171 for (int i = 1; i < argc; ++i) {
172 std::string arg(argv[i]);
174 if (arg == "-display") {
178 _displayreq = argv[i];
179 } else if (arg == "-rc") {
183 _rcfilepath = argv[i];
184 } else if (arg == "-menu") {
188 _menufilepath = argv[i];
189 } else if (arg == "-version") {
192 } else if (arg == "-help") {
206 void Openbox::showVersion()
208 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
209 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
213 void Openbox::showHelp()
215 showVersion(); // show the version string and copyright
217 // print program usage and command line options
218 printf(_("Usage: %s [OPTIONS...]\n\
220 -display <string> use display connection.\n\
221 -rc <string> use alternate resource file.\n\
222 -menu <string> use alternate menu file.\n\
223 -version display version and exit.\n\
224 -help display this help text and exit.\n\n"), _argv0);
226 printf(_("Compile time options:\n\
251 void Openbox::eventLoop()
253 while (!_doshutdown) {
254 dispatchEvents(); // from OtkEventDispatcher
255 _timermanager.fire();
260 void Openbox::addClient(Window window, OBClient *client)
262 _clients[window] = client;
266 void Openbox::removeClient(Window window)
268 _clients[window] = 0;
269 ClientMap::iterator it = _clients.find(window);
270 if (it != _clients.end())
275 OBClient *Openbox::findClient(Window window)
278 NOTE: we dont use _clients[] to find the value because that will insert
279 a new null into the hash, which really sucks when we want to clean up the
282 ClientMap::iterator it = _clients.find(window);
283 if (it != _clients.end())
286 return (OBClient*) 0;