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>
47 //extern void SWIG_init();
51 // The initializer in openbox_wrap.cc
52 extern void init_openbox(void);
53 // The initializer in otk_wrap.cc
54 extern void init_otk(void);
57 #define _(str) gettext(str)
64 Openbox *Openbox::instance = (Openbox *) 0;
67 void Openbox::signalHandler(int signal)
71 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
72 // down and hangs-up on us.
77 printf("Caught signal %d. Exiting.\n", signal);
83 printf("Caught signal %d. Aborting and dumping core.\n", signal);
89 Openbox::Openbox(int argc, char **argv)
90 : otk::OtkEventDispatcher(),
91 otk::OtkEventHandler()
93 struct sigaction action;
95 _state = State_Starting; // initializing everything
97 Openbox::instance = this;
99 _displayreq = (char*) 0;
102 _rcfilepath = otk::expandTilde("~/.openbox/rc3");
104 parseCommandLine(argc, argv);
106 // TEMPORARY: using the xrdb rc3
107 _config.setFile(_rcfilepath);
108 if (!_config.load()) {
109 printf("failed to load rc file %s\n", _config.file().c_str());
113 _config.getValue("session.styleFile", s);
115 if (!_config.load()) {
116 printf("failed to load style %s\n", _config.file().c_str());
120 // open the X display (and gets some info about it, and its screens)
121 otk::OBDisplay::initialize(_displayreq);
122 assert(otk::OBDisplay::display);
124 // set up the signal handler
125 action.sa_handler = Openbox::signalHandler;
126 action.sa_mask = sigset_t();
127 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
128 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
129 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
130 sigaction(SIGFPE, &action, (struct sigaction *) 0);
131 sigaction(SIGTERM, &action, (struct sigaction *) 0);
132 sigaction(SIGINT, &action, (struct sigaction *) 0);
133 sigaction(SIGHUP, &action, (struct sigaction *) 0);
135 _property = new otk::OBProperty();
137 _actions = new OBActions();
139 setMasterHandler(_actions); // set as the master event handler
141 // create the mouse cursors we'll use
142 _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
143 _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
144 _cursors.ll_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ll_angle);
145 _cursors.lr_angle = XCreateFontCursor(otk::OBDisplay::display, XC_lr_angle);
146 _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle);
147 _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle);
149 // initialize all the screens
151 screen = new OBScreen(0, _config);
152 if (screen->managed()) {
153 _screens.push_back(screen);
154 _screens[0]->manageExisting();
155 // XXX: "change to" the first workspace on the screen to initialize stuff
159 if (_screens.empty()) {
160 printf(_("No screens were found without a window manager. Exiting.\n"));
165 // make our guile interfaces exist
168 // run the guile of d3th
169 FILE *rcpyfd = fopen("/home/natas/.openbox/user.scm", "r");
171 printf("failed to load guile script /home/natas/.openbox/user.scm\n");
174 gh_load("/home/natas/.openbox/user.scm");
178 Py_SetProgramName(argv[0]);
183 //PyRun_String("from _otk import *; from _openbox import *;", Py_file_input,
184 // Py_None, Py_None);
185 FILE *rcpyfd = fopen("/home/natas/.openbox/user.py", "r");
187 printf("failed to load python file /home/natas/.openbox/user.py\n");
189 PyRun_SimpleFile(rcpyfd, "/home/natas/.openbox/user.py");
194 _state = State_Normal; // done starting
200 _state = State_Exiting; // time to kill everything
202 std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin());
204 // close the X display
205 otk::OBDisplay::destroy();
209 void Openbox::parseCommandLine(int argc, char **argv)
213 for (int i = 1; i < argc; ++i) {
214 std::string arg(argv[i]);
216 if (arg == "-display") {
220 _displayreq = argv[i];
221 } else if (arg == "-rc") {
225 _rcfilepath = argv[i];
226 } else if (arg == "-menu") {
230 _menufilepath = argv[i];
231 } else if (arg == "-version") {
234 } else if (arg == "-help") {
248 void Openbox::showVersion()
250 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
251 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
255 void Openbox::showHelp()
257 showVersion(); // show the version string and copyright
259 // print program usage and command line options
260 printf(_("Usage: %s [OPTIONS...]\n\
262 -display <string> use display connection.\n\
263 -rc <string> use alternate resource file.\n\
264 -menu <string> use alternate menu file.\n\
265 -version display version and exit.\n\
266 -help display this help text and exit.\n\n"), _argv0);
268 printf(_("Compile time options:\n\
293 void Openbox::eventLoop()
295 while (!_doshutdown) {
296 dispatchEvents(); // from OtkEventDispatcher
297 _timermanager.fire();
302 void Openbox::addClient(Window window, OBClient *client)
304 _clients[window] = client;
308 void Openbox::removeClient(Window window)
310 _clients.erase(window);
314 OBClient *Openbox::findClient(Window window)
317 NOTE: we dont use _clients[] to find the value because that will insert
318 a new null into the hash, which really sucks when we want to clean up the
321 ClientMap::iterator it = _clients.find(window);
322 if (it != _clients.end())
325 return (OBClient*) 0;