]>
Dogcows Code - chaz/openbox/blob - src/openbox.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
11 #include "otk/property.hh"
12 #include "otk/assassin.hh"
13 #include "otk/property.hh"
14 #include "otk/util.hh"
15 #include "otk/rendercolor.hh"
16 #include "otk/renderstyle.hh"
19 #include <X11/cursorfont.h>
23 #endif // HAVE_SIGNAL_H
27 #endif // HAVE_FCNTL_H
29 #ifdef HAVE_SYS_WAIT_H
30 # include <sys/wait.h>
31 #endif // HAVE_SYS_WAIT_H
34 #define _(str) gettext(str)
42 extern void initialize();
43 extern void destroy();
48 Openbox
*openbox
= (Openbox
*) 0;
51 void Openbox::signalHandler(int signal
)
55 printf("Caught SIGUSR1 signal. Restarting.\n");
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::EventDispatcher(),
83 struct sigaction action
;
85 _state
= State_Starting
; // initializing everything
92 _rcfilepath
= otk::expandTilde("~/.openbox/rc3");
93 _scriptfilepath
= otk::expandTilde("~/.openbox/user.py");
98 parseCommandLine(argc
, argv
);
102 XSynchronize(**otk::display
, _sync
);
104 // set up the signal handler
105 action
.sa_handler
= Openbox::signalHandler
;
106 action
.sa_mask
= sigset_t();
107 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
108 sigaction(SIGUSR1
, &action
, (struct sigaction
*) 0);
109 sigaction(SIGPIPE
, &action
, (struct sigaction
*) 0);
110 sigaction(SIGSEGV
, &action
, (struct sigaction
*) 0);
111 sigaction(SIGFPE
, &action
, (struct sigaction
*) 0);
112 sigaction(SIGTERM
, &action
, (struct sigaction
*) 0);
113 sigaction(SIGINT
, &action
, (struct sigaction
*) 0);
114 sigaction(SIGHUP
, &action
, (struct sigaction
*) 0);
115 sigaction(SIGCHLD
, &action
, (struct sigaction
*) 0);
117 // anything that died while we were restarting won't give us a SIGCHLD
118 while (waitpid(-1, NULL
, WNOHANG
) > 0);
120 _actions
= new Actions();
121 _bindings
= new Bindings();
123 setMasterHandler(_actions
); // set as the master event handler
125 // create the mouse cursors we'll use
126 _cursors
.session
= XCreateFontCursor(**otk::display
, XC_left_ptr
);
127 _cursors
.move
= XCreateFontCursor(**otk::display
, XC_fleur
);
128 _cursors
.ll_angle
= XCreateFontCursor(**otk::display
, XC_ll_angle
);
129 _cursors
.lr_angle
= XCreateFontCursor(**otk::display
, XC_lr_angle
);
130 _cursors
.ul_angle
= XCreateFontCursor(**otk::display
, XC_ul_angle
);
131 _cursors
.ur_angle
= XCreateFontCursor(**otk::display
, XC_ur_angle
);
133 // initialize scripting
134 python_init(argv
[0]);
136 // load config values
137 //python_exec(SCRIPTDIR"/config.py"); // load openbox config values
138 // run all of the python scripts
139 //python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks
140 //python_exec(SCRIPTDIR"/focus.py"); // focus helpers
141 // run the user's script or the system defaults if that fails
142 if (!python_exec(_scriptfilepath
.c_str()))
143 python_exec(SCRIPTDIR
"/defaults.py"); // system default bahaviors
145 // initialize all the screens
148 for (int i
= 0, max
= ScreenCount(**otk::display
); i
< max
; ++i
) {
150 // in single mode skip the screens we don't want to manage
151 if (_single
&& i
!= DefaultScreen(**otk::display
)) {
152 _screens
.push_back(0);
155 // try manage the screen
156 screen
= new Screen(i
);
157 if (screen
->managed()) {
158 _screens
.push_back(screen
);
159 if (!_focused_screen
) // set this to the first screen managed
160 _focused_screen
= screen
;
163 _screens
.push_back(0);
167 assert(_focused_screen
);
169 if (_screens
.empty()) {
170 printf(_("No screens were found without a window manager. Exiting.\n"));
174 ScreenList::iterator it
, end
= _screens
.end();
175 for (it
= _screens
.begin(); it
!= end
; ++it
) {
176 (*it
)->manageExisting();
179 // grab any keys set up before the screens existed
180 _bindings
->grabKeys(true);
182 // set up input focus
185 _state
= State_Normal
; // done starting
191 _state
= State_Exiting
; // time to kill everything
193 std::for_each(_screens
.begin(), _screens
.end(), otk::PointerAssassin());
200 XSetInputFocus(**otk::display
, PointerRoot
, RevertToNone
,
202 XSync(**otk::display
, false);
208 void Openbox::parseCommandLine(int argc
, char **argv
)
212 for (int i
= 1; i
< argc
; ++i
) {
213 std::string
arg(argv
[i
]);
219 _rcfilepath
= argv
[i
];
220 } else if (arg
== "-menu") {
224 _menufilepath
= argv
[i
];
225 } else if (arg
== "-script") {
229 _scriptfilepath
= argv
[i
];
230 } else if (arg
== "-sync") {
232 } else if (arg
== "-single") {
234 } else if (arg
== "-version") {
237 } else if (arg
== "-help") {
251 void Openbox::showVersion()
253 printf(_("Openbox - version %s\n"), VERSION
);
254 printf(" (c) 2002 - 2002 Ben Jansens\n\n");
258 void Openbox::showHelp()
260 showVersion(); // show the version string and copyright
262 // print program usage and command line options
263 printf(_("Usage: %s [OPTIONS...]\n\
265 -display <string> use display connection.\n\
266 -single run on a single screen (default is to run every one).\n\
267 -rc <string> use alternate resource file.\n\
268 -menu <string> use alternate menu file.\n\
269 -script <string> use alternate startup script file.\n\
270 -sync run in synchronous mode (for debugging X errors).\n\
271 -version display version and exit.\n\
272 -help display this help text and exit.\n\n"), _argv
[0]);
274 printf(_("Compile time options:\n\
306 void Openbox::eventLoop()
309 dispatchEvents(); // from otk::EventDispatcher
310 XFlush(**otk::display
); // flush here before we go wait for timers
311 // don't wait if we're to shutdown
312 if (_shutdown
) break;
313 otk::Timer::dispatchTimers(!_sync
); // wait if not in sync mode
318 void Openbox::addClient(Window window
, Client
*client
)
320 _clients
[window
] = client
;
324 void Openbox::removeClient(Window window
)
326 _clients
.erase(window
);
330 Client
*Openbox::findClient(Window window
)
333 NOTE: we dont use _clients[] to find the value because that will insert
334 a new null into the hash, which really sucks when we want to clean up the
337 ClientMap::iterator it
= _clients
.find(window
);
338 if (it
!= _clients
.end())
345 void Openbox::setFocusedClient(Client
*c
)
347 // sometimes this is called with the already-focused window, this is
348 // important for the python scripts to work (eg, c = 0 twice). don't just
349 // return if _focused_client == c
351 assert(_focused_screen
);
353 // uninstall the old colormap
355 _focused_client
->installColormap(false);
357 _focused_screen
->installColormap(false);
361 _focused_screen
= _screens
[c
->screen()];
363 // install the client's colormap
364 c
->installColormap(true);
366 XSetInputFocus(**otk::display
, _focused_screen
->focuswindow(),
367 RevertToNone
, CurrentTime
);
369 // install the root window colormap
370 _focused_screen
->installColormap(true);
372 // set the NET_ACTIVE_WINDOW hint for all screens
373 ScreenList::iterator it
, end
= _screens
.end();
374 for (it
= _screens
.begin(); it
!= end
; ++it
) {
375 int num
= (*it
)->number();
376 Window root
= otk::display
->screenInfo(num
)->rootWindow();
377 otk::Property::set(root
, otk::Property::atoms
.net_active_window
,
378 otk::Property::atoms
.window
,
379 (c
&& _focused_screen
== *it
) ? c
->window() : None
);
382 // call the python Focus callbacks
383 EventData
data(_focused_screen
->number(), c
, EventAction::Focus
, 0);
384 _bindings
->fireEvent(&data
);
This page took 0.050602 seconds and 4 git commands to generate.