]>
Dogcows Code - chaz/openbox/blob - openbox.cc
cf41975d3c2af08f5c509eed6d2f8b4e19873a02
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
47 // The initializer in openbox_wrap.cc
48 extern void init_openbox(void);
49 // The initializer in otk_wrap.cc
50 extern void init_otk(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 static void runPython(const char *s
) {
86 FILE *rcpyfd
= fopen(s
, "r");
88 printf("failed to load python file %s\n", s
);
90 PyRun_SimpleFile(rcpyfd
, const_cast<char*>(s
));
96 Openbox::Openbox(int argc
, char **argv
)
97 : otk::OtkEventDispatcher(),
98 otk::OtkEventHandler()
100 struct sigaction action
;
102 _state
= State_Starting
; // initializing everything
104 Openbox::instance
= this;
106 _displayreq
= (char*) 0;
109 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
110 _scriptfilepath
= otk::expandTilde("~/.openbox/user.py");
112 parseCommandLine(argc
, argv
);
114 // TEMPORARY: using the xrdb rc3
115 _config
.setFile(_rcfilepath
);
116 if (!_config
.load()) {
117 printf("failed to load rc file %s\n", _config
.file().c_str());
121 _config
.getValue("session.styleFile", s
);
123 if (!_config
.load()) {
124 printf("failed to load style %s\n", _config
.file().c_str());
128 // open the X display (and gets some info about it, and its screens)
129 otk::OBDisplay::initialize(_displayreq
);
130 assert(otk::OBDisplay::display
);
132 // set up the signal handler
133 action
.sa_handler
= Openbox::signalHandler
;
134 action
.sa_mask
= sigset_t();
135 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
136 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
137 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
138 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
139 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
140 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
141 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
143 _property
= new otk::OBProperty();
145 _actions
= new OBActions();
147 setMasterHandler(_actions
); // set as the master event handler
149 // create the mouse cursors we'll use
150 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
151 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
152 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
153 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
154 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
155 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
157 // start up python and run the user's startup script
158 Py_SetProgramName(argv
[0]);
162 PyRun_SimpleString("from _otk import *; from _openbox import *;");
163 PyRun_SimpleString("openbox = Openbox_instance()");
165 runPython(SCRIPTDIR
"/clientmotion.py"); // moving and resizing clients
166 runPython(_scriptfilepath
.c_str());
168 // initialize all the screens
170 screen
= new OBScreen(0, _config
);
171 if (screen
->managed()) {
172 _screens
.push_back(screen
);
173 _screens
[0]->manageExisting();
174 // XXX: "change to" the first workspace on the screen to initialize stuff
178 if (_screens
.empty()) {
179 printf(_("No screens were found without a window manager. Exiting.\n"));
183 _state
= State_Normal
; // done starting
189 _state
= State_Exiting
; // time to kill everything
191 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
193 // close the X display
194 otk::OBDisplay::destroy();
198 void Openbox::parseCommandLine(int argc
, char **argv
)
202 for (int i
= 1; i
< argc
; ++i
) {
203 std::string
arg(argv
[i
]);
205 if (arg
== "-display") {
209 _displayreq
= argv
[i
];
210 } else if (arg
== "-rc") {
214 _rcfilepath
= argv
[i
];
215 } else if (arg
== "-menu") {
219 _menufilepath
= argv
[i
];
220 } else if (arg
== "-script") {
224 _scriptfilepath
= argv
[i
];
225 } else if (arg
== "-version") {
228 } else if (arg
== "-help") {
242 void Openbox::showVersion()
244 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
245 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
249 void Openbox::showHelp()
251 showVersion(); // show the version string and copyright
253 // print program usage and command line options
254 printf(_("Usage: %s [OPTIONS...]\n\
256 -display <string> use display connection.\n\
257 -rc <string> use alternate resource file.\n\
258 -menu <string> use alternate menu file.\n\
259 -script <string> use alternate startup script file.\n\
260 -version display version and exit.\n\
261 -help display this help text and exit.\n\n"), _argv0
);
263 printf(_("Compile time options:\n\
288 void Openbox::eventLoop()
290 while (!_doshutdown
) {
291 dispatchEvents(); // from OtkEventDispatcher
292 _timermanager
.fire();
297 void Openbox::addClient(Window window
, OBClient
*client
)
299 _clients
[window
] = client
;
303 void Openbox::removeClient(Window window
)
305 _clients
.erase(window
);
309 OBClient
*Openbox::findClient(Window window
)
312 NOTE: we dont use _clients[] to find the value because that will insert
313 a new null into the hash, which really sucks when we want to clean up the
316 ClientMap::iterator it
= _clients
.find(window
);
317 if (it
!= _clients
.end())
320 return (OBClient
*) 0;
This page took 0.04458 seconds and 3 git commands to generate.