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)
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
34 #include <X11/Xutil.h>
35 #include <X11/Xresource.h>
36 #include <X11/Xatom.h>
37 #include <X11/keysym.h>
40 #include <X11/extensions/shape.h>
46 #include "Clientmenu.h"
56 #include "Workspace.h"
57 #include "Workspacemenu.h"
65 #endif // HAVE_STDIO_H
69 #endif // HAVE_STDLIB_H
73 #endif // HAVE_STRING_H
76 # include <sys/types.h>
78 #endif // HAVE_UNISTD_H
80 #ifdef HAVE_SYS_PARAM_H
81 # include <sys/param.h>
82 #endif // HAVE_SYS_PARAM_H
85 #define MAXPATHLEN 255
88 #ifdef HAVE_SYS_SELECT_H
89 # include <sys/select.h>
90 #endif // HAVE_SYS_SELECT_H
94 #endif // HAVE_SIGNAL_H
96 #ifdef HAVE_SYS_SIGNAL_H
97 # include <sys/signal.h>
98 #endif // HAVE_SYS_SIGNAL_H
100 #ifdef HAVE_SYS_STAT_H
101 # include <sys/types.h>
102 # include <sys/stat.h>
103 #endif // HAVE_SYS_STAT_H
105 #ifdef TIME_WITH_SYS_TIME
106 # include <sys/time.h>
108 #else // !TIME_WITH_SYS_TIME
109 # ifdef HAVE_SYS_TIME_H
110 # include <sys/time.h>
111 # else // !HAVE_SYS_TIME_H
113 # endif // HAVE_SYS_TIME_H
114 #endif // TIME_WITH_SYS_TIME
118 #endif // HAVE_LIBGEN_H
120 #ifndef HAVE_BASENAME
121 static inline char *basename (char *s) {
124 while (*s) if (*s++ == '/') save = s;
128 #endif // HAVE_BASENAME
131 // X event scanner for enter/leave notifies - adapted from twm
132 typedef struct scanargs {
134 Bool leave, inferior, enter;
137 static Bool queueScanner(Display *, XEvent *e, char *args) {
138 if ((e->type == LeaveNotify) &&
139 (e->xcrossing.window == ((scanargs *) args)->w) &&
140 (e->xcrossing.mode == NotifyNormal)) {
141 ((scanargs *) args)->leave = True;
142 ((scanargs *) args)->inferior = (e->xcrossing.detail == NotifyInferior);
143 } else if ((e->type == EnterNotify) &&
144 (e->xcrossing.mode == NotifyUngrab)) {
145 ((scanargs *) args)->enter = True;
154 Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
155 : BaseDisplay(m_argv[0], dpy_name) {
158 if (! XSupportsLocale())
159 fprintf(stderr, "X server does not support locale\n");
161 if (XSetLocaleModifiers("") == NULL)
162 fprintf(stderr, "cannot set locale modifiers\n");
168 char *homedir = getenv("HOME");
170 rc_file = new char[strlen(homedir) + strlen("/.openbox/rc") + 1];
171 sprintf(rc_file, "%s/.openbox", homedir);
173 // try to make sure the ~/.openbox directory exists
174 mkdir(rc_file, S_IREAD | S_IWRITE | S_IEXEC | S_IRGRP | S_IWGRP | S_IXGRP |
175 S_IROTH | S_IWOTH | S_IXOTH);
177 sprintf(rc_file, "%s/.openbox/rc", homedir);
179 rc_file = bstrdup(rc);
181 config.setFile(rc_file);
185 resource.menu_file = resource.style_file = NULL;
186 resource.titlebar_layout = NULL;
187 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0;
189 current_screen = (BScreen *) 0;
190 masked_window = (OpenboxWindow *) 0;
196 openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False);
197 #endif // HAVE_GETPID
199 for (unsigned int s = 0; s < getNumberOfScreens(); s++) {
200 BScreen *screen = new BScreen(*this, s, config);
202 if (! screen->isScreenManaged()) {
207 screenList.push_back(screen);
210 if (screenList.empty()) {
212 i18n->getMessage(openboxSet, openboxNoManagableScreens,
213 "Openbox::Openbox: no managable screens found, aborting.\n"));
216 current_screen = screenList.front();
218 // save current settings and default values
221 XSynchronize(getXDisplay(), False);
222 XSync(getXDisplay(), False);
224 reconfigure_wait = reread_menu_wait = False;
226 timer = new BTimer(*this, *this);
227 timer->setTimeout(0);
228 timer->fireOnce(True);
236 Openbox::~Openbox() {
237 for_each(screenList.begin(), screenList.end(),
240 for_each(menuTimestamps.begin(), menuTimestamps.end(),
243 if (resource.menu_file)
244 delete [] resource.menu_file;
246 if (resource.style_file)
247 delete [] resource.style_file;
249 if (resource.titlebar_layout)
250 delete [] resource.titlebar_layout;
258 void Openbox::process_event(XEvent *e) {
259 if ((masked == e->xany.window && masked_window) &&
260 (e->type == MotionNotify)) {
261 last_time = e->xmotion.time;
262 masked_window->motionNotifyEvent(&e->xmotion);
268 // strip the lock key modifiers
269 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
271 last_time = e->xbutton.time;
273 OpenboxWindow *win = (OpenboxWindow *) 0;
274 Basemenu *menu = (Basemenu *) 0;
277 Slit *slit = (Slit *) 0;
280 Toolbar *tbar = (Toolbar *) 0;
282 if ((win = searchWindow(e->xbutton.window))) {
283 win->buttonPressEvent(&e->xbutton);
285 if (e->xbutton.button == 1)
286 win->installColormap(True);
287 } else if ((menu = searchMenu(e->xbutton.window))) {
288 menu->buttonPressEvent(&e->xbutton);
291 } else if ((slit = searchSlit(e->xbutton.window))) {
292 slit->buttonPressEvent(&e->xbutton);
295 } else if ((tbar = searchToolbar(e->xbutton.window))) {
296 tbar->buttonPressEvent(&e->xbutton);
298 ScreenList::iterator it;
299 for (it = screenList.begin(); it != screenList.end(); ++it) {
300 BScreen *screen = *it;
301 if (e->xbutton.window == screen->getRootWindow()) {
302 if (e->xbutton.button == 1) {
303 if (! screen->isRootColormapInstalled())
304 screen->getImageControl()->installRootColormap();
306 if (screen->getWorkspacemenu()->isVisible())
307 screen->getWorkspacemenu()->hide();
309 if (screen->getRootmenu()->isVisible())
310 screen->getRootmenu()->hide();
311 } else if (e->xbutton.button == 2) {
312 int mx = e->xbutton.x_root -
313 (screen->getWorkspacemenu()->getWidth() / 2);
314 int my = e->xbutton.y_root -
315 (screen->getWorkspacemenu()->getTitleHeight() / 2);
320 if (mx + screen->getWorkspacemenu()->getWidth() >
322 mx = screen->size().w() -
323 screen->getWorkspacemenu()->getWidth() -
324 screen->getBorderWidth();
326 if (my + screen->getWorkspacemenu()->getHeight() >
328 my = screen->size().h() -
329 screen->getWorkspacemenu()->getHeight() -
330 screen->getBorderWidth();
332 screen->getWorkspacemenu()->move(mx, my);
334 if (! screen->getWorkspacemenu()->isVisible()) {
335 screen->getWorkspacemenu()->removeParent();
336 screen->getWorkspacemenu()->show();
338 } else if (e->xbutton.button == 3) {
339 int mx = e->xbutton.x_root -
340 (screen->getRootmenu()->getWidth() / 2);
341 int my = e->xbutton.y_root -
342 (screen->getRootmenu()->getTitleHeight() / 2);
347 if (mx + screen->getRootmenu()->getWidth() > screen->size().w())
348 mx = screen->size().w() -
349 screen->getRootmenu()->getWidth() -
350 screen->getBorderWidth();
352 if (my + screen->getRootmenu()->getHeight() > screen->size().h())
353 my = screen->size().h() -
354 screen->getRootmenu()->getHeight() -
355 screen->getBorderWidth();
357 screen->getRootmenu()->move(mx, my);
359 if (! screen->getRootmenu()->isVisible()) {
361 screen->getRootmenu()->show();
363 } else if (e->xbutton.button == 4) {
364 if ((screen->getCurrentWorkspaceID() + 1) >
365 screen->getWorkspaceCount() - 1)
366 screen->changeWorkspaceID(0);
368 screen->changeWorkspaceID(screen->getCurrentWorkspaceID() + 1);
369 } else if (e->xbutton.button == 5) {
370 if ((screen->getCurrentWorkspaceID() - 1) < 0)
371 screen->changeWorkspaceID(screen->getWorkspaceCount() - 1);
373 screen->changeWorkspaceID(screen->getCurrentWorkspaceID() - 1);
382 case ButtonRelease: {
383 // strip the lock key modifiers
384 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
386 last_time = e->xbutton.time;
388 OpenboxWindow *win = (OpenboxWindow *) 0;
389 Basemenu *menu = (Basemenu *) 0;
390 Toolbar *tbar = (Toolbar *) 0;
392 if ((win = searchWindow(e->xbutton.window)))
393 win->buttonReleaseEvent(&e->xbutton);
394 else if ((menu = searchMenu(e->xbutton.window)))
395 menu->buttonReleaseEvent(&e->xbutton);
396 else if ((tbar = searchToolbar(e->xbutton.window)))
397 tbar->buttonReleaseEvent(&e->xbutton);
402 case ConfigureRequest: {
403 OpenboxWindow *win = (OpenboxWindow *) 0;
406 Slit *slit = (Slit *) 0;
409 if ((win = searchWindow(e->xconfigurerequest.window))) {
410 win->configureRequestEvent(&e->xconfigurerequest);
413 } else if ((slit = searchSlit(e->xconfigurerequest.window))) {
414 slit->configureRequestEvent(&e->xconfigurerequest);
420 if (validateWindow(e->xconfigurerequest.window)) {
423 xwc.x = e->xconfigurerequest.x;
424 xwc.y = e->xconfigurerequest.y;
425 xwc.width = e->xconfigurerequest.width;
426 xwc.height = e->xconfigurerequest.height;
427 xwc.border_width = e->xconfigurerequest.border_width;
428 xwc.sibling = e->xconfigurerequest.above;
429 xwc.stack_mode = e->xconfigurerequest.detail;
431 XConfigureWindow(getXDisplay(), e->xconfigurerequest.window,
432 e->xconfigurerequest.value_mask, &xwc);
444 i18n->getMessage(openboxSet, openboxMapRequest,
445 "Openbox::process_event(): MapRequest for 0x%lx\n"),
446 e->xmaprequest.window);
449 OpenboxWindow *win = searchWindow(e->xmaprequest.window);
452 win = new OpenboxWindow(*this, e->xmaprequest.window);
454 if ((win = searchWindow(e->xmaprequest.window)))
455 win->mapRequestEvent(&e->xmaprequest);
461 OpenboxWindow *win = searchWindow(e->xmap.window);
464 win->mapNotifyEvent(&e->xmap);
470 OpenboxWindow *win = (OpenboxWindow *) 0;
473 Slit *slit = (Slit *) 0;
476 if ((win = searchWindow(e->xunmap.window))) {
477 win->unmapNotifyEvent(&e->xunmap);
479 } else if ((slit = searchSlit(e->xunmap.window))) {
480 slit->removeClient(e->xunmap.window);
488 case DestroyNotify: {
489 OpenboxWindow *win = (OpenboxWindow *) 0;
492 Slit *slit = (Slit *) 0;
495 if ((win = searchWindow(e->xdestroywindow.window))) {
496 win->destroyNotifyEvent(&e->xdestroywindow);
498 } else if ((slit = searchSlit(e->xdestroywindow.window))) {
499 slit->removeClient(e->xdestroywindow.window, False);
507 // strip the lock key modifiers
508 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
510 last_time = e->xmotion.time;
512 OpenboxWindow *win = (OpenboxWindow *) 0;
513 Basemenu *menu = (Basemenu *) 0;
515 if ((win = searchWindow(e->xmotion.window)))
516 win->motionNotifyEvent(&e->xmotion);
517 else if ((menu = searchMenu(e->xmotion.window)))
518 menu->motionNotifyEvent(&e->xmotion);
523 case PropertyNotify: {
524 last_time = e->xproperty.time;
526 if (e->xproperty.state != PropertyDelete) {
527 OpenboxWindow *win = searchWindow(e->xproperty.window);
530 win->propertyNotifyEvent(e->xproperty.atom);
537 last_time = e->xcrossing.time;
539 BScreen *screen = (BScreen *) 0;
540 OpenboxWindow *win = (OpenboxWindow *) 0;
541 Basemenu *menu = (Basemenu *) 0;
542 Toolbar *tbar = (Toolbar *) 0;
545 Slit *slit = (Slit *) 0;
548 if (e->xcrossing.mode == NotifyGrab) break;
552 sa.w = e->xcrossing.window;
553 sa.enter = sa.leave = False;
554 XCheckIfEvent(getXDisplay(), &dummy, queueScanner, (char *) &sa);
556 if ((e->xcrossing.window == e->xcrossing.root) &&
557 (screen = searchScreen(e->xcrossing.window))) {
558 screen->getImageControl()->installRootColormap();
559 } else if ((win = searchWindow(e->xcrossing.window))) {
560 if (win->getScreen()->sloppyFocus() &&
561 (! win->isFocused()) && (! no_focus)) {
564 if (((! sa.leave) || sa.inferior) && win->isVisible() &&
565 win->setInputFocus())
566 win->installColormap(True);
570 } else if ((menu = searchMenu(e->xcrossing.window))) {
571 menu->enterNotifyEvent(&e->xcrossing);
572 } else if ((tbar = searchToolbar(e->xcrossing.window))) {
573 tbar->enterNotifyEvent(&e->xcrossing);
575 } else if ((slit = searchSlit(e->xcrossing.window))) {
576 slit->enterNotifyEvent(&e->xcrossing);
583 last_time = e->xcrossing.time;
585 OpenboxWindow *win = (OpenboxWindow *) 0;
586 Basemenu *menu = (Basemenu *) 0;
587 Toolbar *tbar = (Toolbar *) 0;
590 Slit *slit = (Slit *) 0;
593 if ((menu = searchMenu(e->xcrossing.window)))
594 menu->leaveNotifyEvent(&e->xcrossing);
595 else if ((win = searchWindow(e->xcrossing.window)))
596 win->installColormap(False);
597 else if ((tbar = searchToolbar(e->xcrossing.window)))
598 tbar->leaveNotifyEvent(&e->xcrossing);
600 else if ((slit = searchSlit(e->xcrossing.window)))
601 slit->leaveNotifyEvent(&e->xcrossing);
608 OpenboxWindow *win = (OpenboxWindow *) 0;
609 Basemenu *menu = (Basemenu *) 0;
610 Toolbar *tbar = (Toolbar *) 0;
612 if ((win = searchWindow(e->xexpose.window)))
613 win->exposeEvent(&e->xexpose);
614 else if ((menu = searchMenu(e->xexpose.window)))
615 menu->exposeEvent(&e->xexpose);
616 else if ((tbar = searchToolbar(e->xexpose.window)))
617 tbar->exposeEvent(&e->xexpose);
623 Toolbar *tbar = searchToolbar(e->xkey.window);
625 if (tbar && tbar->isEditing())
626 tbar->keyPressEvent(&e->xkey);
631 case ColormapNotify: {
632 BScreen *screen = searchScreen(e->xcolormap.window);
635 screen->setRootColormapInstalled((e->xcolormap.state ==
636 ColormapInstalled) ? True : False);
642 if (e->xfocus.mode == NotifyUngrab || e->xfocus.detail == NotifyPointer)
645 OpenboxWindow *win = searchWindow(e->xfocus.window);
646 if (win && !win->isFocused())
655 case ClientMessage: {
656 if (e->xclient.format == 32) {
657 if (e->xclient.message_type == getWMChangeStateAtom()) {
658 OpenboxWindow *win = searchWindow(e->xclient.window);
659 if (! win || ! win->validateClient()) return;
661 if (e->xclient.data.l[0] == IconicState)
663 if (e->xclient.data.l[0] == NormalState)
665 } else if (e->xclient.message_type == getOpenboxChangeWorkspaceAtom()) {
666 BScreen *screen = searchScreen(e->xclient.window);
668 if (screen && e->xclient.data.l[0] >= 0 &&
669 e->xclient.data.l[0] < screen->getWorkspaceCount())
670 screen->changeWorkspaceID(e->xclient.data.l[0]);
671 } else if (e->xclient.message_type == getOpenboxChangeWindowFocusAtom()) {
672 OpenboxWindow *win = searchWindow(e->xclient.window);
674 if (win && win->isVisible() && win->setInputFocus())
675 win->installColormap(True);
676 } else if (e->xclient.message_type == getOpenboxCycleWindowFocusAtom()) {
677 BScreen *screen = searchScreen(e->xclient.window);
680 if (! e->xclient.data.l[0])
685 } else if (e->xclient.message_type == getOpenboxChangeAttributesAtom()) {
686 OpenboxWindow *win = searchWindow(e->xclient.window);
688 if (win && win->validateClient()) {
690 net.flags = e->xclient.data.l[0];
691 net.attrib = e->xclient.data.l[1];
692 net.workspace = e->xclient.data.l[2];
693 net.stack = e->xclient.data.l[3];
694 net.decoration = e->xclient.data.l[4];
696 win->changeOpenboxHints(&net);
707 if (e->type == getShapeEventBase()) {
708 XShapeEvent *shape_event = (XShapeEvent *) e;
709 OpenboxWindow *win = (OpenboxWindow *) 0;
711 if ((win = searchWindow(e->xany.window)) ||
712 (shape_event->kind != ShapeBounding))
713 win->shapeEvent(shape_event);
722 Bool Openbox::handleSignal(int sig) {
748 BScreen *Openbox::searchScreen(Window window) {
749 ScreenList::iterator it;
750 for (it = screenList.begin(); it != screenList.end(); ++it)
751 if ((*it)->getRootWindow() == window)
753 return (BScreen *) 0;
757 OpenboxWindow *Openbox::searchWindow(Window window) {
758 WindowLookup::iterator it = windowSearchList.find(window);
759 if (it == windowSearchList.end())
760 return (OpenboxWindow *) 0;
765 OpenboxWindow *Openbox::searchGroup(Window window, OpenboxWindow *win) {
766 WindowLookup::iterator it = groupSearchList.find(window);
767 if (it != groupSearchList.end())
768 if (it->second->getClientWindow() != win->getClientWindow())
770 return (OpenboxWindow *) 0;
774 Basemenu *Openbox::searchMenu(Window window) {
775 MenuLookup::iterator it = menuSearchList.find(window);
776 if (it == menuSearchList.end())
777 return (Basemenu *) 0;
782 Toolbar *Openbox::searchToolbar(Window window) {
783 ToolbarLookup::iterator it = toolbarSearchList.find(window);
784 if (it == toolbarSearchList.end())
785 return (Toolbar *) 0;
791 Slit *Openbox::searchSlit(Window window) {
792 SlitLookup::iterator it = slitSearchList.find(window);
793 if (it == slitSearchList.end())
800 void Openbox::saveWindowSearch(Window window, OpenboxWindow *data) {
801 windowSearchList.insert(WindowLookupPair(window, data));
805 void Openbox::saveGroupSearch(Window window, OpenboxWindow *data) {
806 groupSearchList.insert(WindowLookupPair(window, data));
810 void Openbox::saveMenuSearch(Window window, Basemenu *data) {
811 menuSearchList.insert(MenuLookupPair(window, data));
815 void Openbox::saveToolbarSearch(Window window, Toolbar *data) {
816 toolbarSearchList.insert(ToolbarLookupPair(window, data));
821 void Openbox::saveSlitSearch(Window window, Slit *data) {
822 slitSearchList.insert(SlitLookupPair(window, data));
827 void Openbox::removeWindowSearch(Window window) {
828 windowSearchList.erase(window);
832 void Openbox::removeGroupSearch(Window window) {
833 groupSearchList.erase(window);
837 void Openbox::removeMenuSearch(Window window) {
838 menuSearchList.erase(window);
842 void Openbox::removeToolbarSearch(Window window) {
843 toolbarSearchList.erase(window);
848 void Openbox::removeSlitSearch(Window window) {
849 slitSearchList.erase(window);
854 void Openbox::restart(const char *prog) {
858 execlp(prog, prog, NULL);
862 // fall back in case the above execlp doesn't work
863 execvp(argv[0], argv);
864 execvp(basename(argv[0]), argv);
868 void Openbox::shutdown() {
869 BaseDisplay::shutdown();
871 std::for_each(screenList.begin(), screenList.end(),
872 std::mem_fun(&BScreen::shutdown));
876 XSync(getXDisplay(), False);
880 void Openbox::save() {
881 config.setAutoSave(false);
883 // save all values as they are so that the defaults will be written to the rc
886 config.setValue("session.menuFile", getMenuFilename());
887 config.setValue("session.colorsPerChannel",
888 resource.colors_per_channel);
889 config.setValue("session.styleFile", resource.style_file);
890 config.setValue("session.titlebarLayout", resource.titlebar_layout);
891 config.setValue("session.doubleClickInterval",
892 (long)resource.double_click_interval);
893 config.setValue("session.autoRaiseDelay",
894 ((resource.auto_raise_delay.tv_sec * 1000) +
895 (resource.auto_raise_delay.tv_usec / 1000)));
896 config.setValue("session.cacheLife", (long)resource.cache_life / 60000);
897 config.setValue("session.cacheMax", (long)resource.cache_max);
899 std::for_each(screenList.begin(), screenList.end(),
900 std::mem_fun(&BScreen::save));
902 config.setAutoSave(true);
906 void Openbox::load() {
913 if (resource.menu_file)
914 delete [] resource.menu_file;
915 if (config.getValue("session.menuFile", "Session.MenuFile", s))
916 resource.menu_file = bstrdup(s.c_str());
918 resource.menu_file = bstrdup(DEFAULTMENU);
920 if (config.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
922 resource.colors_per_channel = (l < 2 ? 2 : (l > 6 ? 6 : l)); // >= 2, <= 6
924 resource.colors_per_channel = 4;
926 if (resource.style_file)
927 delete [] resource.style_file;
928 if (config.getValue("session.styleFile", "Session.StyleFile", s))
929 resource.style_file = bstrdup(s.c_str());
931 resource.style_file = bstrdup(DEFAULTSTYLE);
933 if (resource.titlebar_layout)
934 delete [] resource.titlebar_layout;
935 if (config.getValue("session.titlebarLayout", "Session.TitlebarLayout", s))
936 resource.titlebar_layout = bstrdup(s.c_str());
938 resource.titlebar_layout = bstrdup("ILMC");
940 if (config.getValue("session.doubleClickInterval",
941 "Session.DoubleClickInterval", l))
942 resource.double_click_interval = l;
944 resource.double_click_interval = 250;
946 if (!config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l))
947 resource.auto_raise_delay.tv_usec = l;
949 resource.auto_raise_delay.tv_usec = 400;
950 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000;
951 resource.auto_raise_delay.tv_usec -=
952 (resource.auto_raise_delay.tv_sec * 1000);
953 resource.auto_raise_delay.tv_usec *= 1000;
955 if (config.getValue("session.cacheLife", "Session.CacheLife", l))
956 resource.cache_life = l;
958 resource.cache_life = 51;
959 resource.cache_life *= 60000;
961 if (config.getValue("session.cacheMax", "Session.CacheMax", l))
962 resource.cache_max = l;
964 resource.cache_max = 200;
968 void Openbox::reconfigure() {
969 reconfigure_wait = True;
971 if (! timer->isTiming()) timer->start();
975 void Openbox::real_reconfigure() {
980 for_each(menuTimestamps.begin(), menuTimestamps.end(),
982 menuTimestamps.clear();
984 std::for_each(screenList.begin(), screenList.end(),
985 std::mem_fun(&BScreen::reconfigure));
991 void Openbox::checkMenu() {
992 MenuTimestampList::iterator it;
993 for (it = menuTimestamps.begin(); it != menuTimestamps.end(); ++it) {
996 if (stat((*it)->filename, &buf) || (*it)->timestamp != buf.st_ctime) {
1004 void Openbox::rereadMenu() {
1005 reread_menu_wait = True;
1007 if (! timer->isTiming()) timer->start();
1011 void Openbox::real_rereadMenu() {
1012 std::for_each(menuTimestamps.begin(), menuTimestamps.end(),
1014 menuTimestamps.clear();
1016 std::for_each(screenList.begin(), screenList.end(),
1017 std::mem_fun(&BScreen::rereadMenu));
1021 void Openbox::setStyleFilename(const char *filename) {
1022 if (resource.style_file)
1023 delete [] resource.style_file;
1025 resource.style_file = bstrdup(filename);
1026 config.setValue("session.styleFile", resource.style_file);
1030 void Openbox::setMenuFilename(const char *filename) {
1033 MenuTimestampList::iterator it;
1034 for (it = menuTimestamps.begin(); it != menuTimestamps.end(); ++it)
1035 if (! strcmp((*it)->filename, filename)) {
1042 if (! stat(filename, &buf)) {
1043 MenuTimestamp *ts = new MenuTimestamp;
1045 ts->filename = bstrdup(filename);
1046 ts->timestamp = buf.st_ctime;
1048 menuTimestamps.push_back(ts);
1054 void Openbox::timeout() {
1055 if (reconfigure_wait)
1058 if (reread_menu_wait)
1061 reconfigure_wait = reread_menu_wait = False;
1065 OpenboxWindow *Openbox::focusedWindow() {
1068 if ((w = current_screen->getCurrentWorkspace()))
1069 return w->focusedWindow();
1070 return (OpenboxWindow *) 0;
1074 void Openbox::focusWindow(OpenboxWindow *win) {
1075 BScreen *old_screen = (BScreen *) 0;
1076 Toolbar *old_tbar = (Toolbar *) 0, *tbar = (Toolbar *) 0;
1077 Workspace *old_wkspc = (Workspace *) 0, *wkspc = (Workspace *) 0;
1079 OpenboxWindow *old_win = focusedWindow();
1080 if (old_win != (OpenboxWindow *) 0) {
1081 old_screen = old_win->getScreen();
1082 old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber());
1083 old_tbar = old_screen->getToolbar();
1085 old_win->setFocusFlag(false);
1086 old_wkspc->focusWindow((OpenboxWindow *) 0);
1089 if (win && !win->isIconic()) {
1090 current_screen = win->getScreen();
1091 tbar = current_screen->getToolbar();
1092 wkspc = current_screen->getWorkspace(win->getWorkspaceNumber());
1093 win->setFocusFlag(true);
1094 wkspc->focusWindow(win);
1097 tbar->redrawWindowLabel(true);
1098 current_screen->updateNetizenWindowFocus();
1100 XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime);
1103 if (old_tbar && old_tbar != tbar)
1104 old_tbar->redrawWindowLabel(true);
1105 if (old_screen && old_screen != current_screen)
1106 old_screen->updateNetizenWindowFocus();