1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
9 #include "otk/property.hh"
10 #include "otk/display.hh"
13 #include <X11/cursorfont.h>
17 #endif // HAVE_STDIO_H
21 #endif // HAVE_STDLIB_H
25 #endif // HAVE_SIGNAL_H
29 #endif // HAVE_FCNTL_H
32 # include <sys/types.h>
34 #endif // HAVE_UNISTD_H
36 #ifdef HAVE_SYS_SELECT_H
37 # include <sys/select.h>
38 #endif // HAVE_SYS_SELECT_H
41 #define _(str) gettext(str)
46 Openbox *Openbox::instance = (Openbox *) 0;
49 void Openbox::signalHandler(int signal)
53 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
54 // down and hangs-up on us.
59 printf("Caught signal %d. Exiting.\n", signal);
65 printf("Caught signal %d. Aborting and dumping core.\n", signal);
71 Openbox::Openbox(int argc, char **argv)
73 struct sigaction action;
75 _state = State_Starting; // initializing everything
77 Openbox::instance = this;
79 _displayreq = (char*) 0;
83 parseCommandLine(argc, argv);
85 // open the X display (and gets some info about it, and its screens)
86 otk::OBDisplay::initialize(_displayreq);
87 assert(otk::OBDisplay::display);
89 // set up the signal handler
90 action.sa_handler = Openbox::signalHandler;
91 action.sa_mask = sigset_t();
92 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
93 sigaction(SIGPIPE, &action, (struct sigaction *) 0);
94 sigaction(SIGSEGV, &action, (struct sigaction *) 0);
95 sigaction(SIGFPE, &action, (struct sigaction *) 0);
96 sigaction(SIGTERM, &action, (struct sigaction *) 0);
97 sigaction(SIGINT, &action, (struct sigaction *) 0);
98 sigaction(SIGHUP, &action, (struct sigaction *) 0);
100 _property = new otk::OBProperty();
102 // create the mouse cursors we'll use
103 _cursors.session = XCreateFontCursor(otk::OBDisplay::display, XC_left_ptr);
104 _cursors.move = XCreateFontCursor(otk::OBDisplay::display, XC_fleur);
105 _cursors.ll_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ll_angle);
106 _cursors.lr_angle = XCreateFontCursor(otk::OBDisplay::display, XC_lr_angle);
107 _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle);
108 _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle);
110 _state = State_Normal; // done starting
116 _state = State_Exiting; // time to kill everything
118 // unmanage all windows
119 while (!_clients.empty())
120 _xeventhandler.unmanageWindow(_clients.begin()->second);
122 // close the X display
123 otk::OBDisplay::destroy();
127 void Openbox::parseCommandLine(int argc, char **argv)
131 for (int i = 1; i < argc; ++i) {
132 std::string arg(argv[i]);
134 if (arg == "-display") {
138 _displayreq = argv[i];
139 } else if (arg == "-rc") {
143 _rcfilepath = argv[i];
144 } else if (arg == "-menu") {
148 _menufilepath = argv[i];
149 } else if (arg == "-version") {
152 } else if (arg == "-help") {
166 void Openbox::showVersion()
168 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
169 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
173 void Openbox::showHelp()
175 showVersion(); // show the version string and copyright
177 // print program usage and command line options
178 printf(_("Usage: %s [OPTIONS...]\n\
180 -display <string> use display connection.\n\
181 -rc <string> use alternate resource file.\n\
182 -menu <string> use alternate menu file.\n\
183 -version display version and exit.\n\
184 -help display this help text and exit.\n\n"), _argv0);
186 printf(_("Compile time options:\n\
211 void Openbox::eventLoop()
213 while (!_doshutdown) {
214 if (XPending(otk::OBDisplay::display)) {
216 XNextEvent(otk::OBDisplay::display, &e);
218 _xeventhandler.handle(e);
220 _timermanager.fire();
226 void Openbox::addClient(Window window, OBClient *client)
228 _clients[window] = client;
232 void Openbox::removeClient(Window window)
234 ClientMap::iterator it = _clients.find(window);
235 if (it != _clients.end())
240 OBClient *Openbox::findClient(Window window)
243 NOTE: we dont use _clients[] to find the value because that will insert
244 a new null into the hash, which really sucks when we want to clean up the
247 ClientMap::iterator it = _clients.find(window);
248 if (it != _clients.end())
251 return (OBClient*) 0;