]>
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"
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
47 #define _(str) gettext(str)
54 Openbox
*openbox
= (Openbox
*) 0;
57 void Openbox::signalHandler(int signal
)
61 printf("Caught SIGUSR1 signal. Restarting.\n");
69 printf("Caught signal %d. Exiting.\n", signal
);
75 printf("Caught signal %d. Aborting and dumping core.\n", signal
);
81 Openbox::Openbox(int argc
, char **argv
)
82 : otk::EventDispatcher(),
86 struct sigaction action
;
88 _state
= State_Starting
; // initializing everything
92 _displayreq
= (char*) 0;
96 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
97 _scriptfilepath
= otk::expandTilde("~/.openbox/user.py");
101 parseCommandLine(argc
, argv
);
103 XSynchronize(**otk::display
, _sync
);
105 // set up the signal handler
106 action
.sa_handler
= Openbox::signalHandler
;
107 action
.sa_mask
= sigset_t();
108 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
109 sigaction(SIGUSR1
, &action
, (struct sigaction
*) 0);
110 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
111 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
112 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
113 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
114 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
115 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
117 otk::Timer::initialize();
118 otk::Property::initialize();
119 _actions
= new Actions();
120 _bindings
= new Bindings();
122 setMasterHandler(_actions
); // set as the master event handler
124 // create the mouse cursors we'll use
125 _cursors
.session
= XCreateFontCursor(**otk::display
, XC_left_ptr
);
126 _cursors
.move
= XCreateFontCursor(**otk::display
, XC_fleur
);
127 _cursors
.ll_angle
= XCreateFontCursor(**otk::display
, XC_ll_angle
);
128 _cursors
.lr_angle
= XCreateFontCursor(**otk::display
, XC_lr_angle
);
129 _cursors
.ul_angle
= XCreateFontCursor(**otk::display
, XC_ul_angle
);
130 _cursors
.ur_angle
= XCreateFontCursor(**otk::display
, XC_ur_angle
);
132 // initialize scripting
133 python_init(argv
[0]);
135 // load config values
136 python_exec(SCRIPTDIR
"/config.py"); // load openbox config values
137 // run all of the python scripts
138 python_exec(SCRIPTDIR
"/builtins.py"); // builtin callbacks
139 // run the user's script or the system defaults if that fails
140 if (!python_exec(_scriptfilepath
.c_str()))
141 python_exec(SCRIPTDIR
"/defaults.py"); // system default bahaviors
143 // initialize all the screens
145 int i
= _single
? DefaultScreen(**otk::display
) : 0;
146 int max
= _single
? i
+ 1 : ScreenCount(**otk::display
);
147 for (; i
< max
; ++i
) {
148 screen
= new Screen(i
);
149 if (screen
->managed())
150 _screens
.push_back(screen
);
155 if (_screens
.empty()) {
156 printf(_("No screens were found without a window manager. Exiting.\n"));
160 ScreenList::iterator it
, end
= _screens
.end();
161 for (it
= _screens
.begin(); it
!= end
; ++it
) {
162 (*it
)->manageExisting();
165 // grab any keys set up before the screens existed
166 _bindings
->grabKeys(true);
168 // set up input focus
169 _focused_screen
= _screens
[0];
172 _state
= State_Normal
; // done starting
178 _state
= State_Exiting
; // time to kill everything
180 int first_screen
= _screens
.front()->number();
182 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
189 XSetInputFocus(**otk::display
, PointerRoot
, RevertToNone
,
191 XSync(**otk::display
, false);
193 // this tends to block.. i honestly am not sure why. causing an x error in
194 // the shutdown process unblocks it. blackbox simply did a ::exit(0), so
195 // all im gunna do is the same.
196 //otk::display->destroy();
198 otk::Timer::destroy();
201 if (!_restart_prog
.empty()) {
202 const std::string
&dstr
=
203 otk::display
->screenInfo(first_screen
)->displayString();
204 otk::putenv(const_cast<char *>(dstr
.c_str()));
205 execlp(_restart_prog
.c_str(), _restart_prog
.c_str(), NULL
);
206 perror(_restart_prog
.c_str());
209 // fall back in case the above execlp doesn't work
210 execvp(_argv
[0], _argv
);
211 execvp(otk::basename(_argv
[0]).c_str(), _argv
);
216 void Openbox::parseCommandLine(int argc
, char **argv
)
220 for (int i
= 1; i
< argc
; ++i
) {
221 std::string
arg(argv
[i
]);
223 if (arg
== "-display") {
227 _displayreq
= argv
[i
];
228 } else if (arg
== "-rc") {
232 _rcfilepath
= argv
[i
];
233 } else if (arg
== "-menu") {
237 _menufilepath
= argv
[i
];
238 } else if (arg
== "-script") {
242 _scriptfilepath
= argv
[i
];
243 } else if (arg
== "-sync") {
245 } else if (arg
== "-single") {
247 } else if (arg
== "-version") {
250 } else if (arg
== "-help") {
264 void Openbox::showVersion()
266 printf(_("Openbox - version %s\n"), VERSION
);
267 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
271 void Openbox::showHelp()
273 showVersion(); // show the version string and copyright
275 // print program usage and command line options
276 printf(_("Usage: %s [OPTIONS...]\n\
278 -display <string> use display connection.\n\
279 -single run on a single screen (default is to run every one).\n\
280 -rc <string> use alternate resource file.\n\
281 -menu <string> use alternate menu file.\n\
282 -script <string> use alternate startup script file.\n\
283 -sync run in synchronous mode (for debugging).\n\
284 -version display version and exit.\n\
285 -help display this help text and exit.\n\n"), _argv
[0]);
287 printf(_("Compile time options:\n\
319 void Openbox::eventLoop()
322 dispatchEvents(); // from otk::EventDispatcher
323 XFlush(**otk::display
); // flush here before we go wait for timers
324 // don't wait if we're to shutdown
325 if (_shutdown
) break;
326 otk::Timer::dispatchTimers(!_sync
); // wait if not in sync mode
331 void Openbox::addClient(Window window
, Client
*client
)
333 _clients
[window
] = client
;
337 void Openbox::removeClient(Window window
)
339 _clients
.erase(window
);
343 Client
*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())
358 void Openbox::setFocusedClient(Client
*c
)
362 _focused_screen
= _screens
[c
->screen()];
364 assert(_focused_screen
);
365 XSetInputFocus(**otk::display
, _focused_screen
->focuswindow(),
366 RevertToNone
, CurrentTime
);
368 // set the NET_ACTIVE_WINDOW hint for all screens
369 ScreenList::iterator it
, end
= _screens
.end();
370 for (it
= _screens
.begin(); it
!= end
; ++it
) {
371 int num
= (*it
)->number();
372 Window root
= otk::display
->screenInfo(num
)->rootWindow();
373 otk::Property::set(root
, otk::Property::atoms
.net_active_window
,
374 otk::Property::atoms
.window
,
375 (c
&& _focused_screen
== *it
) ? c
->window() : None
);
378 // call the python Focus callbacks
379 EventData
data(_focused_screen
->number(), c
, EventFocus
, 0);
380 _bindings
->fireEvent(&data
);
383 void Openbox::execute(int screen
, const std::string
&bin
)
385 if (screen
>= ScreenCount(**otk::display
))
387 otk::bexec(bin
, otk::display
->screenInfo(screen
)->displayString());
This page took 0.056866 seconds and 4 git commands to generate.