]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "../version.h"
12 #include "bindings.hh"
14 #include "otk/property.hh"
15 #include "otk/display.hh"
16 #include "otk/assassin.hh"
17 #include "otk/util.hh" // TEMPORARY
20 #include <X11/cursorfont.h>
24 #endif // HAVE_STDIO_H
28 #endif // HAVE_STDLIB_H
32 #endif // HAVE_SIGNAL_H
36 #endif // HAVE_FCNTL_H
39 # include <sys/types.h>
41 #endif // HAVE_UNISTD_H
43 #ifdef HAVE_SYS_SELECT_H
44 # include <sys/select.h>
45 #endif // HAVE_SYS_SELECT_H
48 #define _(str) gettext(str)
55 Openbox
*Openbox::instance
= (Openbox
*) 0;
58 void Openbox::signalHandler(int signal
)
62 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
63 // down and hangs-up on us.
68 printf("Caught signal %d. Exiting.\n", signal
);
74 printf("Caught signal %d. Aborting and dumping core.\n", signal
);
80 Openbox::Openbox(int argc
, char **argv
)
81 : otk::OtkEventDispatcher(),
82 otk::OtkEventHandler()
84 struct sigaction action
;
86 _state
= State_Starting
; // initializing everything
88 Openbox::instance
= this;
90 _displayreq
= (char*) 0;
93 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
94 _scriptfilepath
= otk::expandTilde("~/.openbox/user.py");
98 parseCommandLine(argc
, argv
);
100 // open the X display (and gets some info about it, and its screens)
101 otk::OBDisplay::initialize(_displayreq
);
102 assert(otk::OBDisplay::display
);
104 XSynchronize(otk::OBDisplay::display
, _sync
);
106 // set up the signal handler
107 action
.sa_handler
= Openbox::signalHandler
;
108 action
.sa_mask
= sigset_t();
109 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
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 _property
= new otk::OBProperty();
118 _actions
= new OBActions();
119 _bindings
= new OBBindings();
121 setMasterHandler(_actions
); // set as the master event handler
123 // create the mouse cursors we'll use
124 _cursors
.session
= XCreateFontCursor(otk::OBDisplay::display
, XC_left_ptr
);
125 _cursors
.move
= XCreateFontCursor(otk::OBDisplay::display
, XC_fleur
);
126 _cursors
.ll_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ll_angle
);
127 _cursors
.lr_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_lr_angle
);
128 _cursors
.ul_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ul_angle
);
129 _cursors
.ur_angle
= XCreateFontCursor(otk::OBDisplay::display
, XC_ur_angle
);
131 // initialize scripting
132 python_init(argv
[0]);
134 // load config values
135 python_exec(SCRIPTDIR
"/config.py"); // load openbox config values
136 // run all of the python scripts
137 python_exec(SCRIPTDIR
"/builtins.py"); // builtin callbacks
138 // run the user's script
139 python_exec(_scriptfilepath
.c_str());
141 // initialize all the screens
143 screen
= new OBScreen(0);
144 if (screen
->managed()) {
145 _screens
.push_back(screen
);
146 // XXX: "change to" the first workspace on the screen to initialize stuff
150 if (_screens
.empty()) {
151 printf(_("No screens were found without a window manager. Exiting.\n"));
155 ScreenList::iterator it
, end
= _screens
.end();
156 for (it
= _screens
.begin(); it
!= end
; ++it
) {
157 (*it
)->manageExisting();
160 // grab any keys set up before the screens existed
161 _bindings
->grabKeys(true);
163 // set up input focus
164 _focused_screen
= _screens
[0];
167 _state
= State_Normal
; // done starting
173 _state
= State_Exiting
; // time to kill everything
175 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
183 // close the X display
184 otk::OBDisplay::destroy();
188 void Openbox::parseCommandLine(int argc
, char **argv
)
192 for (int i
= 1; i
< argc
; ++i
) {
193 std::string
arg(argv
[i
]);
195 if (arg
== "-display") {
199 _displayreq
= argv
[i
];
200 } else if (arg
== "-rc") {
204 _rcfilepath
= argv
[i
];
205 } else if (arg
== "-menu") {
209 _menufilepath
= argv
[i
];
210 } else if (arg
== "-script") {
214 _scriptfilepath
= argv
[i
];
215 } else if (arg
== "-sync") {
217 } else if (arg
== "-version") {
220 } else if (arg
== "-help") {
234 void Openbox::showVersion()
236 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
237 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
241 void Openbox::showHelp()
243 showVersion(); // show the version string and copyright
245 // print program usage and command line options
246 printf(_("Usage: %s [OPTIONS...]\n\
248 -display <string> use display connection.\n\
249 -rc <string> use alternate resource file.\n\
250 -menu <string> use alternate menu file.\n\
251 -script <string> use alternate startup script file.\n\
252 -version display version and exit.\n\
253 -help display this help text and exit.\n\n"), _argv0
);
255 printf(_("Compile time options:\n\
280 void Openbox::eventLoop()
282 while (!_doshutdown
) {
283 dispatchEvents(); // from OtkEventDispatcher
284 XFlush(otk::OBDisplay::display
); // flush here before we go wait for timers
285 _timermanager
.fire();
290 void Openbox::addClient(Window window
, OBClient
*client
)
292 _clients
[window
] = client
;
296 void Openbox::removeClient(Window window
)
298 _clients
.erase(window
);
302 OBClient
*Openbox::findClient(Window window
)
305 NOTE: we dont use _clients[] to find the value because that will insert
306 a new null into the hash, which really sucks when we want to clean up the
309 ClientMap::iterator it
= _clients
.find(window
);
310 if (it
!= _clients
.end())
313 return (OBClient
*) 0;
317 void Openbox::setFocusedClient(OBClient
*c
)
321 _focused_screen
= _screens
[c
->screen()];
323 assert(_focused_screen
);
324 XSetInputFocus(otk::OBDisplay::display
, _focused_screen
->focuswindow(),
325 RevertToNone
, CurrentTime
);
329 void Openbox::execute(int screen
, const std::string
&bin
)
332 // XXX: whats this for? windows?
333 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", bin
.c_str(), NULL
);
335 if (screen
>= ScreenCount(otk::OBDisplay::display
))
337 const std::string
&dstr
=
338 otk::OBDisplay::screenInfo(screen
)->displayString();
342 int ret
= putenv(const_cast<char *>(dstr
.c_str()));
344 ret
= execl("/bin/sh", "/bin/sh", "-c", bin
.c_str(), NULL
);
This page took 0.048761 seconds and 4 git commands to generate.