]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
11 #include "bindings.hh"
13 #include "otk/property.hh"
14 #include "otk/assassin.hh"
15 #include "otk/property.hh"
16 #include "otk/util.hh"
17 #include "otk/rendercolor.hh"
18 #include "otk/renderstyle.hh"
21 #include <X11/cursorfont.h>
25 #endif // HAVE_STDIO_H
29 #endif // HAVE_STDLIB_H
33 #endif // HAVE_SIGNAL_H
37 #endif // HAVE_FCNTL_H
39 #ifdef HAVE_SYS_WAIT_H
40 # include <sys/wait.h>
41 #endif // HAVE_SYS_WAIT_H
44 #define _(str) gettext(str)
51 Openbox
*openbox
= (Openbox
*) 0;
54 void Openbox::signalHandler(int signal
)
58 printf("Caught SIGUSR1 signal. Restarting.\n");
70 printf("Caught signal %d. Exiting.\n", signal
);
76 printf("Caught signal %d. Aborting and dumping core.\n", signal
);
82 Openbox::Openbox(int argc
, char **argv
)
83 : otk::EventDispatcher(),
87 struct sigaction action
;
89 _state
= State_Starting
; // initializing everything
93 _displayreq
= (char*) 0;
97 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
98 _scriptfilepath
= otk::expandTilde("~/.openbox/user.py");
103 parseCommandLine(argc
, argv
);
105 XSynchronize(**otk::display
, _sync
);
107 // set up the signal handler
108 action
.sa_handler
= Openbox::signalHandler
;
109 action
.sa_mask
= sigset_t();
110 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
111 sigaction(SIGUSR1
, &action
, (struct sigaction
*) 0);
112 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
113 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
114 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
115 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
116 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
117 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
118 sigaction(SIGCHLD
, &action
, (struct sigaction
*) 0);
120 // anything that died while we were restarting won't give us a SIGCHLD
121 while (waitpid(-1, NULL
, WNOHANG
) > 0);
123 otk::RenderColor::initialize();
124 otk::RenderStyle::initialize();
125 otk::Timer::initialize();
126 otk::Property::initialize();
127 _actions
= new Actions();
128 _bindings
= new Bindings();
130 setMasterHandler(_actions
); // set as the master event handler
132 // create the mouse cursors we'll use
133 _cursors
.session
= XCreateFontCursor(**otk::display
, XC_left_ptr
);
134 _cursors
.move
= XCreateFontCursor(**otk::display
, XC_fleur
);
135 _cursors
.ll_angle
= XCreateFontCursor(**otk::display
, XC_ll_angle
);
136 _cursors
.lr_angle
= XCreateFontCursor(**otk::display
, XC_lr_angle
);
137 _cursors
.ul_angle
= XCreateFontCursor(**otk::display
, XC_ul_angle
);
138 _cursors
.ur_angle
= XCreateFontCursor(**otk::display
, XC_ur_angle
);
140 // initialize scripting
141 python_init(argv
[0]);
143 // load config values
144 //python_exec(SCRIPTDIR"/config.py"); // load openbox config values
145 // run all of the python scripts
146 //python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks
147 //python_exec(SCRIPTDIR"/focus.py"); // focus helpers
148 // run the user's script or the system defaults if that fails
149 if (!python_exec(_scriptfilepath
.c_str()))
150 python_exec(SCRIPTDIR
"/defaults.py"); // system default bahaviors
152 // initialize all the screens
155 for (int i
= 0, max
= ScreenCount(**otk::display
); i
< max
; ++i
) {
157 // in single mode skip the screens we don't want to manage
158 if (_single
&& i
!= DefaultScreen(**otk::display
)) {
159 _screens
.push_back(0);
162 // try manage the screen
163 screen
= new Screen(i
);
164 if (screen
->managed()) {
165 _screens
.push_back(screen
);
166 if (!_focused_screen
) // set this to the first screen managed
167 _focused_screen
= screen
;
170 _screens
.push_back(0);
174 assert(_focused_screen
);
176 if (_screens
.empty()) {
177 printf(_("No screens were found without a window manager. Exiting.\n"));
181 ScreenList::iterator it
, end
= _screens
.end();
182 for (it
= _screens
.begin(); it
!= end
; ++it
) {
183 (*it
)->manageExisting();
186 // grab any keys set up before the screens existed
187 _bindings
->grabKeys(true);
189 // set up input focus
192 _state
= State_Normal
; // done starting
198 _state
= State_Exiting
; // time to kill everything
200 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
207 XSetInputFocus(**otk::display
, PointerRoot
, RevertToNone
,
209 XSync(**otk::display
, false);
211 // this tends to block.. i honestly am not sure why. causing an x error in
212 // the shutdown process unblocks it. blackbox simply did a ::exit(0), so
213 // all im gunna do is the same.
216 otk::Timer::destroy();
217 otk::RenderStyle::destroy();
218 otk::RenderColor::destroy();
222 void Openbox::parseCommandLine(int argc
, char **argv
)
226 for (int i
= 1; i
< argc
; ++i
) {
227 std::string
arg(argv
[i
]);
229 if (arg
== "-display") {
233 _displayreq
= argv
[i
];
234 } else if (arg
== "-rc") {
238 _rcfilepath
= argv
[i
];
239 } else if (arg
== "-menu") {
243 _menufilepath
= argv
[i
];
244 } else if (arg
== "-script") {
248 _scriptfilepath
= argv
[i
];
249 } else if (arg
== "-sync") {
251 } else if (arg
== "-single") {
253 } else if (arg
== "-version") {
256 } else if (arg
== "-help") {
270 void Openbox::showVersion()
272 printf(_("Openbox - version %s\n"), VERSION
);
273 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
277 void Openbox::showHelp()
279 showVersion(); // show the version string and copyright
281 // print program usage and command line options
282 printf(_("Usage: %s [OPTIONS...]\n\
284 -display <string> use display connection.\n\
285 -single run on a single screen (default is to run every one).\n\
286 -rc <string> use alternate resource file.\n\
287 -menu <string> use alternate menu file.\n\
288 -script <string> use alternate startup script file.\n\
289 -sync run in synchronous mode (for debugging X errors).\n\
290 -version display version and exit.\n\
291 -help display this help text and exit.\n\n"), _argv
[0]);
293 printf(_("Compile time options:\n\
325 void Openbox::eventLoop()
328 dispatchEvents(); // from otk::EventDispatcher
329 XFlush(**otk::display
); // flush here before we go wait for timers
330 // don't wait if we're to shutdown
331 if (_shutdown
) break;
332 otk::Timer::dispatchTimers(!_sync
); // wait if not in sync mode
337 void Openbox::addClient(Window window
, Client
*client
)
339 _clients
[window
] = client
;
343 void Openbox::removeClient(Window window
)
345 _clients
.erase(window
);
349 Client
*Openbox::findClient(Window window
)
352 NOTE: we dont use _clients[] to find the value because that will insert
353 a new null into the hash, which really sucks when we want to clean up the
356 ClientMap::iterator it
= _clients
.find(window
);
357 if (it
!= _clients
.end())
364 void Openbox::setFocusedClient(Client
*c
)
366 // sometimes this is called with the already-focused window, this is
367 // important for the python scripts to work (eg, c = 0 twice). don't just
368 // return if _focused_client == c
370 assert(_focused_screen
);
372 // uninstall the old colormap
374 _focused_client
->installColormap(false);
376 _focused_screen
->installColormap(false);
380 _focused_screen
= _screens
[c
->screen()];
382 // install the client's colormap
383 c
->installColormap(true);
385 XSetInputFocus(**otk::display
, _focused_screen
->focuswindow(),
386 RevertToNone
, CurrentTime
);
388 // install the root window colormap
389 _focused_screen
->installColormap(true);
391 // set the NET_ACTIVE_WINDOW hint for all screens
392 ScreenList::iterator it
, end
= _screens
.end();
393 for (it
= _screens
.begin(); it
!= end
; ++it
) {
394 int num
= (*it
)->number();
395 Window root
= otk::display
->screenInfo(num
)->rootWindow();
396 otk::Property::set(root
, otk::Property::atoms
.net_active_window
,
397 otk::Property::atoms
.window
,
398 (c
&& _focused_screen
== *it
) ? c
->window() : None
);
401 // call the python Focus callbacks
402 EventData
data(_focused_screen
->number(), c
, EventAction::Focus
, 0);
403 _bindings
->fireEvent(&data
);
This page took 0.057103 seconds and 4 git commands to generate.