]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
9d040e14e786b036f37d2bb9bd94fa73a56b4adf
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
10 #include "otk/property.hh"
11 #include "otk/display.hh"
12 #include "otk/assassin.hh"
13 #include "otk/util.hh" // TEMPORARY
16 #include <X11/cursorfont.h>
20 #endif // HAVE_STDIO_H
24 #endif // HAVE_STDLIB_H
28 #endif // HAVE_SIGNAL_H
32 #endif // HAVE_FCNTL_H
35 # include <sys/types.h>
37 #endif // HAVE_UNISTD_H
39 #ifdef HAVE_SYS_SELECT_H
40 # include <sys/select.h>
41 #endif // HAVE_SYS_SELECT_H
44 #define _(str) gettext(str)
51 Openbox
*Openbox::instance
= (Openbox
*) 0;
54 void Openbox::signalHandler(int signal
)
58 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
59 // down and hangs-up on us.
64 printf("Caught signal %d. Exiting.\n", signal
);
70 printf("Caught signal %d. Aborting and dumping core.\n", signal
);
76 Openbox::Openbox(int argc
, char **argv
)
78 struct sigaction action
;
80 _state
= State_Starting
; // initializing everything
82 Openbox::instance
= this;
84 _displayreq
= (char*) 0;
87 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
89 parseCommandLine(argc
, argv
);
91 // TEMPORARY: using the xrdb rc3
92 _config
.setFile(_rcfilepath
);
93 if (!_config
.load()) {
94 printf("failed to load rc file %s\n", _config
.file().c_str());
98 _config
.getValue("session.styleFile", s
);
100 if (!_config
.load()) {
101 printf("failed to load style %s\n", _config
.file().c_str());
105 // open the X display (and gets some info about it, and its screens)
106 otk::OBDisplay::initialize(_displayreq
);
107 assert(otk::OBDisplay::display
);
109 // set up the signal handler
110 action
.sa_handler
= Openbox::signalHandler
;
111 action
.sa_mask
= sigset_t();
112 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
113 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
114 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
115 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
116 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
117 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
118 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
120 _property
= new otk::OBProperty();
122 // create the mouse cursors we'll use
123 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
124 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
125 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
126 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
127 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
128 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
130 // initialize all the screens
131 _screens
.push_back(new OBScreen(0));
132 _screens
[0]->loadStyle(_config
);
134 _state
= State_Normal
; // done starting
140 _state
= State_Exiting
; // time to kill everything
142 // unmanage all windows
143 while (!_clients
.empty())
144 _xeventhandler
.unmanageWindow(_clients
.begin()->second
);
146 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
148 // close the X display
149 otk::OBDisplay::destroy();
153 void Openbox::parseCommandLine(int argc
, char **argv
)
157 for (int i
= 1; i
< argc
; ++i
) {
158 std::string
arg(argv
[i
]);
160 if (arg
== "-display") {
164 _displayreq
= argv
[i
];
165 } else if (arg
== "-rc") {
169 _rcfilepath
= argv
[i
];
170 } else if (arg
== "-menu") {
174 _menufilepath
= argv
[i
];
175 } else if (arg
== "-version") {
178 } else if (arg
== "-help") {
192 void Openbox::showVersion()
194 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
195 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
199 void Openbox::showHelp()
201 showVersion(); // show the version string and copyright
203 // print program usage and command line options
204 printf(_("Usage: %s [OPTIONS...]\n\
206 -display <string> use display connection.\n\
207 -rc <string> use alternate resource file.\n\
208 -menu <string> use alternate menu file.\n\
209 -version display version and exit.\n\
210 -help display this help text and exit.\n\n"), _argv0
);
212 printf(_("Compile time options:\n\
237 void Openbox::eventLoop()
239 while (!_doshutdown
) {
240 if (XPending(otk::OBDisplay::display
)) {
242 XNextEvent(otk::OBDisplay::display
, &e
);
244 _xeventhandler
.handle(e
);
246 _timermanager
.fire();
252 void Openbox::addClient(Window window
, OBClient
*client
)
254 _clients
[window
] = client
;
258 void Openbox::removeClient(Window window
)
260 ClientMap::iterator it
= _clients
.find(window
);
261 if (it
!= _clients
.end())
266 OBClient
*Openbox::findClient(Window window
)
269 NOTE: we dont use _clients[] to find the value because that will insert
270 a new null into the hash, which really sucks when we want to clean up the
273 ClientMap::iterator it
= _clients
.find(window
);
274 if (it
!= _clients
.end())
277 return (OBClient
*) 0;
This page took 0.047496 seconds and 3 git commands to generate.