1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
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
45 //#include <guile/gh.h>
49 // The initializer in openbox_wrap.cc
50 extern void init_openbox(void);
53 #define _(str) gettext(str)
60 Openbox *Openbox::instance = (Openbox *) 0;
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.\n", signal);
79 printf("Caught signal %d. Aborting and dumping core.\n", signal);
85 Openbox::Openbox(int argc, char **argv)
86 : otk::OtkEventDispatcher(),
87 otk::OtkEventHandler()
89 struct sigaction action;
91 _state = State_Starting; // initializing everything
93 Openbox::instance = this;
95 _displayreq = (char*) 0;
98 _rcfilepath = otk::expandTilde("~/.openbox/rc3");
100 parseCommandLine(argc, argv);
102 // TEMPORARY: using the xrdb rc3
103 _config.setFile(_rcfilepath);
104 if (!_config.load()) {
105 printf("failed to load rc file %s\n", _config.file().c_str());
109 _config.getValue("session.styleFile", s);
111 if (!_config.load()) {
112 printf("failed to load style %s\n", _config.file().c_str());
116 // open the X display (and gets some info about it, and its screens)
117 otk::OBDisplay::initialize(_displayreq);
118 assert(otk::OBDisplay::display);
120 // set up the signal handler
121 action.sa_handler = Openbox::signalHandler;
122 action.sa_mask = sigset_t();
123 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
124 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
125 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
126 sigaction(SIGFPE, &action, (struct sigaction *) 0);
127 sigaction(SIGTERM, &action, (struct sigaction *) 0);
128 sigaction(SIGINT, &action, (struct sigaction *) 0);
129 sigaction(SIGHUP, &action, (struct sigaction *) 0);
131 _property = new otk::OBProperty();
133 _actions = new OBActions();
135 setMasterHandler(_actions); // set as the master event handler
137 // create the mouse cursors we'll use
138 _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
139 _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
140 _cursors.ll_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ll_angle);
141 _cursors.lr_angle = XCreateFontCursor(otk::OBDisplay::display, XC_lr_angle);
142 _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle);
143 _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle);
145 // initialize all the screens
147 screen = new OBScreen(0, _config);
148 if (screen->managed()) {
149 _screens.push_back(screen);
150 _screens[0]->manageExisting();
151 // XXX: "change to" the first workspace on the screen to initialize stuff
155 if (_screens.empty()) {
156 printf(_("No screens were found without a window manager. Exiting.\n"));
161 // make our guile interfaces exist
164 // run the guile of d3th
165 FILE *rcpyfd = fopen("/home/natas/.openbox/user.scm", "r");
167 printf("failed to load guile script /home/natas/.openbox/user.scm\n");
170 gh_load("/home/natas/.openbox/user.scm");
174 Py_SetProgramName(argv[0]);
176 //initopenbox(); // initialize the static 'openbox' module
178 FILE *rcpyfd = fopen("/home/natas/.openbox/user.py", "r");
180 printf("failed to load python file /home/natas/.openbox/user.py\n");
182 PyRun_SimpleFile(rcpyfd, "/home/natas/.openbox/user.py");
187 _state = State_Normal; // done starting
193 _state = State_Exiting; // time to kill everything
195 std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
197 // close the X display
198 otk::OBDisplay::destroy();
202 void Openbox::parseCommandLine(int argc, char **argv)
206 for (int i = 1; i < argc; ++i) {
207 std::string arg(argv[i]);
209 if (arg == "-display") {
213 _displayreq = argv[i];
214 } else if (arg == "-rc") {
218 _rcfilepath = argv[i];
219 } else if (arg == "-menu") {
223 _menufilepath = argv[i];
224 } else if (arg == "-version") {
227 } else if (arg == "-help") {
241 void Openbox::showVersion()
243 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
244 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
248 void Openbox::showHelp()
250 showVersion(); // show the version string and copyright
252 // print program usage and command line options
253 printf(_("Usage: %s [OPTIONS...]\n\
255 -display <string> use display connection.\n\
256 -rc <string> use alternate resource file.\n\
257 -menu <string> use alternate menu file.\n\
258 -version display version and exit.\n\
259 -help display this help text and exit.\n\n"), _argv0);
261 printf(_("Compile time options:\n\
286 void Openbox::eventLoop()
288 while (!_doshutdown) {
289 dispatchEvents(); // from OtkEventDispatcher
290 _timermanager.fire();
295 void Openbox::addClient(Window window, OBClient *client)
297 _clients[window] = client;
301 void Openbox::removeClient(Window window)
303 _clients.erase(window);
307 OBClient *Openbox::findClient(Window window)
310 NOTE: we dont use _clients[] to find the value because that will insert
311 a new null into the hash, which really sucks when we want to clean up the
314 ClientMap::iterator it = _clients.find(window);
315 if (it != _clients.end())
318 return (OBClient*) 0;