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;
56 void Openbox::signalHandler(int signal)
60 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
61 // down and hangs-up on us.
66 printf("Caught signal %d. Exiting.\n", signal);
72 printf("Caught signal %d. Aborting and dumping core.\n", signal);
78 Openbox::Openbox(int argc, char **argv)
79 : otk::OtkEventDispatcher(),
80 otk::OtkEventHandler()
82 struct sigaction action;
84 _state = State_Starting; // initializing everything
86 Openbox::instance = this;
88 _displayreq = (char*) 0;
91 _rcfilepath = otk::expandTilde("~/.openbox/rc3");
93 parseCommandLine(argc, argv);
95 // TEMPORARY: using the xrdb rc3
96 _config.setFile(_rcfilepath);
97 if (!_config.load()) {
98 printf("failed to load rc file %s\n", _config.file().c_str());
102 _config.getValue("session.styleFile", s);
104 if (!_config.load()) {
105 printf("failed to load style %s\n", _config.file().c_str());
109 // open the X display (and gets some info about it, and its screens)
110 otk::OBDisplay::initialize(_displayreq);
111 assert(otk::OBDisplay::display);
113 // set up the signal handler
114 action.sa_handler = Openbox::signalHandler;
115 action.sa_mask = sigset_t();
116 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
117 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
118 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
119 sigaction(SIGFPE, &action, (struct sigaction *) 0);
120 sigaction(SIGTERM, &action, (struct sigaction *) 0);
121 sigaction(SIGINT, &action, (struct sigaction *) 0);
122 sigaction(SIGHUP, &action, (struct sigaction *) 0);
124 _property = new otk::OBProperty();
126 _actions = new OBActions();
128 setMasterHandler(_actions); // set as the master event handler
130 // create the mouse cursors we'll use
131 _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
132 _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
133 _cursors.ll_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ll_angle);
134 _cursors.lr_angle = XCreateFontCursor(otk::OBDisplay::display, XC_lr_angle);
135 _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle);
136 _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle);
138 // initialize all the screens
140 screen = new OBScreen(0, _config);
141 if (screen->managed()) {
142 _screens.push_back(screen);
143 _screens[0]->manageExisting();
144 // XXX: "change to" the first workspace on the screen to initialize stuff
148 if (_screens.empty()) {
149 printf(_("No screens were found without a window manager. Exiting.\n"));
153 _state = State_Normal; // done starting
159 _state = State_Exiting; // time to kill everything
161 std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
163 // close the X display
164 otk::OBDisplay::destroy();
168 void Openbox::parseCommandLine(int argc, char **argv)
172 for (int i = 1; i < argc; ++i) {
173 std::string arg(argv[i]);
175 if (arg == "-display") {
179 _displayreq = argv[i];
180 } else if (arg == "-rc") {
184 _rcfilepath = argv[i];
185 } else if (arg == "-menu") {
189 _menufilepath = argv[i];
190 } else if (arg == "-version") {
193 } else if (arg == "-help") {
207 void Openbox::showVersion()
209 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
210 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
214 void Openbox::showHelp()
216 showVersion(); // show the version string and copyright
218 // print program usage and command line options
219 printf(_("Usage: %s [OPTIONS...]\n\
221 -display <string> use display connection.\n\
222 -rc <string> use alternate resource file.\n\
223 -menu <string> use alternate menu file.\n\
224 -version display version and exit.\n\
225 -help display this help text and exit.\n\n"), _argv0);
227 printf(_("Compile time options:\n\
252 void Openbox::eventLoop()
254 while (!_doshutdown) {
255 dispatchEvents(); // from OtkEventDispatcher
256 _timermanager.fire();
261 void Openbox::addClient(Window window, OBClient *client)
263 _clients[window] = client;
267 void Openbox::removeClient(Window window)
269 _clients.erase(window);
273 OBClient *Openbox::findClient(Window window)
276 NOTE: we dont use _clients[] to find the value because that will insert
277 a new null into the hash, which really sucks when we want to clean up the
280 ClientMap::iterator it = _clients.find(window);
281 if (it != _clients.end())
284 return (OBClient*) 0;