]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1af59c25fbce1ea575adb84a06050a55a5a32f22
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
7 #include "../version.h"
9 #include "otk/display.hh"
14 #endif // HAVE_STDIO_H
18 #endif // HAVE_STDLIB_H
22 #endif // HAVE_SIGNAL_H
26 #endif // HAVE_FCNTL_H
29 # include <sys/types.h>
31 #endif // HAVE_UNISTD_H
33 #ifdef HAVE_SYS_SELECT_H
34 # include <sys/select.h>
35 #endif // HAVE_SYS_SELECT_H
38 #define _(str) gettext(str)
44 Openbox
*Openbox::instance
= (Openbox
*) 0;
47 int Openbox::xerrorHandler(Display
*d
, XErrorEvent
*e
)
52 XGetErrorText(d
, e
->error_code
, errtxt
, 128);
53 printf("X Error: %s\n", errtxt
);
63 void Openbox::signalHandler(int signal
)
67 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
68 // down and hangs-up on us.
73 printf("Caught signal %d. Exiting.", signal
);
74 // XXX: Make Openbox exit
78 printf("Caught signal %d. Aborting and dumping core.", signal
);
84 Openbox::Openbox(int argc
, char **argv
)
86 struct sigaction action
;
88 _state
= State_Starting
;
90 Openbox::instance
= this;
92 _displayreq
= (char*) 0;
95 parseCommandLine(argc
, argv
);
97 // open the X display (and gets some info about it, and its screens)
98 otk::OBDisplay::initialize(_displayreq
);
99 assert(otk::OBDisplay::display
);
101 // set up the signal handler
102 action
.sa_handler
= Openbox::signalHandler
;
103 action
.sa_mask
= sigset_t();
104 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
105 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
106 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
107 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
108 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
109 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
110 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
114 _state
= State_Normal
; // done starting
120 // close the X display
121 otk::OBDisplay::destroy();
125 void Openbox::parseCommandLine(int argc
, char **argv
)
129 for (int i
= 1; i
< argc
; ++i
) {
130 std::string
arg(argv
[i
]);
132 if (arg
== "-display") {
136 _displayreq
= argv
[i
];
137 } else if (arg
== "-rc") {
141 _rcfilepath
= argv
[i
];
142 } else if (arg
== "-menu") {
146 _menufilepath
= argv
[i
];
147 } else if (arg
== "-version") {
150 } else if (arg
== "-help") {
164 void Openbox::showVersion()
166 printf(_("Openbox - version %s\n"), OPENBOX_VERSION
);
167 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
171 void Openbox::showHelp()
173 showVersion(); // show the version string and copyright
175 // print program usage and command line options
176 printf(_("Usage: %s [OPTIONS...]\n\
178 -display <string> use display connection.\n\
179 -rc <string> use alternate resource file.\n\
180 -menu <string> use alternate menu file.\n\
181 -version display version and exit.\n\
182 -help display this help text and exit.\n\n"), _argv0
);
184 printf(_("Compile time options:\n\
209 void Openbox::eventLoop()
211 while (_state
== State_Normal
) {
212 if (XPending(otk::OBDisplay::display
)) {
214 XNextEvent(otk::OBDisplay::display
, &e
);
217 _timermanager
.fire();
This page took 0.044032 seconds and 4 git commands to generate.