#include <openbox.hh>
Inheritance diagram for ob::Openbox:
Only a single instance of the Openbox class may be used in the application. A pointer to this instance is held in the Openbox::instance static member variable. Instantiation of this class begins the window manager. After instantiation, the Openbox::eventLoop function should be called. The eventLoop method does not exit until the window manager is ready to be destroyed. Destruction of the Openbox class instance will shutdown the window manager.
Definition at line 58 of file openbox.hh.
Public Types | |
typedef std::map< Window, Client * > | ClientMap |
A map for looking up a specific client class from the window id. | |
typedef std::vector< Screen * > | ScreenList |
A list of Screen classes. | |
enum | RunState { State_Starting, State_Normal, State_Exiting } |
The posible running states of the window manager. More... | |
Public Methods | |
Openbox (int argc, char **argv) | |
Openbox constructor. | |
virtual | ~Openbox () |
Openbox destructor. | |
RunState | state () const |
Returns the state of the window manager (starting, exiting, etc). | |
Actions * | actions () const |
Returns the Actions instance for the window manager. | |
Bindings * | bindings () const |
Returns the Bindings instance for the window manager. | |
Screen * | screen (int num) |
Returns a managed screen or a null pointer. | |
const Cursors & | cursors () const |
Returns the mouse cursors used throughout Openbox. | |
void | eventLoop () |
The main function of the Openbox class. | |
void | addClient (Window window, Client *client) |
Adds an Client to the client list for lookups. | |
void | removeClient (Window window) |
Removes an Client from the client list for lookups. | |
Client * | findClient (Window window) |
Finds an Client based on its window id. | |
Client * | focusedClient () |
The client with input focus. | |
void | setFocusedClient (Client *c) |
Change the client which has focus. | |
Screen * | focusedScreen () |
The screen with input focus. | |
void | shutdown () |
Requests that the window manager exit. | |
void | restart (const std::string &bin="") |
bool | doRestart () const |
True if Openbox should be restarted instead of exiting. | |
const std::string & | restartProgram () const |
The command line requested to be executed in place of restarting Openbox the way it was run previously. | |
Private Methods | |
void | parseCommandLine (int argv, char **argv) |
Parses the command line used when executing this application. | |
void | showVersion () |
Displays the version string to stdout. | |
void | showHelp () |
Displays usage information and help to stdout. | |
Static Private Methods | |
void | signalHandler (int signal) |
Handles signal events for the application. | |
Private Attributes | |
otk::Display | _display |
The display on which Openbox is running. | |
std::string | _rcfilepath |
Path to the config file to use/in use. | |
std::string | _menufilepath |
Path to the menu file to use/in use. | |
std::string | _scriptfilepath |
Path to the script file to execute on startup. | |
char * | _displayreq |
The display requested by the user, or null to use the DISPLAY env var. | |
char ** | _argv |
The value of argv, i.e. how this application was executed. | |
bool | _sync |
Run the application in synchronous mode? (for debugging). | |
bool | _single |
Should Openbox run on a single screen or on all available screens? | |
ClientMap | _clients |
A list of all managed clients. | |
ScreenList | _screens |
A list of all the managed screens. | |
Actions * | _actions |
The action interface through which all user-available actions occur. | |
Bindings * | _bindings |
The interface through which keys/buttons are grabbed and handled. | |
RunState | _state |
The running state of the window manager. | |
Cursors | _cursors |
Mouse cursors used throughout Openbox. | |
bool | _shutdown |
When set to true, the Openbox::eventLoop function will stop and return. | |
bool | _restart |
When set to true, and Openbox is about to exit, it will spawn a new process. | |
std::string | _restart_prog |
If this contains anything, a restart will try to execute the program in this variable, and will fallback to reexec'ing itself if that fails. | |
Client * | _focused_client |
The client with input focus. | |
Screen * | _focused_screen |
The screen with input focus. |
|
A map for looking up a specific client class from the window id.
Definition at line 69 of file openbox.hh. |
|
A list of Screen classes.
Definition at line 72 of file openbox.hh. |
|
The posible running states of the window manager.
Definition at line 62 of file openbox.hh. Referenced by state().
00062 { 00063 State_Starting, //!< The window manager is starting up (being created) 00064 State_Normal, //!< The window manager is running in its normal state 00065 State_Exiting //!< The window manager is exiting (being destroyed) 00066 }; |
|
Openbox constructor.
Definition at line 81 of file openbox.cc. References _, _actions, _argv, _bindings, _cursors, _displayreq, _focused_client, _focused_screen, _rcfilepath, _restart, _screens, _scriptfilepath, _shutdown, _single, _state, _sync, otk::expandTilde(), ob::Bindings::grabKeys(), otk::Property::initialize(), otk::Timer::initialize(), otk::RenderColor::initialize(), ob::Cursors::ll_angle, ob::Cursors::lr_angle, ob::Screen::managed(), ob::Cursors::move, ob::openbox, parseCommandLine(), ob::python_exec(), ob::python_init(), screen(), ob::Cursors::session, setFocusedClient(), otk::EventDispatcher::setMasterHandler(), State_Normal, State_Starting, ob::Cursors::ul_angle, and ob::Cursors::ur_angle.
00082 : otk::EventDispatcher(), 00083 otk::EventHandler(), 00084 _display() 00085 { 00086 struct sigaction action; 00087 00088 _state = State_Starting; // initializing everything 00089 00090 openbox = this; 00091 00092 _displayreq = (char*) 0; 00093 _argv = argv; 00094 _shutdown = false; 00095 _restart = false; 00096 _rcfilepath = otk::expandTilde("~/.openbox/rc3"); 00097 _scriptfilepath = otk::expandTilde("~/.openbox/user.py"); 00098 _focused_client = 0; 00099 _sync = false; 00100 _single = false; 00101 00102 parseCommandLine(argc, argv); 00103 00104 XSynchronize(**otk::display, _sync); 00105 00106 // set up the signal handler 00107 action.sa_handler = Openbox::signalHandler; 00108 action.sa_mask = sigset_t(); 00109 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER; 00110 sigaction(SIGUSR1, &action, (struct sigaction *) 0); 00111 sigaction(SIGPIPE, &action, (struct sigaction *) 0); 00112 sigaction(SIGSEGV, &action, (struct sigaction *) 0); 00113 sigaction(SIGFPE, &action, (struct sigaction *) 0); 00114 sigaction(SIGTERM, &action, (struct sigaction *) 0); 00115 sigaction(SIGINT, &action, (struct sigaction *) 0); 00116 sigaction(SIGHUP, &action, (struct sigaction *) 0); 00117 sigaction(SIGCHLD, &action, (struct sigaction *) 0); 00118 00119 // anything that died while we were restarting won't give us a SIGCHLD 00120 while (waitpid(-1, NULL, WNOHANG) > 0); 00121 00122 otk::RenderColor::initialize(); 00123 otk::Timer::initialize(); 00124 otk::Property::initialize(); 00125 _actions = new Actions(); 00126 _bindings = new Bindings(); 00127 00128 setMasterHandler(_actions); // set as the master event handler 00129 00130 // create the mouse cursors we'll use 00131 _cursors.session = XCreateFontCursor(**otk::display, XC_left_ptr); 00132 _cursors.move = XCreateFontCursor(**otk::display, XC_fleur); 00133 _cursors.ll_angle = XCreateFontCursor(**otk::display, XC_ll_angle); 00134 _cursors.lr_angle = XCreateFontCursor(**otk::display, XC_lr_angle); 00135 _cursors.ul_angle = XCreateFontCursor(**otk::display, XC_ul_angle); 00136 _cursors.ur_angle = XCreateFontCursor(**otk::display, XC_ur_angle); 00137 00138 // initialize scripting 00139 python_init(argv[0]); 00140 00141 // load config values 00142 //python_exec(SCRIPTDIR"/config.py"); // load openbox config values 00143 // run all of the python scripts 00144 //python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks 00145 //python_exec(SCRIPTDIR"/focus.py"); // focus helpers 00146 // run the user's script or the system defaults if that fails 00147 if (!python_exec(_scriptfilepath.c_str())) 00148 python_exec(SCRIPTDIR"/defaults.py"); // system default bahaviors 00149 00150 // initialize all the screens 00151 _focused_screen = 0; 00152 00153 for (int i = 0, max = ScreenCount(**otk::display); i < max; ++i) { 00154 Screen *screen; 00155 // in single mode skip the screens we don't want to manage 00156 if (_single && i != DefaultScreen(**otk::display)) { 00157 _screens.push_back(0); 00158 continue; 00159 } 00160 // try manage the screen 00161 screen = new Screen(i); 00162 if (screen->managed()) { 00163 _screens.push_back(screen); 00164 if (!_focused_screen) // set this to the first screen managed 00165 _focused_screen = screen; 00166 } else { 00167 delete screen; 00168 _screens.push_back(0); 00169 } 00170 } 00171 00172 assert(_focused_screen); 00173 00174 if (_screens.empty()) { 00175 printf(_("No screens were found without a window manager. Exiting.\n")); 00176 ::exit(1); 00177 } 00178 00179 ScreenList::iterator it, end = _screens.end(); 00180 for (it = _screens.begin(); it != end; ++it) { 00181 (*it)->manageExisting(); 00182 } 00183 00184 // grab any keys set up before the screens existed 00185 _bindings->grabKeys(true); 00186 00187 // set up input focus 00188 setFocusedClient(0); 00189 00190 _state = State_Normal; // done starting 00191 } |
|
Openbox destructor.
Definition at line 194 of file openbox.cc. References _actions, _bindings, _screens, _state, otk::RenderColor::destroy(), otk::Timer::destroy(), ob::python_destroy(), and State_Exiting.
00195 { 00196 _state = State_Exiting; // time to kill everything 00197 00198 std::for_each(_screens.begin(), _screens.end(), otk::PointerAssassin()); 00199 00200 delete _bindings; 00201 delete _actions; 00202 00203 python_destroy(); 00204 00205 XSetInputFocus(**otk::display, PointerRoot, RevertToNone, 00206 CurrentTime); 00207 XSync(**otk::display, false); 00208 00209 // this tends to block.. i honestly am not sure why. causing an x error in 00210 // the shutdown process unblocks it. blackbox simply did a ::exit(0), so 00211 // all im gunna do is the same. 00212 //delete _display; 00213 00214 otk::Timer::destroy(); 00215 otk::RenderColor::destroy(); 00216 } |
|
Returns the Actions instance for the window manager.
Definition at line 171 of file openbox.hh.
00171 { return _actions; } |
|
Adds an Client to the client list for lookups.
Definition at line 334 of file openbox.cc. References _clients. Referenced by ob::Screen::manageWindow().
00335 { 00336 _clients[window] = client; 00337 } |
|
Returns the Bindings instance for the window manager.
Definition at line 174 of file openbox.hh. Referenced by ob::Actions::buttonPressHandler(), ob::Actions::buttonReleaseHandler(), ob::Actions::enterHandler(), ob::Client::fireUrgent(), ob::Actions::keyPressHandler(), ob::Actions::keyReleaseHandler(), ob::Actions::leaveHandler(), ob::Screen::manageWindow(), ob::Actions::motionHandler(), ob::Screen::Screen(), ob::Screen::unmanageWindow(), and ob::Screen::~Screen().
00174 { return _bindings; } |
|
Returns the mouse cursors used throughout Openbox.
Definition at line 188 of file openbox.hh. Referenced by ob::Frame::Frame(), and ob::Screen::Screen().
00188 { return _cursors; } |
|
True if Openbox should be restarted instead of exiting.
Definition at line 233 of file openbox.hh.
00233 { return _restart; } |
|
The main function of the Openbox class. This function should be called after instantiating the Openbox class. It loops indefinately while handling all events for the application. The Openbox::shutdown method will cause this function to exit. Definition at line 322 of file openbox.cc. References otk::EventDispatcher::dispatchEvents(), and otk::Timer::dispatchTimers().
00323 { 00324 while (true) { 00325 dispatchEvents(); // from otk::EventDispatcher 00326 XFlush(**otk::display); // flush here before we go wait for timers 00327 // don't wait if we're to shutdown 00328 if (_shutdown) break; 00329 otk::Timer::dispatchTimers(!_sync); // wait if not in sync mode 00330 } 00331 } |
|
Finds an Client based on its window id.
Definition at line 346 of file openbox.cc. References _clients. Referenced by ob::Actions::buttonPressHandler(), ob::Actions::buttonReleaseHandler(), ob::Actions::enterHandler(), ob::Actions::insertPress(), ob::Actions::leaveHandler(), ob::Screen::mapRequestHandler(), ob::Actions::motionHandler(), and ob::Client::updateTransientFor().
00347 { 00348 /* 00349 NOTE: we dont use _clients[] to find the value because that will insert 00350 a new null into the hash, which really sucks when we want to clean up the 00351 hash at shutdown! 00352 */ 00353 ClientMap::iterator it = _clients.find(window); 00354 if (it != _clients.end()) 00355 return it->second; 00356 else 00357 return (Client*) 0; 00358 } |
|
The client with input focus.
Definition at line 210 of file openbox.hh. Referenced by ob::Screen::changeDesktop(), ob::Bindings::fireKey(), ob::Client::unfocus(), and ob::Client::unfocusHandler().
00210 { return _focused_client; } |
|
The screen with input focus.
Definition at line 219 of file openbox.hh.
00219 { return _focused_screen; } |
|
Parses the command line used when executing this application.
Definition at line 219 of file openbox.cc. References _displayreq, _menufilepath, _rcfilepath, _scriptfilepath, _single, _sync, showHelp(), and showVersion(). Referenced by Openbox().
00220 { 00221 bool err = false; 00222 00223 for (int i = 1; i < argc; ++i) { 00224 std::string arg(argv[i]); 00225 00226 if (arg == "-display") { 00227 if (++i >= argc) 00228 err = true; 00229 else 00230 _displayreq = argv[i]; 00231 } else if (arg == "-rc") { 00232 if (++i >= argc) 00233 err = true; 00234 else 00235 _rcfilepath = argv[i]; 00236 } else if (arg == "-menu") { 00237 if (++i >= argc) 00238 err = true; 00239 else 00240 _menufilepath = argv[i]; 00241 } else if (arg == "-script") { 00242 if (++i >= argc) 00243 err = true; 00244 else 00245 _scriptfilepath = argv[i]; 00246 } else if (arg == "-sync") { 00247 _sync = true; 00248 } else if (arg == "-single") { 00249 _single = true; 00250 } else if (arg == "-version") { 00251 showVersion(); 00252 ::exit(0); 00253 } else if (arg == "-help") { 00254 showHelp(); 00255 ::exit(0); 00256 } else 00257 err = true; 00258 00259 if (err) { 00260 showHelp(); 00261 exit(1); 00262 } 00263 } 00264 } |
|
Removes an Client from the client list for lookups.
Definition at line 340 of file openbox.cc. References _clients. Referenced by ob::Screen::unmanageWindow().
00341 { 00342 _clients.erase(window); 00343 } |
|
Definition at line 228 of file openbox.hh. Referenced by signalHandler().
00228 { 00229 _shutdown = true; _restart = true; _restart_prog = bin; 00230 } |
|
The command line requested to be executed in place of restarting Openbox the way it was run previously.
Definition at line 237 of file openbox.hh.
00237 { return _restart_prog; } |
|
Returns a managed screen or a null pointer. ALWAYS check the return value for a non-null, as any unmanaged screens will return one. This includes screen(0) if the first managed screen is 1. Definition at line 181 of file openbox.hh. Referenced by ob::Bindings::addButton(), ob::Client::calcLayer(), ob::Client::clientMessageHandler(), ob::Client::configureRequestHandler(), ob::Client::destroyHandler(), ob::Client::fullscreen(), ob::Client::getDesktop(), ob::Bindings::grabKeyboard(), ob::Bindings::grabKeys(), ob::Bindings::grabPointer(), ob::Client::mapRequestHandler(), ob::Client::maximize(), Openbox(), ob::Bindings::removeAllButtons(), ob::Client::reparentHandler(), ob::Client::setDesktop(), ob::Client::setWMState(), ob::Client::unmapHandler(), and ob::Client::updateStrut().
|
|
Change the client which has focus. This is called by the clients themselves when their focus state changes. Definition at line 361 of file openbox.cc. References _bindings, _focused_client, _focused_screen, _screens, ob::Bindings::fireEvent(), ob::Screen::focuswindow(), ob::Screen::installColormap(), ob::Client::installColormap(), ob::Screen::number(), and otk::Property::set(). Referenced by ob::Screen::changeDesktop(), ob::Client::focusHandler(), Openbox(), ob::Client::unfocus(), and ob::Client::unfocusHandler().
00362 { 00363 // sometimes this is called with the already-focused window, this is 00364 // important for the python scripts to work (eg, c = 0 twice). don't just 00365 // return if _focused_client == c 00366 00367 assert(_focused_screen); 00368 00369 // uninstall the old colormap 00370 if (_focused_client) 00371 _focused_client->installColormap(false); 00372 else 00373 _focused_screen->installColormap(false); 00374 00375 _focused_client = c; 00376 if (c) { 00377 _focused_screen = _screens[c->screen()]; 00378 00379 // install the client's colormap 00380 c->installColormap(true); 00381 } else { 00382 XSetInputFocus(**otk::display, _focused_screen->focuswindow(), 00383 RevertToNone, CurrentTime); 00384 00385 // install the root window colormap 00386 _focused_screen->installColormap(true); 00387 } 00388 // set the NET_ACTIVE_WINDOW hint for all screens 00389 ScreenList::iterator it, end = _screens.end(); 00390 for (it = _screens.begin(); it != end; ++it) { 00391 int num = (*it)->number(); 00392 Window root = otk::display->screenInfo(num)->rootWindow(); 00393 otk::Property::set(root, otk::Property::atoms.net_active_window, 00394 otk::Property::atoms.window, 00395 (c && _focused_screen == *it) ? c->window() : None); 00396 } 00397 00398 // call the python Focus callbacks 00399 EventData data(_focused_screen->number(), c, EventAction::Focus, 0); 00400 _bindings->fireEvent(&data); 00401 } |
|
Displays usage information and help to stdout.
Definition at line 274 of file openbox.cc. References _, and showVersion(). Referenced by parseCommandLine().
00275 { 00276 showVersion(); // show the version string and copyright 00277 00278 // print program usage and command line options 00279 printf(_("Usage: %s [OPTIONS...]\n\ 00280 Options:\n\ 00281 -display <string> use display connection.\n\ 00282 -single run on a single screen (default is to run every one).\n\ 00283 -rc <string> use alternate resource file.\n\ 00284 -menu <string> use alternate menu file.\n\ 00285 -script <string> use alternate startup script file.\n\ 00286 -sync run in synchronous mode (for debugging X errors).\n\ 00287 -version display version and exit.\n\ 00288 -help display this help text and exit.\n\n"), _argv[0]); 00289 00290 printf(_("Compile time options:\n\ 00291 Debugging: %s\n\ 00292 Shape: %s\n\ 00293 Xinerama: %s\n\ 00294 Xkb: %s\n"), 00295 #ifdef DEBUG 00296 _("yes"), 00297 #else // !DEBUG 00298 _("no"), 00299 #endif // DEBUG 00300 00301 #ifdef SHAPE 00302 _("yes"), 00303 #else // !SHAPE 00304 _("no"), 00305 #endif // SHAPE 00306 00307 #ifdef XINERAMA 00308 _("yes"), 00309 #else // !XINERAMA 00310 _("no"), 00311 #endif // XINERAMA 00312 00313 #ifdef XKB 00314 _("yes") 00315 #else // !XKB 00316 _("no") 00317 #endif // XKB 00318 ); 00319 } |
|
Displays the version string to stdout.
Definition at line 267 of file openbox.cc. References _. Referenced by parseCommandLine(), and showHelp().
00268 { 00269 printf(_("Openbox - version %s\n"), VERSION); 00270 printf(" (c) 2002 - 2002 Ben Jansens\n\n"); 00271 } |
|
Requests that the window manager exit. Causes the Openbox::eventLoop function to stop looping, so that the window manager can be destroyed. Definition at line 226 of file openbox.hh. Referenced by signalHandler().
00226 { _shutdown = true; } |
|
Handles signal events for the application.
Definition at line 53 of file openbox.cc. References ob::openbox, restart(), and shutdown().
00054 { 00055 switch (signal) { 00056 case SIGUSR1: 00057 printf("Caught SIGUSR1 signal. Restarting.\n"); 00058 openbox->restart(); 00059 break; 00060 00061 case SIGCHLD: 00062 wait(NULL); 00063 break; 00064 00065 case SIGHUP: 00066 case SIGINT: 00067 case SIGTERM: 00068 case SIGPIPE: 00069 printf("Caught signal %d. Exiting.\n", signal); 00070 openbox->shutdown(); 00071 break; 00072 00073 case SIGFPE: 00074 case SIGSEGV: 00075 printf("Caught signal %d. Aborting and dumping core.\n", signal); 00076 abort(); 00077 } 00078 } |
|
Returns the state of the window manager (starting, exiting, etc).
Definition at line 168 of file openbox.hh. References RunState. Referenced by ob::Client::Client(), ob::Frame::grabClient(), ob::Screen::manageWindow(), and ob::Client::~Client().
00168 { return _state; } |
|
The action interface through which all user-available actions occur.
Definition at line 110 of file openbox.hh. Referenced by Openbox(), and ~Openbox(). |
|
The value of argv, i.e. how this application was executed.
Definition at line 97 of file openbox.hh. Referenced by Openbox(). |
|
The interface through which keys/buttons are grabbed and handled.
Definition at line 113 of file openbox.hh. Referenced by Openbox(), setFocusedClient(), and ~Openbox(). |
|
A list of all managed clients.
Definition at line 104 of file openbox.hh. Referenced by addClient(), findClient(), and removeClient(). |
|
Mouse cursors used throughout Openbox.
Definition at line 119 of file openbox.hh. Referenced by Openbox(). |
|
The display on which Openbox is running.
Definition at line 76 of file openbox.hh. |
|
The display requested by the user, or null to use the DISPLAY env var.
Definition at line 95 of file openbox.hh. Referenced by Openbox(), and parseCommandLine(). |
|
The client with input focus. Updated by the clients themselves. Definition at line 136 of file openbox.hh. Referenced by Openbox(), and setFocusedClient(). |
|
The screen with input focus. Updated by the clients when they update the Openbox::focused_client property. Definition at line 143 of file openbox.hh. Referenced by Openbox(), and setFocusedClient(). |
|
Path to the menu file to use/in use. Defaults to /home/xor/.openbox/menu3 Definition at line 88 of file openbox.hh. Referenced by parseCommandLine(). |
|
Path to the config file to use/in use. Defaults to /home/xor/.openbox/rc3 Definition at line 83 of file openbox.hh. Referenced by Openbox(), and parseCommandLine(). |
|
When set to true, and Openbox is about to exit, it will spawn a new process.
Definition at line 126 of file openbox.hh. Referenced by Openbox(). |
|
If this contains anything, a restart will try to execute the program in this variable, and will fallback to reexec'ing itself if that fails.
Definition at line 130 of file openbox.hh. |
|
A list of all the managed screens.
Definition at line 107 of file openbox.hh. Referenced by Openbox(), setFocusedClient(), and ~Openbox(). |
|
Path to the script file to execute on startup. Defaults to /home/xor/.openbox/user.py Definition at line 93 of file openbox.hh. Referenced by Openbox(), and parseCommandLine(). |
|
When set to true, the Openbox::eventLoop function will stop and return.
Definition at line 122 of file openbox.hh. Referenced by Openbox(). |
|
Should Openbox run on a single screen or on all available screens?
Definition at line 101 of file openbox.hh. Referenced by Openbox(), and parseCommandLine(). |
|
The running state of the window manager.
Definition at line 116 of file openbox.hh. Referenced by Openbox(), and ~Openbox(). |
|
Run the application in synchronous mode? (for debugging).
Definition at line 99 of file openbox.hh. Referenced by Openbox(), and parseCommandLine(). |