]>
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 "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 _clients
= (PyDictObject
*) PyDict_New();
96 parseCommandLine(argc
, argv
);
98 // TEMPORARY: using the xrdb rc3
99 _config
.setFile(_rcfilepath
);
100 if (!_config
.load()) {
101 printf("failed to load rc file %s\n", _config
.file().c_str());
105 _config
.getValue("session.styleFile", s
);
107 if (!_config
.load()) {
108 printf("failed to load style %s\n", _config
.file().c_str());
112 // open the X display (and gets some info about it, and its screens)
113 otk::OBDisplay::initialize(_displayreq
);
114 assert(otk::OBDisplay::display
);
116 // set up the signal handler
117 action
.sa_handler
= Openbox::signalHandler
;
118 action
.sa_mask
= sigset_t();
119 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
120 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
121 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
122 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
123 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
124 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
125 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
127 _property
= new otk::OBProperty();
129 _actions
= new OBActions();
131 setMasterHandler(_actions
); // set as the master event handler
133 // create the mouse cursors we'll use
134 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
135 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
136 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
137 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
138 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
139 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
141 // initialize all the screens
143 screen
= new OBScreen(0, _config
);
144 if (screen
->managed()) {
145 _screens
.push_back(screen
);
146 _screens
[0]->manageExisting();
147 // XXX: "change to" the first workspace on the screen to initialize stuff
151 if (_screens
.empty()) {
152 printf(_("No screens were found without a window manager. Exiting.\n"));
156 // initialize the python interface
157 Py_SetProgramName(argv
[0]);
159 initopenbox(); // initialize the static 'openbox' module
160 FILE *rcpyfd
= fopen("/home/natas/.openbox/user.py", "r");
162 printf("failed to load python file /home/natas/.openbox/user.py\n");
164 PyRun_SimpleFile(rcpyfd
, "/home/natas/.openbox/user.py");
168 _state
= State_Normal
; // done starting
174 _state
= State_Exiting
; // time to kill everything
176 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
178 // close the X display
179 otk::OBDisplay::destroy();
183 void Openbox::parseCommandLine(int argc
, char **argv
)
187 for (int i
= 1; i
< argc
; ++i
) {
188 std::string
arg(argv
[i
]);
190 if (arg
== "-display") {
194 _displayreq
= argv
[i
];
195 } else if (arg
== "-rc") {
199 _rcfilepath
= argv
[i
];
200 } else if (arg
== "-menu") {
204 _menufilepath
= argv
[i
];
205 } else if (arg
== "-version") {
208 } else if (arg
== "-help") {
222 void Openbox::showVersion()
224 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
225 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
229 void Openbox::showHelp()
231 showVersion(); // show the version string and copyright
233 // print program usage and command line options
234 printf(_("Usage: %s [OPTIONS...]\n\
236 -display <string> use display connection.\n\
237 -rc <string> use alternate resource file.\n\
238 -menu <string> use alternate menu file.\n\
239 -version display version and exit.\n\
240 -help display this help text and exit.\n\n"), _argv0
);
242 printf(_("Compile time options:\n\
267 void Openbox::eventLoop()
269 while (!_doshutdown
) {
270 dispatchEvents(); // from OtkEventDispatcher
271 _timermanager
.fire();
276 void Openbox::addClient(Window window
, OBClient
*client
)
278 // maintain the python list here too
279 PyDict_SetItem((PyObject
*)_clients
, PyLong_FromLong(window
),
284 void Openbox::removeClient(Window window
)
286 PyDict_DelItem((PyObject
*)_clients
, PyLong_FromLong(window
));
290 OBClient
*Openbox::findClient(Window window
)
292 PyClientObject
*client
= PyDist_GetItem((PyObject
*)_clients
,
293 PyLong_FromLong(window
));
295 return client
->client
;
This page took 0.044151 seconds and 4 git commands to generate.