]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
9 #include "otk/property.hh"
10 #include "otk/display.hh"
15 #endif // HAVE_STDIO_H
19 #endif // HAVE_STDLIB_H
23 #endif // HAVE_SIGNAL_H
27 #endif // HAVE_FCNTL_H
30 # include <sys/types.h>
32 #endif // HAVE_UNISTD_H
34 #ifdef HAVE_SYS_SELECT_H
35 # include <sys/select.h>
36 #endif // HAVE_SYS_SELECT_H
39 #define _(str) gettext(str)
44 Openbox
*Openbox::instance
= (Openbox
*) 0;
47 void Openbox::signalHandler(int signal
)
51 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
52 // down and hangs-up on us.
57 printf("Caught signal %d. Exiting.", signal
);
63 printf("Caught signal %d. Aborting and dumping core.", signal
);
69 Openbox::Openbox(int argc
, char **argv
)
71 struct sigaction action
;
73 _state
= State_Starting
; // initializing everything
75 Openbox::instance
= this;
77 _displayreq
= (char*) 0;
81 parseCommandLine(argc
, argv
);
83 // open the X display (and gets some info about it, and its screens)
84 otk::OBDisplay::initialize(_displayreq
);
85 assert(otk::OBDisplay::display
);
87 // set up the signal handler
88 action
.sa_handler
= Openbox::signalHandler
;
89 action
.sa_mask
= sigset_t();
90 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
91 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
92 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
93 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
94 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
95 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
96 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
98 _property
= new otk::OBProperty();
101 _state
= State_Normal
; // done starting
107 _state
= State_Exiting
; // time to kill everything
109 // unmanage all windows
110 ClientMap::iterator it
, end
;
111 for (it
= _clients
.begin(), end
= _clients
.end(); it
!= end
; ++it
) {
112 _xeventhandler
.unmanageWindow(it
->second
);
115 // close the X display
116 otk::OBDisplay::destroy();
120 void Openbox::parseCommandLine(int argc
, char **argv
)
124 for (int i
= 1; i
< argc
; ++i
) {
125 std::string
arg(argv
[i
]);
127 if (arg
== "-display") {
131 _displayreq
= argv
[i
];
132 } else if (arg
== "-rc") {
136 _rcfilepath
= argv
[i
];
137 } else if (arg
== "-menu") {
141 _menufilepath
= argv
[i
];
142 } else if (arg
== "-version") {
145 } else if (arg
== "-help") {
159 void Openbox::showVersion()
161 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
162 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
166 void Openbox::showHelp()
168 showVersion(); // show the version string and copyright
170 // print program usage and command line options
171 printf(_("Usage: %s [OPTIONS...]\n\
173 -display <string> use display connection.\n\
174 -rc <string> use alternate resource file.\n\
175 -menu <string> use alternate menu file.\n\
176 -version display version and exit.\n\
177 -help display this help text and exit.\n\n"), _argv0
);
179 printf(_("Compile time options:\n\
204 void Openbox::eventLoop()
206 while (!_doshutdown
) {
207 if (XPending(otk::OBDisplay::display
)) {
209 XNextEvent(otk::OBDisplay::display
, &e
);
211 _xeventhandler
.handle(e
);
213 _timermanager
.fire();
219 void Openbox::addClient(Window window
, OBClient
*client
)
221 _clients
[window
] = client
;
225 void Openbox::removeClient(Window window
)
227 _clients
[window
] = (OBClient
*) 0;
231 OBClient
*Openbox::findClient(Window window
)
233 return _clients
[window
];
This page took 0.046299 seconds and 4 git commands to generate.