]> Dogcows Code - chaz/openbox/blob - src/openbox.cc
b3dc5b28284dfc8087a5afe33c2a4a7f8d81e78d
[chaz/openbox] / src / openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "../version.h"
8 #include "openbox.hh"
9 #include "otk/display.hh"
10
11 extern "C" {
12 #ifdef HAVE_STDIO_H
13 # include <stdio.h>
14 #endif // HAVE_STDIO_H
15
16 #ifdef HAVE_STDLIB_H
17 # include <stdlib.h>
18 #endif // HAVE_STDLIB_H
19
20 #ifdef HAVE_SIGNAL_H
21 # include <signal.h>
22 #endif // HAVE_SIGNAL_H
23
24 #ifdef HAVE_FCNTL_H
25 # include <fcntl.h>
26 #endif // HAVE_FCNTL_H
27
28 #ifdef HAVE_UNISTD_H
29 # include <sys/types.h>
30 # include <unistd.h>
31 #endif // HAVE_UNISTD_H
32
33 #ifdef HAVE_SYS_SELECT_H
34 # include <sys/select.h>
35 #endif // HAVE_SYS_SELECT_H
36
37 #include "gettext.h"
38 #define _(str) gettext(str)
39 }
40
41 namespace ob {
42
43
44 Openbox *Openbox::instance = (Openbox *) 0;
45
46
47 void Openbox::signalHandler(int signal)
48 {
49 switch (signal) {
50 case SIGHUP:
51 // XXX: Do something with HUP? Really shouldn't, we get this when X shuts
52 // down and hangs-up on us.
53
54 case SIGINT:
55 case SIGTERM:
56 case SIGPIPE:
57 printf("Caught signal %d. Exiting.", signal);
58 instance->shutdown();
59
60 break;
61 case SIGFPE:
62 case SIGSEGV:
63 printf("Caught signal %d. Aborting and dumping core.", signal);
64 abort();
65 }
66 }
67
68
69 Openbox::Openbox(int argc, char **argv)
70 {
71 struct sigaction action;
72
73 _state = State_Starting; // initializing everything
74
75 Openbox::instance = this;
76
77 _displayreq = (char*) 0;
78 _argv0 = argv[0];
79 _doshutdown = false;
80
81 parseCommandLine(argc, argv);
82
83 // open the X display (and gets some info about it, and its screens)
84 otk::OBDisplay::initialize(_displayreq);
85 assert(otk::OBDisplay::display);
86
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);
97
98
99
100 _state = State_Normal; // done starting
101 }
102
103
104 Openbox::~Openbox()
105 {
106 _state = State_Exiting; // time to kill everything
107
108 // close the X display
109 otk::OBDisplay::destroy();
110 }
111
112
113 void Openbox::parseCommandLine(int argc, char **argv)
114 {
115 bool err = false;
116
117 for (int i = 1; i < argc; ++i) {
118 std::string arg(argv[i]);
119
120 if (arg == "-display") {
121 if (++i >= argc)
122 err = true;
123 else
124 _displayreq = argv[i];
125 } else if (arg == "-rc") {
126 if (++i >= argc)
127 err = true;
128 else
129 _rcfilepath = argv[i];
130 } else if (arg == "-menu") {
131 if (++i >= argc)
132 err = true;
133 else
134 _menufilepath = argv[i];
135 } else if (arg == "-version") {
136 showVersion();
137 ::exit(0);
138 } else if (arg == "-help") {
139 showHelp();
140 ::exit(0);
141 } else
142 err = true;
143
144 if (err) {
145 showHelp();
146 exit(1);
147 }
148 }
149 }
150
151
152 void Openbox::showVersion()
153 {
154 printf(_("Openbox - version %s\n"), OPENBOX_VERSION);
155 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
156 }
157
158
159 void Openbox::showHelp()
160 {
161 showVersion(); // show the version string and copyright
162
163 // print program usage and command line options
164 printf(_("Usage: %s [OPTIONS...]\n\
165 Options:\n\
166 -display <string> use display connection.\n\
167 -rc <string> use alternate resource file.\n\
168 -menu <string> use alternate menu file.\n\
169 -version display version and exit.\n\
170 -help display this help text and exit.\n\n"), _argv0);
171
172 printf(_("Compile time options:\n\
173 Debugging: %s\n\
174 Shape: %s\n\
175 Xinerama: %s\n"),
176 #ifdef DEBUG
177 _("yes"),
178 #else // !DEBUG
179 _("no"),
180 #endif // DEBUG
181
182 #ifdef SHAPE
183 _("yes"),
184 #else // !SHAPE
185 _("no"),
186 #endif // SHAPE
187
188 #ifdef XINERAMA
189 _("yes")
190 #else // !XINERAMA
191 _("no")
192 #endif // XINERAMA
193 );
194 }
195
196
197 void Openbox::eventLoop()
198 {
199 while (!_doshutdown) {
200 if (XPending(otk::OBDisplay::display)) {
201 XEvent e;
202 XNextEvent(otk::OBDisplay::display, &e);
203 //process_event(&e);
204 _xeventhandler.handle(e);
205 } else {
206 _timermanager.fire();
207 }
208 }
209 }
210
211
212 }
213
This page took 0.040562 seconds and 4 git commands to generate.