]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
12 #include "python_client.hh"
13 #include "otk/property.hh"
14 #include "otk/display.hh"
15 #include "otk/assassin.hh"
16 #include "otk/util.hh" // TEMPORARY
19 #include <X11/cursorfont.h>
23 #endif // HAVE_STDIO_H
27 #endif // HAVE_STDLIB_H
31 #endif // HAVE_SIGNAL_H
35 #endif // HAVE_FCNTL_H
38 # include <sys/types.h>
40 #endif // HAVE_UNISTD_H
42 #ifdef HAVE_SYS_SELECT_H
43 # include <sys/select.h>
44 #endif // HAVE_SYS_SELECT_H
47 #define _(str) gettext(str)
54 Openbox
*Openbox::instance
= (Openbox
*) 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 _pyclients
= PyDict_New();
97 parseCommandLine(argc
, argv
);
99 // TEMPORARY: using the xrdb rc3
100 _config
.setFile(_rcfilepath
);
101 if (!_config
.load()) {
102 printf("failed to load rc file %s\n", _config
.file().c_str());
106 _config
.getValue("session.styleFile", s
);
108 if (!_config
.load()) {
109 printf("failed to load style %s\n", _config
.file().c_str());
113 // open the X display (and gets some info about it, and its screens)
114 otk::OBDisplay::initialize(_displayreq
);
115 assert(otk::OBDisplay::display
);
117 // set up the signal handler
118 action
.sa_handler
= Openbox::signalHandler
;
119 action
.sa_mask
= sigset_t();
120 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
121 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
122 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
123 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
124 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
125 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
126 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
128 _property
= new otk::OBProperty();
130 _actions
= new OBActions();
132 setMasterHandler(_actions
); // set as the master event handler
134 // create the mouse cursors we'll use
135 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
136 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
137 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
138 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
139 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
140 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
142 // initialize all the screens
144 screen
= new OBScreen(0, _config
);
145 if (screen
->managed()) {
146 _screens
.push_back(screen
);
147 _screens
[0]->manageExisting();
148 // XXX: "change to" the first workspace on the screen to initialize stuff
152 if (_screens
.empty()) {
153 printf(_("No screens were found without a window manager. Exiting.\n"));
157 // initialize the python interface
158 Py_SetProgramName(argv
[0]);
160 initopenbox(); // initialize the static 'openbox' module
161 FILE *rcpyfd
= fopen("/home/natas/.openbox/user.py", "r");
163 printf("failed to load python file /home/natas/.openbox/user.py\n");
165 PyRun_SimpleFile(rcpyfd
, "/home/natas/.openbox/user.py");
169 _state
= State_Normal
; // done starting
175 _state
= State_Exiting
; // time to kill everything
177 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
179 // close the X display
180 otk::OBDisplay::destroy();
184 void Openbox::parseCommandLine(int argc
, char **argv
)
188 for (int i
= 1; i
< argc
; ++i
) {
189 std::string
arg(argv
[i
]);
191 if (arg
== "-display") {
195 _displayreq
= argv
[i
];
196 } else if (arg
== "-rc") {
200 _rcfilepath
= argv
[i
];
201 } else if (arg
== "-menu") {
205 _menufilepath
= argv
[i
];
206 } else if (arg
== "-version") {
209 } else if (arg
== "-help") {
223 void Openbox::showVersion()
225 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
226 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
230 void Openbox::showHelp()
232 showVersion(); // show the version string and copyright
234 // print program usage and command line options
235 printf(_("Usage: %s [OPTIONS...]\n\
237 -display <string> use display connection.\n\
238 -rc <string> use alternate resource file.\n\
239 -menu <string> use alternate menu file.\n\
240 -version display version and exit.\n\
241 -help display this help text and exit.\n\n"), _argv0
);
243 printf(_("Compile time options:\n\
268 void Openbox::eventLoop()
270 while (!_doshutdown
) {
271 dispatchEvents(); // from OtkEventDispatcher
272 _timermanager
.fire();
277 void Openbox::addClient(Window window
, OBClient
*client
)
279 _clients
[window
] = client
;
281 // maintain the python list here too
282 PyClientObject
* pyclient
= PyObject_New(PyClientObject
, &PyClient_Type
);
283 pyclient
->window
= window
;
284 pyclient
->client
= client
;
285 PyDict_SetItem(_pyclients
, PyLong_FromLong(window
), (PyObject
*)pyclient
);
289 void Openbox::removeClient(Window window
)
291 _clients
.erase(window
);
295 OBClient
*Openbox::findClient(Window window
)
298 NOTE: we dont use _clients[] to find the value because that will insert
299 a new null into the hash, which really sucks when we want to clean up the
302 ClientMap::iterator it
= _clients
.find(window
);
303 if (it
!= _clients
.end())
306 return (OBClient
*) 0;
This page took 0.054777 seconds and 4 git commands to generate.