]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "../version.h"
12 #include "bindings.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
48 // The initializer in openbox_wrap.cc
49 extern void init_openbox(void);
50 // The initializer in otk_wrap.cc
51 extern void init_otk(void);
54 #define _(str) gettext(str)
61 Openbox
*Openbox::instance
= (Openbox
*) 0;
64 void Openbox::signalHandler(int signal
)
68 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
69 // down and hangs-up on us.
74 printf("Caught signal %d. Exiting.\n", signal
);
80 printf("Caught signal %d. Aborting and dumping core.\n", signal
);
86 static void runPython(const char *s
) {
87 FILE *rcpyfd
= fopen(s
, "r");
89 printf("failed to load python file %s\n", s
);
91 PyRun_SimpleFile(rcpyfd
, const_cast<char*>(s
));
97 Openbox::Openbox(int argc
, char **argv
)
98 : otk::OtkEventDispatcher(),
99 otk::OtkEventHandler()
101 struct sigaction action
;
103 _state
= State_Starting
; // initializing everything
105 Openbox::instance
= this;
107 _displayreq
= (char*) 0;
110 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
111 _scriptfilepath
= otk::expandTilde("~/.openbox/user.py");
115 parseCommandLine(argc
, argv
);
117 // TEMPORARY: using the xrdb rc3
118 _config
.setFile(_rcfilepath
);
119 if (!_config
.load()) {
120 printf("failed to load rc file %s\n", _config
.file().c_str());
124 _config
.getValue("session.styleFile", s
);
126 if (!_config
.load()) {
127 printf("failed to load style %s\n", _config
.file().c_str());
131 // open the X display (and gets some info about it, and its screens)
132 otk::OBDisplay::initialize(_displayreq
);
133 assert(otk::OBDisplay::display
);
135 XSynchronize(otk::OBDisplay::display
, _sync
);
137 // set up the signal handler
138 action
.sa_handler
= Openbox::signalHandler
;
139 action
.sa_mask
= sigset_t();
140 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
141 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
142 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
143 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
144 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
145 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
146 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
148 _property
= new otk::OBProperty();
149 _actions
= new OBActions();
150 _bindings
= new OBBindings();
152 OBBindings::StringVect v
;
153 v
.push_back("C-A-x");
156 _bindings
->add_key(v
, 1);
158 // v.push_back("C-x");
159 // v.push_back("C-z");
161 _bindings
->add_key(v
, 2);
163 _bindings
->add_mouse("A-1", 1);
166 _bindings
->display();
169 setMasterHandler(_actions
); // set as the master event handler
171 // create the mouse cursors we'll use
172 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
173 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
174 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
175 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
176 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
177 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
179 // start up python and run the user's startup script
180 Py_SetProgramName(argv
[0]);
184 PyRun_SimpleString("from _otk import *; from _openbox import *;");
185 PyRun_SimpleString("openbox = Openbox_instance()");
187 runPython(SCRIPTDIR
"/clientmotion.py"); // moving and resizing clients
188 runPython(SCRIPTDIR
"/clicks.py"); // titlebar/root clicks and dblclicks
189 runPython(_scriptfilepath
.c_str());
191 // initialize all the screens
193 screen
= new OBScreen(0, _config
);
194 if (screen
->managed()) {
195 _screens
.push_back(screen
);
196 _screens
[0]->manageExisting();
197 // XXX: "change to" the first workspace on the screen to initialize stuff
201 if (_screens
.empty()) {
202 printf(_("No screens were found without a window manager. Exiting.\n"));
206 // set up input focus
207 _focused_screen
= _screens
[0];
210 _state
= State_Normal
; // done starting
216 _state
= State_Exiting
; // time to kill everything
218 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
224 // close the X display
225 otk::OBDisplay::destroy();
229 void Openbox::parseCommandLine(int argc
, char **argv
)
233 for (int i
= 1; i
< argc
; ++i
) {
234 std::string
arg(argv
[i
]);
236 if (arg
== "-display") {
240 _displayreq
= argv
[i
];
241 } else if (arg
== "-rc") {
245 _rcfilepath
= argv
[i
];
246 } else if (arg
== "-menu") {
250 _menufilepath
= argv
[i
];
251 } else if (arg
== "-script") {
255 _scriptfilepath
= argv
[i
];
256 } else if (arg
== "-sync") {
258 } else if (arg
== "-version") {
261 } else if (arg
== "-help") {
275 void Openbox::showVersion()
277 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
278 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
282 void Openbox::showHelp()
284 showVersion(); // show the version string and copyright
286 // print program usage and command line options
287 printf(_("Usage: %s [OPTIONS...]\n\
289 -display <string> use display connection.\n\
290 -rc <string> use alternate resource file.\n\
291 -menu <string> use alternate menu file.\n\
292 -script <string> use alternate startup script file.\n\
293 -version display version and exit.\n\
294 -help display this help text and exit.\n\n"), _argv0
);
296 printf(_("Compile time options:\n\
321 void Openbox::eventLoop()
323 while (!_doshutdown
) {
324 dispatchEvents(); // from OtkEventDispatcher
325 XFlush(otk::OBDisplay::display
); // flush here before we go wait for timers
326 _timermanager
.fire();
331 void Openbox::addClient(Window window
, OBClient
*client
)
333 _clients
[window
] = client
;
337 void Openbox::removeClient(Window window
)
339 _clients
.erase(window
);
343 OBClient
*Openbox::findClient(Window window
)
346 NOTE: we dont use _clients[] to find the value because that will insert
347 a new null into the hash, which really sucks when we want to clean up the
350 ClientMap::iterator it
= _clients
.find(window
);
351 if (it
!= _clients
.end())
354 return (OBClient
*) 0;
358 void Openbox::setFocusedClient(OBClient
*c
)
362 _focused_screen
= _screens
[c
->screen()];
364 assert(_focused_screen
);
365 XSetInputFocus(otk::OBDisplay::display
, _focused_screen
->focuswindow(),
366 RevertToNone
, CurrentTime
);
This page took 0.053363 seconds and 4 git commands to generate.