]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
12 #include "otk/property.hh"
13 #include "otk/display.hh"
14 #include "otk/assassin.hh"
15 #include "otk/util.hh" // TEMPORARY
18 #include <X11/cursorfont.h>
22 #endif // HAVE_STDIO_H
26 #endif // HAVE_STDLIB_H
30 #endif // HAVE_SIGNAL_H
34 #endif // HAVE_FCNTL_H
37 # include <sys/types.h>
39 #endif // HAVE_UNISTD_H
41 #ifdef HAVE_SYS_SELECT_H
42 # include <sys/select.h>
43 #endif // HAVE_SYS_SELECT_H
46 #define _(str) gettext(str)
53 Openbox
*Openbox::instance
= (Openbox
*) 0;
54 OBActions
*Openbox::actions
= (OBActions
*) 0;
57 void Openbox::signalHandler(int signal
)
61 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
62 // down and hangs-up on us.
67 printf("Caught signal %d. Exiting.\n", signal
);
73 printf("Caught signal %d. Aborting and dumping core.\n", signal
);
79 Openbox::Openbox(int argc
, char **argv
)
80 : otk::OtkEventDispatcher(),
81 otk::OtkEventHandler()
83 struct sigaction action
;
85 _state
= State_Starting
; // initializing everything
87 Openbox::instance
= this;
89 _displayreq
= (char*) 0;
92 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
94 parseCommandLine(argc
, argv
);
96 // TEMPORARY: using the xrdb rc3
97 _config
.setFile(_rcfilepath
);
98 if (!_config
.load()) {
99 printf("failed to load rc file %s\n", _config
.file().c_str());
103 _config
.getValue("session.styleFile", s
);
105 if (!_config
.load()) {
106 printf("failed to load style %s\n", _config
.file().c_str());
110 // open the X display (and gets some info about it, and its screens)
111 otk::OBDisplay::initialize(_displayreq
);
112 assert(otk::OBDisplay::display
);
114 // set up the signal handler
115 action
.sa_handler
= Openbox::signalHandler
;
116 action
.sa_mask
= sigset_t();
117 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
118 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
119 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
120 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
121 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
122 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
123 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
125 _property
= new otk::OBProperty();
127 Openbox::actions
= new OBActions();
129 setMasterHandler(Openbox::actions
); // set as the master event handler
131 // create the mouse cursors we'll use
132 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
133 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
134 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
135 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
136 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
137 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
139 // initialize all the screens
141 screen
= new OBScreen(0, _config
);
142 if (screen
->managed()) {
143 _screens
.push_back(screen
);
144 _screens
[0]->manageExisting();
145 // XXX: "change to" the first workspace on the screen to initialize stuff
149 if (_screens
.empty()) {
150 printf(_("No screens were found without a window manager. Exiting.\n"));
154 _state
= State_Normal
; // done starting
160 _state
= State_Exiting
; // time to kill everything
162 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
164 // close the X display
165 otk::OBDisplay::destroy();
169 void Openbox::parseCommandLine(int argc
, char **argv
)
173 for (int i
= 1; i
< argc
; ++i
) {
174 std::string
arg(argv
[i
]);
176 if (arg
== "-display") {
180 _displayreq
= argv
[i
];
181 } else if (arg
== "-rc") {
185 _rcfilepath
= argv
[i
];
186 } else if (arg
== "-menu") {
190 _menufilepath
= argv
[i
];
191 } else if (arg
== "-version") {
194 } else if (arg
== "-help") {
208 void Openbox::showVersion()
210 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
211 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
215 void Openbox::showHelp()
217 showVersion(); // show the version string and copyright
219 // print program usage and command line options
220 printf(_("Usage: %s [OPTIONS...]\n\
222 -display <string> use display connection.\n\
223 -rc <string> use alternate resource file.\n\
224 -menu <string> use alternate menu file.\n\
225 -version display version and exit.\n\
226 -help display this help text and exit.\n\n"), _argv0
);
228 printf(_("Compile time options:\n\
253 void Openbox::eventLoop()
255 while (!_doshutdown
) {
256 dispatchEvents(); // from OtkEventDispatcher
257 _timermanager
.fire();
262 void Openbox::addClient(Window window
, OBClient
*client
)
264 _clients
[window
] = client
;
268 void Openbox::removeClient(Window window
)
270 _clients
.erase(window
);
274 OBClient
*Openbox::findClient(Window window
)
277 NOTE: we dont use _clients[] to find the value because that will insert
278 a new null into the hash, which really sucks when we want to clean up the
281 ClientMap::iterator it
= _clients
.find(window
);
282 if (it
!= _clients
.end())
285 return (OBClient
*) 0;
This page took 0.04346 seconds and 4 git commands to generate.