]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
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
)
77 : otk::OtkEventDispatcher(),
78 otk::OtkEventHandler()
80 struct sigaction action
;
82 _state
= State_Starting
; // initializing everything
84 Openbox::instance
= this;
86 _displayreq
= (char*) 0;
89 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
91 parseCommandLine(argc
, argv
);
93 // TEMPORARY: using the xrdb rc3
94 _config
.setFile(_rcfilepath
);
95 if (!_config
.load()) {
96 printf("failed to load rc file %s\n", _config
.file().c_str());
100 _config
.getValue("session.styleFile", s
);
102 if (!_config
.load()) {
103 printf("failed to load style %s\n", _config
.file().c_str());
107 // open the X display (and gets some info about it, and its screens)
108 otk::OBDisplay::initialize(_displayreq
);
109 assert(otk::OBDisplay::display
);
111 // set up the signal handler
112 action
.sa_handler
= Openbox::signalHandler
;
113 action
.sa_mask
= sigset_t();
114 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
115 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
116 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
117 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
118 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
119 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
120 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
122 _property
= new otk::OBProperty();
124 // create the mouse cursors we'll use
125 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
126 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
127 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
128 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
129 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
130 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
132 // initialize all the screens
134 screen
= new OBScreen(0, _config
);
135 if (screen
->managed()) {
136 _screens
.push_back(screen
);
137 _screens
[0]->manageExisting();
138 // XXX: "change to" the first workspace on the screen to initialize stuff
142 if (_screens
.empty()) {
143 printf(_("No screens were found without a window manager. Exiting.\n"));
147 _state
= State_Normal
; // done starting
153 _state
= State_Exiting
; // time to kill everything
155 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
157 // close the X display
158 otk::OBDisplay::destroy();
162 void Openbox::parseCommandLine(int argc
, char **argv
)
166 for (int i
= 1; i
< argc
; ++i
) {
167 std::string
arg(argv
[i
]);
169 if (arg
== "-display") {
173 _displayreq
= argv
[i
];
174 } else if (arg
== "-rc") {
178 _rcfilepath
= argv
[i
];
179 } else if (arg
== "-menu") {
183 _menufilepath
= argv
[i
];
184 } else if (arg
== "-version") {
187 } else if (arg
== "-help") {
201 void Openbox::showVersion()
203 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
204 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
208 void Openbox::showHelp()
210 showVersion(); // show the version string and copyright
212 // print program usage and command line options
213 printf(_("Usage: %s [OPTIONS...]\n\
215 -display <string> use display connection.\n\
216 -rc <string> use alternate resource file.\n\
217 -menu <string> use alternate menu file.\n\
218 -version display version and exit.\n\
219 -help display this help text and exit.\n\n"), _argv0
);
221 printf(_("Compile time options:\n\
246 void Openbox::eventLoop()
248 while (!_doshutdown
) {
249 dispatchEvents(); // from OtkEventDispatcher
250 _timermanager
.fire();
255 void Openbox::addClient(Window window
, OBClient
*client
)
257 _clients
[window
] = client
;
261 void Openbox::removeClient(Window window
)
263 _clients
[window
] = 0;
264 ClientMap::iterator it
= _clients
.find(window
);
265 if (it
!= _clients
.end())
270 OBClient
*Openbox::findClient(Window window
)
273 NOTE: we dont use _clients[] to find the value because that will insert
274 a new null into the hash, which really sucks when we want to clean up the
277 ClientMap::iterator it
= _clients
.find(window
);
278 if (it
!= _clients
.end())
281 return (OBClient
*) 0;
This page took 0.043827 seconds and 4 git commands to generate.