]> Dogcows Code - chaz/openbox/blob - src/openbox.cc
670c41c05dfd66ba95959c5d3d2e123b0d9c6150
[chaz/openbox] / src / openbox.cc
1 // openbox.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef HAVE_CONFIG_H
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include <X11/Xlib.h>
34 #include <X11/Xutil.h>
35 #include <X11/Xresource.h>
36 #include <X11/Xatom.h>
37 #include <X11/keysym.h>
38
39 #ifdef SHAPE
40 #include <X11/extensions/shape.h>
41 #endif // SHAPE
42
43 #include "i18n.h"
44 #include "openbox.h"
45 #include "Basemenu.h"
46 #include "Clientmenu.h"
47 #include "Rootmenu.h"
48 #include "Screen.h"
49
50 #ifdef SLIT
51 #include "Slit.h"
52 #endif // SLIT
53
54 #include "Toolbar.h"
55 #include "Window.h"
56 #include "Workspace.h"
57 #include "Workspacemenu.h"
58
59 #include <string>
60 #include <algorithm>
61
62 #ifdef HAVE_STDIO_H
63 # include <stdio.h>
64 #endif // HAVE_STDIO_H
65
66 #ifdef STDC_HEADERS
67 # include <stdlib.h>
68 # include <string.h>
69 #endif // STDC_HEADERS
70
71 #ifdef HAVE_UNISTD_H
72 # include <sys/types.h>
73 # include <unistd.h>
74 #endif // HAVE_UNISTD_H
75
76 #ifdef HAVE_SYS_PARAM_H
77 # include <sys/param.h>
78 #endif // HAVE_SYS_PARAM_H
79
80 #ifndef MAXPATHLEN
81 #define MAXPATHLEN 255
82 #endif // MAXPATHLEN
83
84 #ifdef HAVE_SYS_SELECT_H
85 # include <sys/select.h>
86 #endif // HAVE_SYS_SELECT_H
87
88 #ifdef HAVE_SIGNAL_H
89 # include <signal.h>
90 #endif // HAVE_SIGNAL_H
91
92 #ifdef HAVE_SYS_SIGNAL_H
93 # include <sys/signal.h>
94 #endif // HAVE_SYS_SIGNAL_H
95
96 #ifdef HAVE_SYS_STAT_H
97 # include <sys/types.h>
98 # include <sys/stat.h>
99 #endif // HAVE_SYS_STAT_H
100
101 #ifdef TIME_WITH_SYS_TIME
102 # include <sys/time.h>
103 # include <time.h>
104 #else // !TIME_WITH_SYS_TIME
105 # ifdef HAVE_SYS_TIME_H
106 # include <sys/time.h>
107 # else // !HAVE_SYS_TIME_H
108 # include <time.h>
109 # endif // HAVE_SYS_TIME_H
110 #endif // TIME_WITH_SYS_TIME
111
112 #ifdef HAVE_LIBGEN_H
113 # include <libgen.h>
114 #endif // HAVE_LIBGEN_H
115
116 #ifndef HAVE_BASENAME
117 static inline char *basename (char *s) {
118 char *save = s;
119
120 while (*s) if (*s++ == '/') save = s;
121
122 return save;
123 }
124 #endif // HAVE_BASENAME
125
126
127 // X event scanner for enter/leave notifies - adapted from twm
128 typedef struct scanargs {
129 Window w;
130 Bool leave, inferior, enter;
131 } scanargs;
132
133 static Bool queueScanner(Display *, XEvent *e, char *args) {
134 if ((e->type == LeaveNotify) &&
135 (e->xcrossing.window == ((scanargs *) args)->w) &&
136 (e->xcrossing.mode == NotifyNormal)) {
137 ((scanargs *) args)->leave = True;
138 ((scanargs *) args)->inferior = (e->xcrossing.detail == NotifyInferior);
139 } else if ((e->type == EnterNotify) &&
140 (e->xcrossing.mode == NotifyUngrab)) {
141 ((scanargs *) args)->enter = True;
142 }
143
144 return False;
145 }
146
147 Openbox *openbox;
148
149
150 Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
151 : BaseDisplay(m_argv[0], dpy_name) {
152 grab();
153
154 if (! XSupportsLocale())
155 fprintf(stderr, "X server does not support locale\n");
156
157 if (XSetLocaleModifiers("") == NULL)
158 fprintf(stderr, "cannot set locale modifiers\n");
159
160 ::openbox = this;
161 argc = m_argc;
162 argv = m_argv;
163 if (rc == NULL) {
164 char *homedir = getenv("HOME");
165
166 rc_file = new char[strlen(homedir) + strlen("/.openbox/rc") + 1];
167 sprintf(rc_file, "%s/.openbox", homedir);
168
169 // try to make sure the ~/.openbox directory exists
170 mkdir(rc_file, S_IREAD | S_IWRITE | S_IEXEC | S_IRGRP | S_IWGRP | S_IXGRP |
171 S_IROTH | S_IWOTH | S_IXOTH);
172
173 sprintf(rc_file, "%s/.openbox/rc", homedir);
174 } else {
175 rc_file = bstrdup(rc);
176 }
177 symlink_rc(rc_file);
178 config.setFile(rc_file);
179
180 no_focus = False;
181
182 resource.menu_file = resource.style_file = (char *) 0;
183 resource.titlebar_layout = (char *) NULL;
184 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0;
185
186 focused_window = masked_window = (OpenboxWindow *) 0;
187 masked = None;
188
189 windowSearchList = new LinkedList<WindowSearch>;
190 menuSearchList = new LinkedList<MenuSearch>;
191
192 #ifdef SLIT
193 slitSearchList = new LinkedList<SlitSearch>;
194 #endif // SLIT
195
196 toolbarSearchList = new LinkedList<ToolbarSearch>;
197 groupSearchList = new LinkedList<WindowSearch>;
198
199 menuTimestamps = new LinkedList<MenuTimestamp>;
200
201 load_rc();
202
203 #ifdef HAVE_GETPID
204 openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False);
205 #endif // HAVE_GETPID
206
207 screenList = new LinkedList<BScreen>;
208 for (int i = 0; i < getNumberOfScreens(); i++) {
209 BScreen *screen = new BScreen(*this, i);
210
211 if (! screen->isScreenManaged()) {
212 delete screen;
213 continue;
214 }
215
216 screenList->insert(screen);
217 }
218
219 if (! screenList->count()) {
220 fprintf(stderr,
221 i18n->getMessage(openboxSet, openboxNoManagableScreens,
222 "Openbox::Openbox: no managable screens found, aborting.\n"));
223 ::exit(3);
224 }
225
226 XSynchronize(getXDisplay(), False);
227 XSync(getXDisplay(), False);
228
229 reconfigure_wait = reread_menu_wait = False;
230
231 timer = new BTimer(*this, *this);
232 timer->setTimeout(0);
233 timer->fireOnce(True);
234
235 ungrab();
236 }
237
238
239 Openbox::~Openbox(void) {
240 while (screenList->count())
241 delete screenList->remove(0);
242
243 while (menuTimestamps->count()) {
244 MenuTimestamp *ts = menuTimestamps->remove(0);
245
246 if (ts->filename)
247 delete [] ts->filename;
248
249 delete ts;
250 }
251
252 if (resource.menu_file)
253 delete [] resource.menu_file;
254
255 if (resource.style_file)
256 delete [] resource.style_file;
257
258 delete timer;
259
260 delete screenList;
261 delete menuTimestamps;
262
263 delete windowSearchList;
264 delete menuSearchList;
265 delete toolbarSearchList;
266 delete groupSearchList;
267
268 delete [] rc_file;
269
270 #ifdef SLIT
271 delete slitSearchList;
272 #endif // SLIT
273 }
274
275
276 void Openbox::process_event(XEvent *e) {
277 if ((masked == e->xany.window) && masked_window &&
278 (e->type == MotionNotify)) {
279 last_time = e->xmotion.time;
280 masked_window->motionNotifyEvent(&e->xmotion);
281
282 return;
283 }
284
285 switch (e->type) {
286 case ButtonPress: {
287 // strip the lock key modifiers
288 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
289
290 last_time = e->xbutton.time;
291
292 OpenboxWindow *win = (OpenboxWindow *) 0;
293 Basemenu *menu = (Basemenu *) 0;
294
295 #ifdef SLIT
296 Slit *slit = (Slit *) 0;
297 #endif // SLIT
298
299 Toolbar *tbar = (Toolbar *) 0;
300
301 if ((win = searchWindow(e->xbutton.window))) {
302 win->buttonPressEvent(&e->xbutton);
303
304 if (e->xbutton.button == 1)
305 win->installColormap(True);
306 } else if ((menu = searchMenu(e->xbutton.window))) {
307 menu->buttonPressEvent(&e->xbutton);
308
309 #ifdef SLIT
310 } else if ((slit = searchSlit(e->xbutton.window))) {
311 slit->buttonPressEvent(&e->xbutton);
312 #endif // SLIT
313
314 } else if ((tbar = searchToolbar(e->xbutton.window))) {
315 tbar->buttonPressEvent(&e->xbutton);
316 } else {
317 LinkedListIterator<BScreen> it(screenList);
318 BScreen *screen = it.current();
319 for (; screen; it++, screen = it.current()) {
320 if (e->xbutton.window == screen->getRootWindow()) {
321 if (e->xbutton.button == 1) {
322 if (! screen->isRootColormapInstalled())
323 screen->getImageControl()->installRootColormap();
324
325 if (screen->getWorkspacemenu()->isVisible())
326 screen->getWorkspacemenu()->hide();
327
328 if (screen->getRootmenu()->isVisible())
329 screen->getRootmenu()->hide();
330 } else if (e->xbutton.button == 2) {
331 int mx = e->xbutton.x_root -
332 (screen->getWorkspacemenu()->getWidth() / 2);
333 int my = e->xbutton.y_root -
334 (screen->getWorkspacemenu()->getTitleHeight() / 2);
335
336 if (mx < 0) mx = 0;
337 if (my < 0) my = 0;
338
339 if (mx + screen->getWorkspacemenu()->getWidth() >
340 screen->getWidth())
341 mx = screen->getWidth() -
342 screen->getWorkspacemenu()->getWidth() -
343 screen->getBorderWidth();
344
345 if (my + screen->getWorkspacemenu()->getHeight() >
346 screen->getHeight())
347 my = screen->getHeight() -
348 screen->getWorkspacemenu()->getHeight() -
349 screen->getBorderWidth();
350
351 screen->getWorkspacemenu()->move(mx, my);
352
353 if (! screen->getWorkspacemenu()->isVisible()) {
354 screen->getWorkspacemenu()->removeParent();
355 screen->getWorkspacemenu()->show();
356 }
357 } else if (e->xbutton.button == 3) {
358 int mx = e->xbutton.x_root -
359 (screen->getRootmenu()->getWidth() / 2);
360 int my = e->xbutton.y_root -
361 (screen->getRootmenu()->getTitleHeight() / 2);
362
363 if (mx < 0) mx = 0;
364 if (my < 0) my = 0;
365
366 if (mx + screen->getRootmenu()->getWidth() > screen->getWidth())
367 mx = screen->getWidth() -
368 screen->getRootmenu()->getWidth() -
369 screen->getBorderWidth();
370
371 if (my + screen->getRootmenu()->getHeight() > screen->getHeight())
372 my = screen->getHeight() -
373 screen->getRootmenu()->getHeight() -
374 screen->getBorderWidth();
375
376 screen->getRootmenu()->move(mx, my);
377
378 if (! screen->getRootmenu()->isVisible()) {
379 checkMenu();
380 screen->getRootmenu()->show();
381 }
382 } else if (e->xbutton.button == 4) {
383 if ((screen->getCurrentWorkspaceID()-1)<0)
384 screen->changeWorkspaceID(screen->getWorkspaceCount()-1);
385 else
386 screen->changeWorkspaceID(screen->getCurrentWorkspaceID()-1);
387 } else if (e->xbutton.button == 5) {
388 if ((screen->getCurrentWorkspaceID()+1)>screen->getWorkspaceCount()-1)
389 screen->changeWorkspaceID(0);
390 else
391 screen->changeWorkspaceID(screen->getCurrentWorkspaceID()+1);
392 }
393 }
394 }
395 }
396
397 break;
398 }
399
400 case ButtonRelease: {
401 // strip the lock key modifiers
402 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
403
404 last_time = e->xbutton.time;
405
406 OpenboxWindow *win = (OpenboxWindow *) 0;
407 Basemenu *menu = (Basemenu *) 0;
408 Toolbar *tbar = (Toolbar *) 0;
409
410 if ((win = searchWindow(e->xbutton.window)))
411 win->buttonReleaseEvent(&e->xbutton);
412 else if ((menu = searchMenu(e->xbutton.window)))
413 menu->buttonReleaseEvent(&e->xbutton);
414 else if ((tbar = searchToolbar(e->xbutton.window)))
415 tbar->buttonReleaseEvent(&e->xbutton);
416
417 break;
418 }
419
420 case ConfigureRequest: {
421 OpenboxWindow *win = (OpenboxWindow *) 0;
422
423 #ifdef SLIT
424 Slit *slit = (Slit *) 0;
425 #endif // SLIT
426
427 if ((win = searchWindow(e->xconfigurerequest.window))) {
428 win->configureRequestEvent(&e->xconfigurerequest);
429
430 #ifdef SLIT
431 } else if ((slit = searchSlit(e->xconfigurerequest.window))) {
432 slit->configureRequestEvent(&e->xconfigurerequest);
433 #endif // SLIT
434
435 } else {
436 grab();
437
438 if (validateWindow(e->xconfigurerequest.window)) {
439 XWindowChanges xwc;
440
441 xwc.x = e->xconfigurerequest.x;
442 xwc.y = e->xconfigurerequest.y;
443 xwc.width = e->xconfigurerequest.width;
444 xwc.height = e->xconfigurerequest.height;
445 xwc.border_width = e->xconfigurerequest.border_width;
446 xwc.sibling = e->xconfigurerequest.above;
447 xwc.stack_mode = e->xconfigurerequest.detail;
448
449 XConfigureWindow(getXDisplay(), e->xconfigurerequest.window,
450 e->xconfigurerequest.value_mask, &xwc);
451 }
452
453 ungrab();
454 }
455
456 break;
457 }
458
459 case MapRequest: {
460 #ifdef DEBUG
461 fprintf(stderr,
462 i18n->getMessage(openboxSet, openboxMapRequest,
463 "Openbox::process_event(): MapRequest for 0x%lx\n"),
464 e->xmaprequest.window);
465 #endif // DEBUG
466
467 OpenboxWindow *win = searchWindow(e->xmaprequest.window);
468
469 if (! win)
470 win = new OpenboxWindow(this, e->xmaprequest.window);
471
472 if ((win = searchWindow(e->xmaprequest.window)))
473 win->mapRequestEvent(&e->xmaprequest);
474
475 break;
476 }
477
478 case MapNotify: {
479 OpenboxWindow *win = searchWindow(e->xmap.window);
480
481 if (win)
482 win->mapNotifyEvent(&e->xmap);
483
484 break;
485 }
486
487 case UnmapNotify: {
488 OpenboxWindow *win = (OpenboxWindow *) 0;
489
490 #ifdef SLIT
491 Slit *slit = (Slit *) 0;
492 #endif // SLIT
493
494 if ((win = searchWindow(e->xunmap.window))) {
495 win->unmapNotifyEvent(&e->xunmap);
496 if (focused_window == win)
497 focused_window = (OpenboxWindow *) 0;
498 #ifdef SLIT
499 } else if ((slit = searchSlit(e->xunmap.window))) {
500 slit->removeClient(e->xunmap.window);
501 #endif // SLIT
502
503 }
504
505 break;
506 }
507
508 case DestroyNotify: {
509 OpenboxWindow *win = (OpenboxWindow *) 0;
510
511 #ifdef SLIT
512 Slit *slit = (Slit *) 0;
513 #endif // SLIT
514
515 if ((win = searchWindow(e->xdestroywindow.window))) {
516 win->destroyNotifyEvent(&e->xdestroywindow);
517 if (focused_window == win)
518 focused_window = (OpenboxWindow *) 0;
519 #ifdef SLIT
520 } else if ((slit = searchSlit(e->xdestroywindow.window))) {
521 slit->removeClient(e->xdestroywindow.window, False);
522 #endif // SLIT
523 }
524
525 break;
526 }
527
528 case MotionNotify: {
529 // strip the lock key modifiers
530 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
531
532 last_time = e->xmotion.time;
533
534 OpenboxWindow *win = (OpenboxWindow *) 0;
535 Basemenu *menu = (Basemenu *) 0;
536
537 if ((win = searchWindow(e->xmotion.window)))
538 win->motionNotifyEvent(&e->xmotion);
539 else if ((menu = searchMenu(e->xmotion.window)))
540 menu->motionNotifyEvent(&e->xmotion);
541
542 break;
543 }
544
545 case PropertyNotify: {
546 last_time = e->xproperty.time;
547
548 if (e->xproperty.state != PropertyDelete) {
549 OpenboxWindow *win = searchWindow(e->xproperty.window);
550
551 if (win)
552 win->propertyNotifyEvent(e->xproperty.atom);
553 }
554
555 break;
556 }
557
558 case EnterNotify: {
559 last_time = e->xcrossing.time;
560
561 BScreen *screen = (BScreen *) 0;
562 OpenboxWindow *win = (OpenboxWindow *) 0;
563 Basemenu *menu = (Basemenu *) 0;
564 Toolbar *tbar = (Toolbar *) 0;
565
566 #ifdef SLIT
567 Slit *slit = (Slit *) 0;
568 #endif // SLIT
569
570 if (e->xcrossing.mode == NotifyGrab) break;
571
572 XEvent dummy;
573 scanargs sa;
574 sa.w = e->xcrossing.window;
575 sa.enter = sa.leave = False;
576 XCheckIfEvent(getXDisplay(), &dummy, queueScanner, (char *) &sa);
577
578 if ((e->xcrossing.window == e->xcrossing.root) &&
579 (screen = searchScreen(e->xcrossing.window))) {
580 screen->getImageControl()->installRootColormap();
581 } else if ((win = searchWindow(e->xcrossing.window))) {
582 if (win->getScreen()->isSloppyFocus() &&
583 (! win->isFocused()) && (! no_focus)) {
584 grab();
585
586 if (((! sa.leave) || sa.inferior) && win->isVisible() &&
587 win->setInputFocus())
588 win->installColormap(True);
589
590 ungrab();
591 }
592 } else if ((menu = searchMenu(e->xcrossing.window))) {
593 menu->enterNotifyEvent(&e->xcrossing);
594 } else if ((tbar = searchToolbar(e->xcrossing.window))) {
595 tbar->enterNotifyEvent(&e->xcrossing);
596 #ifdef SLIT
597 } else if ((slit = searchSlit(e->xcrossing.window))) {
598 slit->enterNotifyEvent(&e->xcrossing);
599 #endif // SLIT
600 }
601 break;
602 }
603
604 case LeaveNotify: {
605 last_time = e->xcrossing.time;
606
607 OpenboxWindow *win = (OpenboxWindow *) 0;
608 Basemenu *menu = (Basemenu *) 0;
609 Toolbar *tbar = (Toolbar *) 0;
610
611 #ifdef SLIT
612 Slit *slit = (Slit *) 0;
613 #endif // SLIT
614
615 if ((menu = searchMenu(e->xcrossing.window)))
616 menu->leaveNotifyEvent(&e->xcrossing);
617 else if ((win = searchWindow(e->xcrossing.window)))
618 win->installColormap(False);
619 else if ((tbar = searchToolbar(e->xcrossing.window)))
620 tbar->leaveNotifyEvent(&e->xcrossing);
621 #ifdef SLIT
622 else if ((slit = searchSlit(e->xcrossing.window)))
623 slit->leaveNotifyEvent(&e->xcrossing);
624 #endif // SLIT
625
626 break;
627 }
628
629 case Expose: {
630 OpenboxWindow *win = (OpenboxWindow *) 0;
631 Basemenu *menu = (Basemenu *) 0;
632 Toolbar *tbar = (Toolbar *) 0;
633
634 if ((win = searchWindow(e->xexpose.window)))
635 win->exposeEvent(&e->xexpose);
636 else if ((menu = searchMenu(e->xexpose.window)))
637 menu->exposeEvent(&e->xexpose);
638 else if ((tbar = searchToolbar(e->xexpose.window)))
639 tbar->exposeEvent(&e->xexpose);
640
641 break;
642 }
643
644 case KeyPress: {
645 Toolbar *tbar = searchToolbar(e->xkey.window);
646
647 if (tbar && tbar->isEditing())
648 tbar->keyPressEvent(&e->xkey);
649
650 break;
651 }
652
653 case ColormapNotify: {
654 BScreen *screen = searchScreen(e->xcolormap.window);
655
656 if (screen)
657 screen->setRootColormapInstalled((e->xcolormap.state ==
658 ColormapInstalled) ? True : False);
659
660 break;
661 }
662
663 case FocusIn: {
664 if (e->xfocus.mode == NotifyUngrab || e->xfocus.detail == NotifyPointer)
665 break;
666
667 OpenboxWindow *win = searchWindow(e->xfocus.window);
668 if (win && ! win->isFocused())
669 setFocusedWindow(win);
670
671 break;
672 }
673
674 case FocusOut:
675 break;
676
677 case ClientMessage: {
678 if (e->xclient.format == 32) {
679 if (e->xclient.message_type == getWMChangeStateAtom()) {
680 OpenboxWindow *win = searchWindow(e->xclient.window);
681 if (! win || ! win->validateClient()) return;
682
683 if (e->xclient.data.l[0] == IconicState)
684 win->iconify();
685 if (e->xclient.data.l[0] == NormalState)
686 win->deiconify();
687 } else if (e->xclient.message_type == getOpenboxChangeWorkspaceAtom()) {
688 BScreen *screen = searchScreen(e->xclient.window);
689
690 if (screen && e->xclient.data.l[0] >= 0 &&
691 e->xclient.data.l[0] < screen->getWorkspaceCount())
692 screen->changeWorkspaceID(e->xclient.data.l[0]);
693 } else if (e->xclient.message_type == getOpenboxChangeWindowFocusAtom()) {
694 OpenboxWindow *win = searchWindow(e->xclient.window);
695
696 if (win && win->isVisible() && win->setInputFocus())
697 win->installColormap(True);
698 } else if (e->xclient.message_type == getOpenboxCycleWindowFocusAtom()) {
699 BScreen *screen = searchScreen(e->xclient.window);
700
701 if (screen) {
702 if (! e->xclient.data.l[0])
703 screen->prevFocus();
704 else
705 screen->nextFocus();
706 }
707 } else if (e->xclient.message_type == getOpenboxChangeAttributesAtom()) {
708 OpenboxWindow *win = searchWindow(e->xclient.window);
709
710 if (win && win->validateClient()) {
711 OpenboxHints net;
712 net.flags = e->xclient.data.l[0];
713 net.attrib = e->xclient.data.l[1];
714 net.workspace = e->xclient.data.l[2];
715 net.stack = e->xclient.data.l[3];
716 net.decoration = e->xclient.data.l[4];
717
718 win->changeOpenboxHints(&net);
719 }
720 }
721 }
722
723 break;
724 }
725
726
727 default: {
728 #ifdef SHAPE
729 if (e->type == getShapeEventBase()) {
730 XShapeEvent *shape_event = (XShapeEvent *) e;
731 OpenboxWindow *win = (OpenboxWindow *) 0;
732
733 if ((win = searchWindow(e->xany.window)) ||
734 (shape_event->kind != ShapeBounding))
735 win->shapeEvent(shape_event);
736 }
737 #endif // SHAPE
738
739 }
740 } // switch
741 }
742
743
744 Bool Openbox::handleSignal(int sig) {
745 switch (sig) {
746 case SIGHUP:
747 reconfigure();
748 break;
749
750 case SIGUSR1:
751 reload_rc();
752 break;
753
754 case SIGUSR2:
755 rereadMenu();
756 break;
757
758 case SIGPIPE:
759 case SIGSEGV:
760 case SIGFPE:
761 case SIGINT:
762 case SIGTERM:
763 shutdown();
764
765 default:
766 return False;
767 }
768
769 return True;
770 }
771
772
773 BScreen *Openbox::searchScreen(Window window) {
774 LinkedListIterator<BScreen> it(screenList);
775
776 for (BScreen *curr = it.current(); curr; it++, curr = it.current()) {
777 if (curr->getRootWindow() == window) {
778 return curr;
779 }
780 }
781
782 return (BScreen *) 0;
783 }
784
785
786 OpenboxWindow *Openbox::searchWindow(Window window) {
787 LinkedListIterator<WindowSearch> it(windowSearchList);
788
789 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
790 if (tmp->getWindow() == window) {
791 return tmp->getData();
792 }
793 }
794
795 return (OpenboxWindow *) 0;
796 }
797
798
799 OpenboxWindow *Openbox::searchGroup(Window window, OpenboxWindow *win) {
800 OpenboxWindow *w = (OpenboxWindow *) 0;
801 LinkedListIterator<WindowSearch> it(groupSearchList);
802
803 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
804 if (tmp->getWindow() == window) {
805 w = tmp->getData();
806 if (w->getClientWindow() != win->getClientWindow())
807 return win;
808 }
809 }
810
811 return (OpenboxWindow *) 0;
812 }
813
814
815 Basemenu *Openbox::searchMenu(Window window) {
816 LinkedListIterator<MenuSearch> it(menuSearchList);
817
818 for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
819 if (tmp->getWindow() == window)
820 return tmp->getData();
821 }
822
823 return (Basemenu *) 0;
824 }
825
826
827 Toolbar *Openbox::searchToolbar(Window window) {
828 LinkedListIterator<ToolbarSearch> it(toolbarSearchList);
829
830 for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
831 if (tmp->getWindow() == window)
832 return tmp->getData();
833 }
834
835 return (Toolbar *) 0;
836 }
837
838
839 #ifdef SLIT
840 Slit *Openbox::searchSlit(Window window) {
841 LinkedListIterator<SlitSearch> it(slitSearchList);
842
843 for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
844 if (tmp->getWindow() == window)
845 return tmp->getData();
846 }
847
848 return (Slit *) 0;
849 }
850 #endif // SLIT
851
852
853 void Openbox::saveWindowSearch(Window window, OpenboxWindow *data) {
854 windowSearchList->insert(new WindowSearch(window, data));
855 }
856
857
858 void Openbox::saveGroupSearch(Window window, OpenboxWindow *data) {
859 groupSearchList->insert(new WindowSearch(window, data));
860 }
861
862
863 void Openbox::saveMenuSearch(Window window, Basemenu *data) {
864 menuSearchList->insert(new MenuSearch(window, data));
865 }
866
867
868 void Openbox::saveToolbarSearch(Window window, Toolbar *data) {
869 toolbarSearchList->insert(new ToolbarSearch(window, data));
870 }
871
872
873 #ifdef SLIT
874 void Openbox::saveSlitSearch(Window window, Slit *data) {
875 slitSearchList->insert(new SlitSearch(window, data));
876 }
877 #endif // SLIT
878
879
880 void Openbox::removeWindowSearch(Window window) {
881 LinkedListIterator<WindowSearch> it(windowSearchList);
882 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
883 if (tmp->getWindow() == window) {
884 windowSearchList->remove(tmp);
885 delete tmp;
886 break;
887 }
888 }
889 }
890
891
892 void Openbox::removeGroupSearch(Window window) {
893 LinkedListIterator<WindowSearch> it(groupSearchList);
894 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
895 if (tmp->getWindow() == window) {
896 groupSearchList->remove(tmp);
897 delete tmp;
898 break;
899 }
900 }
901 }
902
903
904 void Openbox::removeMenuSearch(Window window) {
905 LinkedListIterator<MenuSearch> it(menuSearchList);
906 for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
907 if (tmp->getWindow() == window) {
908 menuSearchList->remove(tmp);
909 delete tmp;
910 break;
911 }
912 }
913 }
914
915
916 void Openbox::removeToolbarSearch(Window window) {
917 LinkedListIterator<ToolbarSearch> it(toolbarSearchList);
918 for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
919 if (tmp->getWindow() == window) {
920 toolbarSearchList->remove(tmp);
921 delete tmp;
922 break;
923 }
924 }
925 }
926
927
928 #ifdef SLIT
929 void Openbox::removeSlitSearch(Window window) {
930 LinkedListIterator<SlitSearch> it(slitSearchList);
931 for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
932 if (tmp->getWindow() == window) {
933 slitSearchList->remove(tmp);
934 delete tmp;
935 break;
936 }
937 }
938 }
939 #endif // SLIT
940
941
942 void Openbox::restart(const char *prog) {
943 shutdown();
944
945 if (prog) {
946 execlp(prog, prog, NULL);
947 perror(prog);
948 }
949
950 // fall back in case the above execlp doesn't work
951 execvp(argv[0], argv);
952 execvp(basename(argv[0]), argv);
953 }
954
955
956 void Openbox::shutdown(void) {
957 BaseDisplay::shutdown();
958
959 XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime);
960
961 LinkedListIterator<BScreen> it(screenList);
962 for (BScreen *s = it.current(); s; it++, s = it.current())
963 s->shutdown();
964
965 XSync(getXDisplay(), False);
966
967 save_rc();
968 }
969
970
971 void Openbox::save_rc(void) {
972 config.setAutoSave(false);
973
974 config.setValue("session.menuFile", getMenuFilename());
975 config.setValue("session.colorsPerChannel",
976 resource.colors_per_channel);
977 config.setValue("session.doubleClickInterval",
978 (long)resource.double_click_interval);
979 config.setValue("session.autoRaiseDelay",
980 ((resource.auto_raise_delay.tv_sec * 1000) +
981 (resource.auto_raise_delay.tv_usec / 1000)));
982 config.setValue("session.cacheLife", (long)resource.cache_life / 60000);
983 config.setValue("session.cacheMax", (long)resource.cache_max);
984
985 LinkedListIterator<BScreen> it(screenList);
986 for (BScreen *screen = it.current(); screen; it++, screen = it.current()) {
987 // ScreenList::iterator it = screenList.begin();
988 // for (; it != screenList.end(); ++it) {
989 // BScreen *screen = *it;
990 char rc_string[1024];
991 const int screen_number = screen->getScreenNumber();
992
993 char *placement = (char *) 0;
994
995 switch (screen->getSlitPlacement()) {
996 case Slit::TopLeft: placement = "TopLeft"; break;
997 case Slit::CenterLeft: placement = "CenterLeft"; break;
998 case Slit::BottomLeft: placement = "BottomLeft"; break;
999 case Slit::TopCenter: placement = "TopCenter"; break;
1000 case Slit::BottomCenter: placement = "BottomCenter"; break;
1001 case Slit::TopRight: placement = "TopRight"; break;
1002 case Slit::BottomRight: placement = "BottomRight"; break;
1003 case Slit::CenterRight: default: placement = "CenterRight"; break;
1004 }
1005 sprintf(rc_string, "session.screen%d.slit.placement", screen_number);
1006 config.setValue(rc_string, placement);
1007
1008 sprintf(rc_string, "session.screen%d.slit.direction", screen_number);
1009 config.setValue(rc_string,
1010 screen->getSlitDirection() == Slit::Horizontal ?
1011 "Horizontal" : "Vertical");
1012
1013 sprintf(rc_string, "session.screen%d.slit.onTop", screen_number);
1014 config.setValue(rc_string, screen->getSlit()->isOnTop() ? "True" : "False");
1015
1016 sprintf(rc_string, "session.screen%d.slit.autoHide", screen_number);
1017 config.setValue(rc_string, screen->getSlit()->doAutoHide() ?
1018 "True" : "False");
1019
1020 config.setValue("session.opaqueMove",
1021 (screen->doOpaqueMove()) ? "True" : "False");
1022 config.setValue("session.imageDither",
1023 (screen->getImageControl()->doDither()) ? "True" : "False");
1024
1025 sprintf(rc_string, "session.screen%d.fullMaximization", screen_number);
1026 config.setValue(rc_string, screen->doFullMax() ? "True" : "False");
1027
1028 sprintf(rc_string, "session.screen%d.focusNewWindows", screen_number);
1029 config.setValue(rc_string, screen->doFocusNew() ? "True" : "False");
1030
1031 sprintf(rc_string, "session.screen%d.focusLastWindow", screen_number);
1032 config.setValue(rc_string, screen->doFocusLast() ? "True" : "False");
1033
1034 sprintf(rc_string, "session.screen%d.rowPlacementDirection", screen_number);
1035 config.setValue(rc_string,
1036 screen->getRowPlacementDirection() == BScreen::LeftRight ?
1037 "LeftToRight" : "RightToLeft");
1038
1039 sprintf(rc_string, "session.screen%d.colPlacementDirection", screen_number);
1040 config.setValue(rc_string,
1041 screen->getColPlacementDirection() == BScreen::TopBottom ?
1042 "TopToBottom" : "BottomToTop");
1043
1044 switch (screen->getPlacementPolicy()) {
1045 case BScreen::CascadePlacement: placement = "CascadePlacement"; break;
1046 case BScreen::BestFitPlacement: placement = "BestFitPlacement"; break;
1047 case BScreen::ColSmartPlacement: placement = "ColSmartPlacement"; break;
1048 default:
1049 case BScreen::RowSmartPlacement: placement = "RowSmartPlacement"; break;
1050 }
1051 sprintf(rc_string, "session.screen%d.windowPlacement", screen_number);
1052 config.setValue(rc_string, placement);
1053
1054 sprintf(rc_string, "session.screen%d.focusModel", screen_number);
1055 config.setValue(rc_string,
1056 (screen->isSloppyFocus() ?
1057 (screen->doAutoRaise() ? "AutoRaiseSloppyFocus" :
1058 "SloppyFocus") : "ClickToFocus"));
1059
1060 sprintf(rc_string, "session.screen%d.workspaces", screen_number);
1061 config.setValue(rc_string, screen->getWorkspaceCount());
1062
1063 sprintf(rc_string, "session.screen%d.toolbar.onTop", screen_number);
1064 config.setValue(rc_string, screen->getToolbar()->isOnTop() ?
1065 "True" : "False");
1066
1067 sprintf(rc_string, "session.screen%d.toolbar.autoHide", screen_number);
1068 config.setValue(rc_string, screen->getToolbar()->doAutoHide() ?
1069 "True" : "False");
1070
1071 switch (screen->getToolbarPlacement()) {
1072 case Toolbar::TopLeft: placement = "TopLeft"; break;
1073 case Toolbar::BottomLeft: placement = "BottomLeft"; break;
1074 case Toolbar::TopCenter: placement = "TopCenter"; break;
1075 case Toolbar::TopRight: placement = "TopRight"; break;
1076 case Toolbar::BottomRight: placement = "BottomRight"; break;
1077 default:
1078 case Toolbar::BottomCenter: placement = "BottomCenter"; break;
1079 }
1080
1081 sprintf(rc_string, "session.screen%d.toolbar.placement", screen_number);
1082 config.setValue(rc_string, placement);
1083
1084 #ifdef HAVE_STRFTIME
1085 sprintf(rc_string, "session.screen%d.strftimeFormat", screen_number);
1086 config.setValue(rc_string, screen->getStrftimeFormat());
1087 #else // !HAVE_STRFTIME
1088 sprintf(rc_string, "session.screen%d.dateFormat", screen_number);
1089 config.setValue(rc_string, screen->getDateFormat() == B_EuropeanDate ?
1090 "European" : "American");
1091
1092 sprintf(rc_string, "session.screen%d.clockFormat", screen_number);
1093 config.setValue(rc_string, screen->isClock24Hour() ? 24 : 12);
1094 #endif // HAVE_STRFTIME
1095
1096 sprintf(rc_string, "session.screen%d.edgeSnapThreshold", screen_number);
1097 config.setValue(rc_string, screen->getEdgeSnapThreshold());
1098
1099 sprintf(rc_string, "session.screen%d.toolbar.widthPercent", screen_number);
1100 config.setValue(rc_string, screen->getToolbarWidthPercent());
1101
1102 // write out the user's workspace names
1103 int i, len = 0;
1104 for (i = 0; i < screen->getWorkspaceCount(); i++)
1105 len += strlen((screen->getWorkspace(i)->getName()) ?
1106 screen->getWorkspace(i)->getName() : "Null") + 1;
1107
1108 char *resource_string = new char[len + 1024],
1109 *save_string = new char[len], *save_string_pos = save_string,
1110 *name_string_pos;
1111 if (save_string) {
1112 for (i = 0; i < screen->getWorkspaceCount(); i++) {
1113 len = strlen((screen->getWorkspace(i)->getName()) ?
1114 screen->getWorkspace(i)->getName() : "Null") + 1;
1115 name_string_pos =
1116 (char *) ((screen->getWorkspace(i)->getName()) ?
1117 screen->getWorkspace(i)->getName() : "Null");
1118
1119 while (--len) *(save_string_pos++) = *(name_string_pos++);
1120 *(save_string_pos++) = ',';
1121 }
1122 }
1123
1124 *(--save_string_pos) = '\0';
1125
1126 sprintf(resource_string, "session.screen%d.workspaceNames", screen_number);
1127 config.setValue(resource_string, save_string);
1128
1129 delete [] resource_string;
1130 delete [] save_string;
1131 /*
1132 std::string save_string = screen->getWorkspace(0)->getName();
1133 for (unsigned int i = 1; i < screen->getWorkspaceCount(); ++i) {
1134 save_string += ',';
1135 save_string += screen->getWorkspace(i)->getName();
1136 }
1137
1138 char *resource_string = new char[save_string.length() + 48];
1139 sprintf(resource_string, "session.screen%d.workspaceNames", screen_number);
1140 config.setValue(rc_string, save_string);
1141
1142 delete [] resource_string;*/
1143 }
1144
1145 config.setAutoSave(true);
1146 config.save();
1147 }
1148
1149 void Openbox::load_rc(void) {
1150 if (!config.load())
1151 return;
1152
1153 std::string s;
1154 long l;
1155
1156 if (resource.menu_file)
1157 delete [] resource.menu_file;
1158 if (config.getValue("session.menuFile", "Session.MenuFile", s))
1159 resource.menu_file = bstrdup(s.c_str());
1160 else
1161 resource.menu_file = bstrdup(DEFAULTMENU);
1162
1163 if (config.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
1164 l))
1165 resource.colors_per_channel = (l < 2 ? 2 : (l > 6 ? 6 : l)); // >= 2, <= 6
1166 else
1167 resource.colors_per_channel = 4;
1168
1169 if (resource.style_file)
1170 delete [] resource.style_file;
1171 if (config.getValue("session.styleFile", "Session.StyleFile", s))
1172 resource.style_file = bstrdup(s.c_str());
1173 else
1174 resource.style_file = bstrdup(DEFAULTSTYLE);
1175
1176 if (resource.titlebar_layout)
1177 delete [] resource.titlebar_layout;
1178 if (config.getValue("session.titlebarLayout", "Session.TitlebarLayout", s))
1179 resource.titlebar_layout = bstrdup(s.c_str());
1180 else
1181 resource.titlebar_layout = bstrdup("ILMC");
1182
1183 if (config.getValue("session.doubleClickInterval",
1184 "Session.DoubleClickInterval", l))
1185 resource.double_click_interval = l;
1186 else
1187 resource.double_click_interval = 250;
1188
1189 if (!config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l))
1190 resource.auto_raise_delay.tv_usec = l;
1191 else
1192 resource.auto_raise_delay.tv_usec = 400;
1193 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000;
1194 resource.auto_raise_delay.tv_usec -=
1195 (resource.auto_raise_delay.tv_sec * 1000);
1196 resource.auto_raise_delay.tv_usec *= 1000;
1197
1198 if (config.getValue("session.cacheLife", "Session.CacheLife", l))
1199 resource.cache_life = l;
1200 else
1201 resource.cache_life = 51;
1202 resource.cache_life *= 60000;
1203
1204 if (config.getValue("session.cacheMax", "Session.CacheMax", l))
1205 resource.cache_max = l;
1206 else
1207 resource.cache_max = 200;
1208 }
1209
1210
1211 void Openbox::load_rc(BScreen *screen) {
1212 assert (screen != NULL);
1213 const int screen_number = screen->getScreenNumber();
1214 assert (screen_number >= 0);
1215
1216 if (!config.load())
1217 return;
1218
1219 std::string s;
1220 long l;
1221 bool b;
1222 char name_lookup[1024], class_lookup[1024];
1223
1224 sprintf(name_lookup, "session.screen%d.fullMaximization", screen_number);
1225 sprintf(class_lookup, "Session.Screen%d.FullMaximization", screen_number);
1226 if (config.getValue(name_lookup, class_lookup, b))
1227 screen->saveFullMax((Bool)b);
1228 else
1229 screen->saveFullMax(False);
1230
1231 sprintf(name_lookup, "session.screen%d.focusNewWindows", screen_number);
1232 sprintf(class_lookup, "Session.Screen%d.FocusNewWindows", screen_number);
1233 if (config.getValue(name_lookup, class_lookup, b))
1234 screen->saveFocusNew((Bool)b);
1235 else
1236 screen->saveFocusNew(False);
1237
1238 sprintf(name_lookup, "session.screen%d.focusLastWindow", screen_number);
1239 sprintf(class_lookup, "Session.Screen%d.focusLastWindow", screen_number);
1240 if (config.getValue(name_lookup, class_lookup, b))
1241 screen->saveFocusLast((Bool)b);
1242 else
1243 screen->saveFocusLast(False);
1244
1245 sprintf(name_lookup, "session.screen%d.rowPlacementDirection",
1246 screen_number);
1247 sprintf(class_lookup, "Session.Screen%d.RowPlacementDirection",
1248 screen_number);
1249 if (config.getValue(name_lookup, class_lookup, s)) {
1250 if (0 == strncasecmp(s.c_str(), "righttoleft", s.length()))
1251 screen->saveRowPlacementDirection(BScreen::RightLeft);
1252 else
1253 screen->saveRowPlacementDirection(BScreen::LeftRight);
1254 } else
1255 screen->saveRowPlacementDirection(BScreen::LeftRight);
1256
1257 sprintf(name_lookup, "session.screen%d.colPlacementDirection",
1258 screen_number);
1259 sprintf(class_lookup, "Session.Screen%d.ColPlacementDirection",
1260 screen_number);
1261 if (config.getValue(name_lookup, class_lookup, s)) {
1262 if (0 == strncasecmp(s.c_str(), "bottomtotop", s.length()))
1263 screen->saveColPlacementDirection(BScreen::BottomTop);
1264 else
1265 screen->saveColPlacementDirection(BScreen::TopBottom);
1266 } else
1267 screen->saveColPlacementDirection(BScreen::TopBottom);
1268
1269 sprintf(name_lookup, "session.screen%d.workspaces", screen_number);
1270 sprintf(class_lookup, "Session.Screen%d.Workspaces", screen_number);
1271 if (config.getValue(name_lookup, class_lookup, l))
1272 screen->saveWorkspaces(l);
1273 else
1274 screen->saveWorkspaces(1);
1275
1276 sprintf(name_lookup, "session.screen%d.toolbar.widthPercent",
1277 screen_number);
1278 sprintf(class_lookup, "Session.Screen%d.Toolbar.WidthPercent",
1279 screen_number);
1280 if (config.getValue(name_lookup, class_lookup, l) && (l > 0 && l <= 100))
1281 screen->saveToolbarWidthPercent(l);
1282 else
1283 screen->saveToolbarWidthPercent(66);
1284
1285 sprintf(name_lookup, "session.screen%d.toolbar.placement", screen_number);
1286 sprintf(class_lookup, "Session.Screen%d.Toolbar.Placement", screen_number);
1287 if (config.getValue(name_lookup, class_lookup, s)) {
1288 if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
1289 screen->saveToolbarPlacement(Toolbar::TopLeft);
1290 else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
1291 screen->saveToolbarPlacement(Toolbar::BottomLeft);
1292 else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
1293 screen->saveToolbarPlacement(Toolbar::TopCenter);
1294 else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
1295 screen->saveToolbarPlacement(Toolbar::TopRight);
1296 else if ( 0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
1297 screen->saveToolbarPlacement(Toolbar::BottomRight);
1298 else
1299 screen->saveToolbarPlacement(Toolbar::BottomCenter);
1300 } else
1301 screen->saveToolbarPlacement(Toolbar::BottomCenter);
1302
1303 screen->removeWorkspaceNames();
1304 sprintf(name_lookup, "session.screen%d.workspaceNames", screen_number);
1305 sprintf(class_lookup, "Session.Screen%d.WorkspaceNames", screen_number);
1306 if (config.getValue(name_lookup, class_lookup, s)) {
1307 // for (int i = 0; i < screen->getNumberOfWorkspaces(); i++) {
1308 std::string::const_iterator it = s.begin(), end = s.end();
1309 while(1) {
1310 std::string::const_iterator tmp = it;// current string.begin()
1311 it = std::find(tmp, end, ','); // look for comma between tmp and end
1312 std::string name(tmp, it); // name = s[tmp:it]
1313 screen->addWorkspaceName(name.c_str());
1314 if (it == end)
1315 break;
1316 ++it;
1317 }
1318 }
1319
1320 sprintf(name_lookup, "session.screen%d.toolbar.onTop", screen_number);
1321 sprintf(class_lookup, "Session.Screen%d.Toolbar.OnTop", screen_number);
1322 if (config.getValue(name_lookup, class_lookup, b))
1323 screen->saveToolbarOnTop((Bool)b);
1324 else
1325 screen->saveToolbarOnTop(False);
1326
1327 sprintf(name_lookup, "session.screen%d.toolbar.autoHide", screen_number);
1328 sprintf(class_lookup, "Session.Screen%d.Toolbar.autoHide", screen_number);
1329 if (config.getValue(name_lookup, class_lookup, b))
1330 screen->saveToolbarAutoHide((Bool)b);
1331 else
1332 screen->saveToolbarAutoHide(False);
1333
1334 sprintf(name_lookup, "session.screen%d.focusModel", screen_number);
1335 sprintf(class_lookup, "Session.Screen%d.FocusModel", screen_number);
1336 if (config.getValue(name_lookup, class_lookup, s)) {
1337 if (0 == strncasecmp(s.c_str(), "clicktofocus", s.length())) {
1338 screen->saveAutoRaise(False);
1339 screen->saveSloppyFocus(False);
1340 } else if (0 == strncasecmp(s.c_str(), "autoraisesloppyfocus",
1341 s.length())) {
1342 screen->saveSloppyFocus(True);
1343 screen->saveAutoRaise(True);
1344 } else {
1345 screen->saveSloppyFocus(True);
1346 screen->saveAutoRaise(False);
1347 }
1348 } else {
1349 screen->saveSloppyFocus(True);
1350 screen->saveAutoRaise(False);
1351 }
1352
1353 sprintf(name_lookup, "session.screen%d.windowZones", screen_number);
1354 sprintf(class_lookup, "Session.Screen%d.WindowZones", screen_number);
1355 if (config.getValue(name_lookup, class_lookup, l))
1356 screen->saveWindowZones((l == 1 || l == 2 || l == 4) ? l : 1);
1357 else
1358 screen->saveWindowZones(1);
1359
1360 sprintf(name_lookup, "session.screen%d.windowPlacement", screen_number);
1361 sprintf(class_lookup, "Session.Screen%d.WindowPlacement", screen_number);
1362 if (config.getValue(name_lookup, class_lookup, s)) {
1363 if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length()))
1364 screen->savePlacementPolicy(BScreen::RowSmartPlacement);
1365 else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length()))
1366 screen->savePlacementPolicy(BScreen::ColSmartPlacement);
1367 else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
1368 screen->savePlacementPolicy(BScreen::BestFitPlacement);
1369 else
1370 screen->savePlacementPolicy(BScreen::CascadePlacement);
1371 } else
1372 screen->savePlacementPolicy(BScreen::RowSmartPlacement);
1373
1374 #ifdef SLIT
1375 sprintf(name_lookup, "session.screen%d.slit.placement", screen_number);
1376 sprintf(class_lookup, "Session.Screen%d.Slit.Placement", screen_number);
1377 if (config.getValue(name_lookup, class_lookup, s)) {
1378 if (0 == strncasecmp(s.c_str(), "TopLeft", s.length()))
1379 screen->saveSlitPlacement(Slit::TopLeft);
1380 else if (0 == strncasecmp(s.c_str(), "CenterLeft", s.length()))
1381 screen->saveSlitPlacement(Slit::CenterLeft);
1382 else if (0 == strncasecmp(s.c_str(), "BottomLeft", s.length()))
1383 screen->saveSlitPlacement(Slit::BottomLeft);
1384 else if (0 == strncasecmp(s.c_str(), "TopCenter", s.length()))
1385 screen->saveSlitPlacement(Slit::TopCenter);
1386 else if (0 == strncasecmp(s.c_str(), "BottomCenter", s.length()))
1387 screen->saveSlitPlacement(Slit::BottomCenter);
1388 else if (0 == strncasecmp(s.c_str(), "TopRight", s.length()))
1389 screen->saveSlitPlacement(Slit::TopRight);
1390 else if (0 == strncasecmp(s.c_str(), "BottomRight", s.length()))
1391 screen->saveSlitPlacement(Slit::BottomRight);
1392 else
1393 screen->saveSlitPlacement(Slit::CenterRight);
1394 } else
1395 screen->saveSlitPlacement(Slit::CenterRight);
1396
1397 sprintf(name_lookup, "session.screen%d.slit.direction", screen_number);
1398 sprintf(class_lookup, "Session.Screen%d.Slit.Direction", screen_number);
1399 if (config.getValue(name_lookup, class_lookup, s)) {
1400 if (0 == strncasecmp(s.c_str(), "Horizontal", s.length()))
1401 screen->saveSlitDirection(Slit::Horizontal);
1402 else
1403 screen->saveSlitDirection(Slit::Vertical);
1404 } else
1405 screen->saveSlitDirection(Slit::Vertical);
1406
1407 sprintf(name_lookup, "session.screen%d.slit.onTop", screen_number);
1408 sprintf(class_lookup, "Session.Screen%d.Slit.OnTop", screen_number);
1409 if (config.getValue(name_lookup, class_lookup, b))
1410 screen->saveSlitOnTop((Bool)b);
1411 else
1412 screen->saveSlitOnTop(False);
1413
1414 sprintf(name_lookup, "session.screen%d.slit.autoHide", screen_number);
1415 sprintf(class_lookup, "Session.Screen%d.Slit.AutoHide", screen_number);
1416 if (config.getValue(name_lookup, class_lookup, b))
1417 screen->saveSlitAutoHide((Bool)b);
1418 else
1419 screen->saveSlitAutoHide(False);
1420 #endif // SLIT
1421
1422 #ifdef HAVE_STRFTIME
1423 sprintf(name_lookup, "session.screen%d.strftimeFormat", screen_number);
1424 sprintf(class_lookup, "Session.Screen%d.StrftimeFormat", screen_number);
1425 if (config.getValue(name_lookup, class_lookup, s))
1426 screen->saveStrftimeFormat(s.c_str());
1427 else
1428 screen->saveStrftimeFormat("%I:%M %p");
1429
1430 #else // HAVE_STRFTIME
1431 sprintf(name_lookup, "session.screen%d.dateFormat", screen_number);
1432 sprintf(class_lookup, "Session.Screen%d.DateFormat", screen_number);
1433 if (config.getValue(name_lookup, class_lookup, s)) {
1434 if (strncasecmp(s.c_str(), "european", s.length()))
1435 screen->saveDateFormat(B_AmericanDate);
1436 else
1437 screen->saveDateFormat(B_EuropeanDate);
1438 } else
1439 screen->saveDateFormat(B_AmericanDate);
1440
1441 sprintf(name_lookup, "session.screen%d.clockFormat", screen_number);
1442 sprintf(class_lookup, "Session.Screen%d.ClockFormat", screen_number);
1443 if (config.getValue(name_lookup, class_lookup, l)) {
1444 if (clock == 24)
1445 screen->saveClock24Hour(True);
1446 else
1447 screen->saveClock24Hour(False);
1448 } else
1449 screen->saveClock24Hour(False);
1450 #endif // HAVE_STRFTIME
1451
1452 sprintf(name_lookup, "session.screen%d.edgeSnapThreshold", screen_number);
1453 sprintf(class_lookup, "Session.Screen%d.EdgeSnapThreshold", screen_number);
1454 if (config.getValue(name_lookup, class_lookup, l))
1455 screen->saveEdgeSnapThreshold(l);
1456 else
1457 screen->saveEdgeSnapThreshold(4);
1458
1459 sprintf(name_lookup, "session.screen%d.imageDither", screen_number);
1460 sprintf(class_lookup, "Session.Screen%d.ImageDither", screen_number);
1461 if (config.getValue("session.imageDither", "Session.ImageDither", b))
1462 screen->saveImageDither((Bool)b);
1463 else
1464 screen->saveImageDither(True);
1465
1466 sprintf(name_lookup, "session.screen%d.rootCommand", screen_number);
1467 sprintf(class_lookup, "Session.Screen%d.RootCommand", screen_number);
1468 if (config.getValue(name_lookup, class_lookup, s))
1469 screen->saveRootCommand(s.c_str());
1470 else
1471 screen->saveRootCommand(NULL);
1472
1473 if (config.getValue("session.opaqueMove", "Session.OpaqueMove", b))
1474 screen->saveOpaqueMove((Bool)b);
1475 else
1476 screen->saveOpaqueMove(False);
1477 }
1478
1479
1480 void Openbox::reload_rc(void) {
1481 load_rc();
1482 reconfigure();
1483 }
1484
1485
1486 void Openbox::reconfigure(void) {
1487 reconfigure_wait = True;
1488
1489 if (! timer->isTiming()) timer->start();
1490 }
1491
1492
1493 void Openbox::real_reconfigure(void) {
1494 grab();
1495
1496 config.load();
1497 config.setValue("session.styleFile", resource.style_file); // autosave's
1498
1499 for (int i = 0, n = menuTimestamps->count(); i < n; i++) {
1500 MenuTimestamp *ts = menuTimestamps->remove(0);
1501
1502 if (ts) {
1503 if (ts->filename)
1504 delete [] ts->filename;
1505
1506 delete ts;
1507 }
1508 }
1509
1510 LinkedListIterator<BScreen> it(screenList);
1511 for (BScreen *screen = it.current(); screen; it++, screen = it.current()) {
1512 screen->reconfigure();
1513 }
1514
1515 ungrab();
1516 }
1517
1518
1519 void Openbox::checkMenu(void) {
1520 Bool reread = False;
1521 LinkedListIterator<MenuTimestamp> it(menuTimestamps);
1522 for (MenuTimestamp *tmp = it.current(); tmp && (! reread);
1523 it++, tmp = it.current()) {
1524 struct stat buf;
1525
1526 if (! stat(tmp->filename, &buf)) {
1527 if (tmp->timestamp != buf.st_ctime)
1528 reread = True;
1529 } else {
1530 reread = True;
1531 }
1532 }
1533
1534 if (reread) rereadMenu();
1535 }
1536
1537
1538 void Openbox::rereadMenu(void) {
1539 reread_menu_wait = True;
1540
1541 if (! timer->isTiming()) timer->start();
1542 }
1543
1544
1545 void Openbox::real_rereadMenu(void) {
1546 for (int i = 0, n = menuTimestamps->count(); i < n; i++) {
1547 MenuTimestamp *ts = menuTimestamps->remove(0);
1548
1549 if (ts) {
1550 if (ts->filename)
1551 delete [] ts->filename;
1552
1553 delete ts;
1554 }
1555 }
1556
1557 LinkedListIterator<BScreen> it(screenList);
1558 for (BScreen *screen = it.current(); screen; it++, screen = it.current())
1559 screen->rereadMenu();
1560 }
1561
1562
1563 void Openbox::saveStyleFilename(const char *filename) {
1564 if (resource.style_file)
1565 delete [] resource.style_file;
1566
1567 resource.style_file = bstrdup(filename);
1568 }
1569
1570
1571 void Openbox::saveMenuFilename(const char *filename) {
1572 Bool found = False;
1573
1574 LinkedListIterator<MenuTimestamp> it(menuTimestamps);
1575 for (MenuTimestamp *tmp = it.current(); tmp && (! found);
1576 it++, tmp = it.current()) {
1577 if (! strcmp(tmp->filename, filename)) found = True;
1578 }
1579 if (! found) {
1580 struct stat buf;
1581
1582 if (! stat(filename, &buf)) {
1583 MenuTimestamp *ts = new MenuTimestamp;
1584
1585 ts->filename = bstrdup(filename);
1586 ts->timestamp = buf.st_ctime;
1587
1588 menuTimestamps->insert(ts);
1589 }
1590 }
1591 }
1592
1593
1594 void Openbox::timeout(void) {
1595 if (reconfigure_wait)
1596 real_reconfigure();
1597
1598 if (reread_menu_wait)
1599 real_rereadMenu();
1600
1601 reconfigure_wait = reread_menu_wait = False;
1602 }
1603
1604
1605 void Openbox::setFocusedWindow(OpenboxWindow *win) {
1606 BScreen *old_screen = (BScreen *) 0, *screen = (BScreen *) 0;
1607 OpenboxWindow *old_win = (OpenboxWindow *) 0;
1608 Toolbar *old_tbar = (Toolbar *) 0, *tbar = (Toolbar *) 0;
1609 Workspace *old_wkspc = (Workspace *) 0, *wkspc = (Workspace *) 0;
1610
1611 if (focused_window) {
1612 old_win = focused_window;
1613 old_screen = old_win->getScreen();
1614 old_tbar = old_screen->getToolbar();
1615 old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber());
1616
1617 old_win->setFocusFlag(False);
1618 old_wkspc->getMenu()->setItemSelected(old_win->getWindowNumber(), False);
1619 }
1620
1621 if (win && ! win->isIconic()) {
1622 screen = win->getScreen();
1623 tbar = screen->getToolbar();
1624 wkspc = screen->getWorkspace(win->getWorkspaceNumber());
1625
1626 focused_window = win;
1627
1628 win->setFocusFlag(True);
1629 wkspc->getMenu()->setItemSelected(win->getWindowNumber(), True);
1630 } else {
1631 focused_window = (OpenboxWindow *) 0;
1632 }
1633
1634 if (tbar)
1635 tbar->redrawWindowLabel(True);
1636 if (screen)
1637 screen->updateNetizenWindowFocus();
1638
1639 if (old_tbar && old_tbar != tbar)
1640 old_tbar->redrawWindowLabel(True);
1641 if (old_screen && old_screen != screen)
1642 old_screen->updateNetizenWindowFocus();
1643 }
1644
1645 #warning TODO: wrap in appropriate #ifdefs.
1646
1647 void Openbox::symlink_rc(const char*rcfile)const{
1648 char *homedir = getenv("HOME");
1649
1650 char *link_file = new char[strlen(homedir) + strlen("/.blackoxrc") + 1];
1651 sprintf(link_file, "%s/.blackboxrc", homedir);
1652 if(symlink(rcfile, link_file) == -1){
1653 perror("Cannot create symlink");
1654 }
1655 }
This page took 0.116295 seconds and 4 git commands to generate.