]>
Dogcows Code - chaz/openbox/blob - openbox.cc
ad31718359a335c69c65d1d27ba7f00354e5de4c
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");
114 parseCommandLine(argc
, argv
);
116 // TEMPORARY: using the xrdb rc3
117 _config
.setFile(_rcfilepath
);
118 if (!_config
.load()) {
119 printf("failed to load rc file %s\n", _config
.file().c_str());
123 _config
.getValue("session.styleFile", s
);
125 if (!_config
.load()) {
126 printf("failed to load style %s\n", _config
.file().c_str());
130 // open the X display (and gets some info about it, and its screens)
131 otk::OBDisplay::initialize(_displayreq
);
132 assert(otk::OBDisplay::display
);
134 XSynchronize(otk::OBDisplay::display
, _sync
);
136 // set up the signal handler
137 action
.sa_handler
= Openbox::signalHandler
;
138 action
.sa_mask
= sigset_t();
139 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
140 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
141 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
142 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
143 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
144 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
145 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
147 _property
= new otk::OBProperty();
149 _actions
= new OBActions();
151 setMasterHandler(_actions
); // set as the master event handler
153 // create the mouse cursors we'll use
154 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
155 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
156 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
157 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
158 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
159 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
161 // start up python and run the user's startup script
162 Py_SetProgramName(argv
[0]);
166 PyRun_SimpleString("from _otk import *; from _openbox import *;");
167 PyRun_SimpleString("openbox = Openbox_instance()");
169 runPython(SCRIPTDIR
"/clientmotion.py"); // moving and resizing clients
170 runPython(SCRIPTDIR
"/clicks.py"); // titlebar/root clicks and dblclicks
171 runPython(_scriptfilepath
.c_str());
173 // initialize all the screens
175 screen
= new OBScreen(0, _config
);
176 if (screen
->managed()) {
177 _screens
.push_back(screen
);
178 _screens
[0]->manageExisting();
179 // XXX: "change to" the first workspace on the screen to initialize stuff
183 if (_screens
.empty()) {
184 printf(_("No screens were found without a window manager. Exiting.\n"));
188 // set up input focus
189 _focused_screen
= _screens
[0];
192 _state
= State_Normal
; // done starting
198 _state
= State_Exiting
; // time to kill everything
200 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
202 // close the X display
203 otk::OBDisplay::destroy();
207 void Openbox::parseCommandLine(int argc
, char **argv
)
211 for (int i
= 1; i
< argc
; ++i
) {
212 std::string
arg(argv
[i
]);
214 if (arg
== "-display") {
218 _displayreq
= argv
[i
];
219 } else if (arg
== "-rc") {
223 _rcfilepath
= argv
[i
];
224 } else if (arg
== "-menu") {
228 _menufilepath
= argv
[i
];
229 } else if (arg
== "-script") {
233 _scriptfilepath
= argv
[i
];
234 } else if (arg
== "-sync") {
236 } else if (arg
== "-version") {
239 } else if (arg
== "-help") {
253 void Openbox::showVersion()
255 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
256 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
260 void Openbox::showHelp()
262 showVersion(); // show the version string and copyright
264 // print program usage and command line options
265 printf(_("Usage: %s [OPTIONS...]\n\
267 -display <string> use display connection.\n\
268 -rc <string> use alternate resource file.\n\
269 -menu <string> use alternate menu file.\n\
270 -script <string> use alternate startup script file.\n\
271 -version display version and exit.\n\
272 -help display this help text and exit.\n\n"), _argv0
);
274 printf(_("Compile time options:\n\
299 void Openbox::eventLoop()
301 while (!_doshutdown
) {
302 dispatchEvents(); // from OtkEventDispatcher
303 XFlush(otk::OBDisplay::display
); // flush here before we go wait for timers
304 _timermanager
.fire();
309 void Openbox::addClient(Window window
, OBClient
*client
)
311 _clients
[window
] = client
;
315 void Openbox::removeClient(Window window
)
317 _clients
.erase(window
);
321 OBClient
*Openbox::findClient(Window window
)
324 NOTE: we dont use _clients[] to find the value because that will insert
325 a new null into the hash, which really sucks when we want to clean up the
328 ClientMap::iterator it
= _clients
.find(window
);
329 if (it
!= _clients
.end())
332 return (OBClient
*) 0;
336 void Openbox::setFocusedClient(OBClient
*c
)
340 _focused_screen
= _screens
[c
->screen()];
342 assert(_focused_screen
);
343 XSetInputFocus(otk::OBDisplay::display
, _focused_screen
->focuswindow(),
344 RevertToNone
, CurrentTime
);
This page took 0.046744 seconds and 3 git commands to generate.