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 focused_window = masked_window = NULL;
192 windowSearchList = new LinkedList<WindowSearch>;
193 menuSearchList = new LinkedList<MenuSearch>;
196 slitSearchList = new LinkedList<SlitSearch>;
199 toolbarSearchList = new LinkedList<ToolbarSearch>;
200 groupSearchList = new LinkedList<WindowSearch>;
202 menuTimestamps = new LinkedList<MenuTimestamp>;
207 openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False);
208 #endif // HAVE_GETPID
210 screenList = new LinkedList<BScreen>;
211 for (int i = 0; i < getNumberOfScreens(); i++) {
212 BScreen *screen = new BScreen(*this, i, config);
214 if (! screen->isScreenManaged()) {
219 screenList->insert(screen);
222 if (! screenList->count()) {
224 i18n->getMessage(openboxSet, openboxNoManagableScreens,
225 "Openbox::Openbox: no managable screens found, aborting.\n"));
229 // save current settings and default values
232 XSynchronize(getXDisplay(), False);
233 XSync(getXDisplay(), False);
235 reconfigure_wait = reread_menu_wait = False;
237 timer = new BTimer(*this, *this);
238 timer->setTimeout(0);
239 timer->fireOnce(True);
245 Openbox::~Openbox() {
246 while (screenList->count())
247 delete screenList->remove(0);
249 while (menuTimestamps->count()) {
250 MenuTimestamp *ts = menuTimestamps->remove(0);
253 delete [] ts->filename;
258 if (resource.menu_file)
259 delete [] resource.menu_file;
261 if (resource.style_file)
262 delete [] resource.style_file;
264 if (resource.titlebar_layout)
265 delete [] resource.titlebar_layout;
270 delete menuTimestamps;
272 delete windowSearchList;
273 delete menuSearchList;
274 delete toolbarSearchList;
275 delete groupSearchList;
280 delete slitSearchList;
285 void Openbox::process_event(XEvent *e) {
286 if ((masked == e->xany.window && masked_window) &&
287 (e->type == MotionNotify)) {
288 last_time = e->xmotion.time;
289 masked_window->motionNotifyEvent(&e->xmotion);
295 // strip the lock key modifiers
296 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
298 last_time = e->xbutton.time;
300 OpenboxWindow *win = (OpenboxWindow *) 0;
301 Basemenu *menu = (Basemenu *) 0;
304 Slit *slit = (Slit *) 0;
307 Toolbar *tbar = (Toolbar *) 0;
309 if ((win = searchWindow(e->xbutton.window))) {
310 win->buttonPressEvent(&e->xbutton);
312 if (e->xbutton.button == 1)
313 win->installColormap(True);
314 } else if ((menu = searchMenu(e->xbutton.window))) {
315 menu->buttonPressEvent(&e->xbutton);
318 } else if ((slit = searchSlit(e->xbutton.window))) {
319 slit->buttonPressEvent(&e->xbutton);
322 } else if ((tbar = searchToolbar(e->xbutton.window))) {
323 tbar->buttonPressEvent(&e->xbutton);
325 LinkedListIterator<BScreen> it(screenList);
326 BScreen *screen = it.current();
327 for (; screen; it++, screen = it.current()) {
328 if (e->xbutton.window == screen->getRootWindow()) {
329 if (e->xbutton.button == 1) {
330 if (! screen->isRootColormapInstalled())
331 screen->getImageControl()->installRootColormap();
333 if (screen->getWorkspacemenu()->isVisible())
334 screen->getWorkspacemenu()->hide();
336 if (screen->getRootmenu()->isVisible())
337 screen->getRootmenu()->hide();
338 } else if (e->xbutton.button == 2) {
339 int mx = e->xbutton.x_root -
340 (screen->getWorkspacemenu()->getWidth() / 2);
341 int my = e->xbutton.y_root -
342 (screen->getWorkspacemenu()->getTitleHeight() / 2);
347 if (mx + screen->getWorkspacemenu()->getWidth() >
349 mx = screen->size().w() -
350 screen->getWorkspacemenu()->getWidth() -
351 screen->getBorderWidth();
353 if (my + screen->getWorkspacemenu()->getHeight() >
355 my = screen->size().h() -
356 screen->getWorkspacemenu()->getHeight() -
357 screen->getBorderWidth();
359 screen->getWorkspacemenu()->move(mx, my);
361 if (! screen->getWorkspacemenu()->isVisible()) {
362 screen->getWorkspacemenu()->removeParent();
363 screen->getWorkspacemenu()->show();
365 } else if (e->xbutton.button == 3) {
366 int mx = e->xbutton.x_root -
367 (screen->getRootmenu()->getWidth() / 2);
368 int my = e->xbutton.y_root -
369 (screen->getRootmenu()->getTitleHeight() / 2);
374 if (mx + screen->getRootmenu()->getWidth() > screen->size().w())
375 mx = screen->size().w() -
376 screen->getRootmenu()->getWidth() -
377 screen->getBorderWidth();
379 if (my + screen->getRootmenu()->getHeight() > screen->size().h())
380 my = screen->size().h() -
381 screen->getRootmenu()->getHeight() -
382 screen->getBorderWidth();
384 screen->getRootmenu()->move(mx, my);
386 if (! screen->getRootmenu()->isVisible()) {
388 screen->getRootmenu()->show();
390 } else if (e->xbutton.button == 4) {
391 if ((screen->getCurrentWorkspaceID() + 1) >
392 screen->getWorkspaceCount() - 1)
393 screen->changeWorkspaceID(0);
395 screen->changeWorkspaceID(screen->getCurrentWorkspaceID() + 1);
396 } else if (e->xbutton.button == 5) {
397 if ((screen->getCurrentWorkspaceID() - 1) < 0)
398 screen->changeWorkspaceID(screen->getWorkspaceCount() - 1);
400 screen->changeWorkspaceID(screen->getCurrentWorkspaceID() - 1);
409 case ButtonRelease: {
410 // strip the lock key modifiers
411 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
413 last_time = e->xbutton.time;
415 OpenboxWindow *win = (OpenboxWindow *) 0;
416 Basemenu *menu = (Basemenu *) 0;
417 Toolbar *tbar = (Toolbar *) 0;
419 if ((win = searchWindow(e->xbutton.window)))
420 win->buttonReleaseEvent(&e->xbutton);
421 else if ((menu = searchMenu(e->xbutton.window)))
422 menu->buttonReleaseEvent(&e->xbutton);
423 else if ((tbar = searchToolbar(e->xbutton.window)))
424 tbar->buttonReleaseEvent(&e->xbutton);
429 case ConfigureRequest: {
430 OpenboxWindow *win = (OpenboxWindow *) 0;
433 Slit *slit = (Slit *) 0;
436 if ((win = searchWindow(e->xconfigurerequest.window))) {
437 win->configureRequestEvent(&e->xconfigurerequest);
440 } else if ((slit = searchSlit(e->xconfigurerequest.window))) {
441 slit->configureRequestEvent(&e->xconfigurerequest);
447 if (validateWindow(e->xconfigurerequest.window)) {
450 xwc.x = e->xconfigurerequest.x;
451 xwc.y = e->xconfigurerequest.y;
452 xwc.width = e->xconfigurerequest.width;
453 xwc.height = e->xconfigurerequest.height;
454 xwc.border_width = e->xconfigurerequest.border_width;
455 xwc.sibling = e->xconfigurerequest.above;
456 xwc.stack_mode = e->xconfigurerequest.detail;
458 XConfigureWindow(getXDisplay(), e->xconfigurerequest.window,
459 e->xconfigurerequest.value_mask, &xwc);
471 i18n->getMessage(openboxSet, openboxMapRequest,
472 "Openbox::process_event(): MapRequest for 0x%lx\n"),
473 e->xmaprequest.window);
476 OpenboxWindow *win = searchWindow(e->xmaprequest.window);
479 win = new OpenboxWindow(*this, e->xmaprequest.window);
481 if ((win = searchWindow(e->xmaprequest.window)))
482 win->mapRequestEvent(&e->xmaprequest);
488 OpenboxWindow *win = searchWindow(e->xmap.window);
491 win->mapNotifyEvent(&e->xmap);
497 OpenboxWindow *win = (OpenboxWindow *) 0;
500 Slit *slit = (Slit *) 0;
503 if ((win = searchWindow(e->xunmap.window))) {
504 win->unmapNotifyEvent(&e->xunmap);
505 if (focused_window == win)
506 focused_window = (OpenboxWindow *) 0;
508 } else if ((slit = searchSlit(e->xunmap.window))) {
509 slit->removeClient(e->xunmap.window);
517 case DestroyNotify: {
518 OpenboxWindow *win = (OpenboxWindow *) 0;
521 Slit *slit = (Slit *) 0;
524 if ((win = searchWindow(e->xdestroywindow.window))) {
525 win->destroyNotifyEvent(&e->xdestroywindow);
526 if (focused_window == win)
527 focused_window = (OpenboxWindow *) 0;
529 } else if ((slit = searchSlit(e->xdestroywindow.window))) {
530 slit->removeClient(e->xdestroywindow.window, False);
538 // strip the lock key modifiers
539 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
541 last_time = e->xmotion.time;
543 OpenboxWindow *win = (OpenboxWindow *) 0;
544 Basemenu *menu = (Basemenu *) 0;
546 if ((win = searchWindow(e->xmotion.window)))
547 win->motionNotifyEvent(&e->xmotion);
548 else if ((menu = searchMenu(e->xmotion.window)))
549 menu->motionNotifyEvent(&e->xmotion);
554 case PropertyNotify: {
555 last_time = e->xproperty.time;
557 if (e->xproperty.state != PropertyDelete) {
558 OpenboxWindow *win = searchWindow(e->xproperty.window);
561 win->propertyNotifyEvent(e->xproperty.atom);
568 last_time = e->xcrossing.time;
570 BScreen *screen = (BScreen *) 0;
571 OpenboxWindow *win = (OpenboxWindow *) 0;
572 Basemenu *menu = (Basemenu *) 0;
573 Toolbar *tbar = (Toolbar *) 0;
576 Slit *slit = (Slit *) 0;
579 if (e->xcrossing.mode == NotifyGrab) break;
583 sa.w = e->xcrossing.window;
584 sa.enter = sa.leave = False;
585 XCheckIfEvent(getXDisplay(), &dummy, queueScanner, (char *) &sa);
587 if ((e->xcrossing.window == e->xcrossing.root) &&
588 (screen = searchScreen(e->xcrossing.window))) {
589 screen->getImageControl()->installRootColormap();
590 } else if ((win = searchWindow(e->xcrossing.window))) {
591 if (win->getScreen()->sloppyFocus() &&
592 (! win->isFocused()) && (! no_focus)) {
595 if (((! sa.leave) || sa.inferior) && win->isVisible() &&
596 win->setInputFocus())
597 win->installColormap(True);
601 } else if ((menu = searchMenu(e->xcrossing.window))) {
602 menu->enterNotifyEvent(&e->xcrossing);
603 } else if ((tbar = searchToolbar(e->xcrossing.window))) {
604 tbar->enterNotifyEvent(&e->xcrossing);
606 } else if ((slit = searchSlit(e->xcrossing.window))) {
607 slit->enterNotifyEvent(&e->xcrossing);
614 last_time = e->xcrossing.time;
616 OpenboxWindow *win = (OpenboxWindow *) 0;
617 Basemenu *menu = (Basemenu *) 0;
618 Toolbar *tbar = (Toolbar *) 0;
621 Slit *slit = (Slit *) 0;
624 if ((menu = searchMenu(e->xcrossing.window)))
625 menu->leaveNotifyEvent(&e->xcrossing);
626 else if ((win = searchWindow(e->xcrossing.window)))
627 win->installColormap(False);
628 else if ((tbar = searchToolbar(e->xcrossing.window)))
629 tbar->leaveNotifyEvent(&e->xcrossing);
631 else if ((slit = searchSlit(e->xcrossing.window)))
632 slit->leaveNotifyEvent(&e->xcrossing);
639 OpenboxWindow *win = (OpenboxWindow *) 0;
640 Basemenu *menu = (Basemenu *) 0;
641 Toolbar *tbar = (Toolbar *) 0;
643 if ((win = searchWindow(e->xexpose.window)))
644 win->exposeEvent(&e->xexpose);
645 else if ((menu = searchMenu(e->xexpose.window)))
646 menu->exposeEvent(&e->xexpose);
647 else if ((tbar = searchToolbar(e->xexpose.window)))
648 tbar->exposeEvent(&e->xexpose);
654 Toolbar *tbar = searchToolbar(e->xkey.window);
656 if (tbar && tbar->isEditing())
657 tbar->keyPressEvent(&e->xkey);
662 case ColormapNotify: {
663 BScreen *screen = searchScreen(e->xcolormap.window);
666 screen->setRootColormapInstalled((e->xcolormap.state ==
667 ColormapInstalled) ? True : False);
673 if (e->xfocus.mode == NotifyUngrab || e->xfocus.detail == NotifyPointer)
676 OpenboxWindow *win = searchWindow(e->xfocus.window);
677 if (win && ! win->isFocused())
678 setFocusedWindow(win);
686 case ClientMessage: {
687 if (e->xclient.format == 32) {
688 if (e->xclient.message_type == getWMChangeStateAtom()) {
689 OpenboxWindow *win = searchWindow(e->xclient.window);
690 if (! win || ! win->validateClient()) return;
692 if (e->xclient.data.l[0] == IconicState)
694 if (e->xclient.data.l[0] == NormalState)
696 } else if (e->xclient.message_type == getOpenboxChangeWorkspaceAtom()) {
697 BScreen *screen = searchScreen(e->xclient.window);
699 if (screen && e->xclient.data.l[0] >= 0 &&
700 e->xclient.data.l[0] < screen->getWorkspaceCount())
701 screen->changeWorkspaceID(e->xclient.data.l[0]);
702 } else if (e->xclient.message_type == getOpenboxChangeWindowFocusAtom()) {
703 OpenboxWindow *win = searchWindow(e->xclient.window);
705 if (win && win->isVisible() && win->setInputFocus())
706 win->installColormap(True);
707 } else if (e->xclient.message_type == getOpenboxCycleWindowFocusAtom()) {
708 BScreen *screen = searchScreen(e->xclient.window);
711 if (! e->xclient.data.l[0])
716 } else if (e->xclient.message_type == getOpenboxChangeAttributesAtom()) {
717 OpenboxWindow *win = searchWindow(e->xclient.window);
719 if (win && win->validateClient()) {
721 net.flags = e->xclient.data.l[0];
722 net.attrib = e->xclient.data.l[1];
723 net.workspace = e->xclient.data.l[2];
724 net.stack = e->xclient.data.l[3];
725 net.decoration = e->xclient.data.l[4];
727 win->changeOpenboxHints(&net);
738 if (e->type == getShapeEventBase()) {
739 XShapeEvent *shape_event = (XShapeEvent *) e;
740 OpenboxWindow *win = (OpenboxWindow *) 0;
742 if ((win = searchWindow(e->xany.window)) ||
743 (shape_event->kind != ShapeBounding))
744 win->shapeEvent(shape_event);
753 Bool Openbox::handleSignal(int sig) {
779 BScreen *Openbox::searchScreen(Window window) {
780 LinkedListIterator<BScreen> it(screenList);
782 for (BScreen *curr = it.current(); curr; it++, curr = it.current()) {
783 if (curr->getRootWindow() == window) {
788 return (BScreen *) 0;
792 OpenboxWindow *Openbox::searchWindow(Window window) {
793 LinkedListIterator<WindowSearch> it(windowSearchList);
795 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
796 if (tmp->getWindow() == window) {
797 return tmp->getData();
801 return (OpenboxWindow *) 0;
805 OpenboxWindow *Openbox::searchGroup(Window window, OpenboxWindow *win) {
806 OpenboxWindow *w = (OpenboxWindow *) 0;
807 LinkedListIterator<WindowSearch> it(groupSearchList);
809 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
810 if (tmp->getWindow() == window) {
812 if (w->getClientWindow() != win->getClientWindow())
817 return (OpenboxWindow *) 0;
821 Basemenu *Openbox::searchMenu(Window window) {
822 LinkedListIterator<MenuSearch> it(menuSearchList);
824 for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
825 if (tmp->getWindow() == window)
826 return tmp->getData();
829 return (Basemenu *) 0;
833 Toolbar *Openbox::searchToolbar(Window window) {
834 LinkedListIterator<ToolbarSearch> it(toolbarSearchList);
836 for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
837 if (tmp->getWindow() == window)
838 return tmp->getData();
841 return (Toolbar *) 0;
846 Slit *Openbox::searchSlit(Window window) {
847 LinkedListIterator<SlitSearch> it(slitSearchList);
849 for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
850 if (tmp->getWindow() == window)
851 return tmp->getData();
859 void Openbox::saveWindowSearch(Window window, OpenboxWindow *data) {
860 windowSearchList->insert(new WindowSearch(window, data));
864 void Openbox::saveGroupSearch(Window window, OpenboxWindow *data) {
865 groupSearchList->insert(new WindowSearch(window, data));
869 void Openbox::saveMenuSearch(Window window, Basemenu *data) {
870 menuSearchList->insert(new MenuSearch(window, data));
874 void Openbox::saveToolbarSearch(Window window, Toolbar *data) {
875 toolbarSearchList->insert(new ToolbarSearch(window, data));
880 void Openbox::saveSlitSearch(Window window, Slit *data) {
881 slitSearchList->insert(new SlitSearch(window, data));
886 void Openbox::removeWindowSearch(Window window) {
887 LinkedListIterator<WindowSearch> it(windowSearchList);
888 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
889 if (tmp->getWindow() == window) {
890 windowSearchList->remove(tmp);
898 void Openbox::removeGroupSearch(Window window) {
899 LinkedListIterator<WindowSearch> it(groupSearchList);
900 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
901 if (tmp->getWindow() == window) {
902 groupSearchList->remove(tmp);
910 void Openbox::removeMenuSearch(Window window) {
911 LinkedListIterator<MenuSearch> it(menuSearchList);
912 for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
913 if (tmp->getWindow() == window) {
914 menuSearchList->remove(tmp);
922 void Openbox::removeToolbarSearch(Window window) {
923 LinkedListIterator<ToolbarSearch> it(toolbarSearchList);
924 for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
925 if (tmp->getWindow() == window) {
926 toolbarSearchList->remove(tmp);
935 void Openbox::removeSlitSearch(Window window) {
936 LinkedListIterator<SlitSearch> it(slitSearchList);
937 for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
938 if (tmp->getWindow() == window) {
939 slitSearchList->remove(tmp);
948 void Openbox::restart(const char *prog) {
952 execlp(prog, prog, NULL);
956 // fall back in case the above execlp doesn't work
957 execvp(argv[0], argv);
958 execvp(basename(argv[0]), argv);
962 void Openbox::shutdown() {
963 BaseDisplay::shutdown();
965 XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime);
967 LinkedListIterator<BScreen> it(screenList);
968 for (BScreen *s = it.current(); s; it++, s = it.current())
971 XSync(getXDisplay(), False);
975 void Openbox::save() {
976 config.setAutoSave(false);
978 // save all values as they are so that the defaults will be written to the rc
981 config.setValue("session.menuFile", getMenuFilename());
982 config.setValue("session.colorsPerChannel",
983 resource.colors_per_channel);
984 config.setValue("session.styleFile", resource.style_file);
985 config.setValue("session.titlebarLayout", resource.titlebar_layout);
986 config.setValue("session.doubleClickInterval",
987 (long)resource.double_click_interval);
988 config.setValue("session.autoRaiseDelay",
989 ((resource.auto_raise_delay.tv_sec * 1000) +
990 (resource.auto_raise_delay.tv_usec / 1000)));
991 config.setValue("session.cacheLife", (long)resource.cache_life / 60000);
992 config.setValue("session.cacheMax", (long)resource.cache_max);
994 LinkedListIterator<BScreen> it(screenList);
995 for (BScreen *s = it.current(); s != NULL; it++, s = it.current()) {
997 s->getToolbar()->save();
999 s->getSlit()->save();
1003 config.setAutoSave(true);
1007 void Openbox::load() {
1014 if (resource.menu_file)
1015 delete [] resource.menu_file;
1016 if (config.getValue("session.menuFile", "Session.MenuFile", s))
1017 resource.menu_file = bstrdup(s.c_str());
1019 resource.menu_file = bstrdup(DEFAULTMENU);
1021 if (config.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
1023 resource.colors_per_channel = (l < 2 ? 2 : (l > 6 ? 6 : l)); // >= 2, <= 6
1025 resource.colors_per_channel = 4;
1027 if (resource.style_file)
1028 delete [] resource.style_file;
1029 if (config.getValue("session.styleFile", "Session.StyleFile", s))
1030 resource.style_file = bstrdup(s.c_str());
1032 resource.style_file = bstrdup(DEFAULTSTYLE);
1034 if (resource.titlebar_layout)
1035 delete [] resource.titlebar_layout;
1036 if (config.getValue("session.titlebarLayout", "Session.TitlebarLayout", s))
1037 resource.titlebar_layout = bstrdup(s.c_str());
1039 resource.titlebar_layout = bstrdup("ILMC");
1041 if (config.getValue("session.doubleClickInterval",
1042 "Session.DoubleClickInterval", l))
1043 resource.double_click_interval = l;
1045 resource.double_click_interval = 250;
1047 if (!config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l))
1048 resource.auto_raise_delay.tv_usec = l;
1050 resource.auto_raise_delay.tv_usec = 400;
1051 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000;
1052 resource.auto_raise_delay.tv_usec -=
1053 (resource.auto_raise_delay.tv_sec * 1000);
1054 resource.auto_raise_delay.tv_usec *= 1000;
1056 if (config.getValue("session.cacheLife", "Session.CacheLife", l))
1057 resource.cache_life = l;
1059 resource.cache_life = 51;
1060 resource.cache_life *= 60000;
1062 if (config.getValue("session.cacheMax", "Session.CacheMax", l))
1063 resource.cache_max = l;
1065 resource.cache_max = 200;
1069 void Openbox::reconfigure() {
1070 reconfigure_wait = True;
1072 if (! timer->isTiming()) timer->start();
1076 void Openbox::real_reconfigure() {
1081 for (int i = 0, n = menuTimestamps->count(); i < n; i++) {
1082 MenuTimestamp *ts = menuTimestamps->remove(0);
1086 delete [] ts->filename;
1092 LinkedListIterator<BScreen> it(screenList);
1093 for (BScreen *screen = it.current(); screen; it++, screen = it.current()) {
1094 screen->reconfigure();
1101 void Openbox::checkMenu() {
1102 Bool reread = False;
1103 LinkedListIterator<MenuTimestamp> it(menuTimestamps);
1104 for (MenuTimestamp *tmp = it.current(); tmp && (! reread);
1105 it++, tmp = it.current()) {
1108 if (! stat(tmp->filename, &buf)) {
1109 if (tmp->timestamp != buf.st_ctime)
1116 if (reread) rereadMenu();
1120 void Openbox::rereadMenu() {
1121 reread_menu_wait = True;
1123 if (! timer->isTiming()) timer->start();
1127 void Openbox::real_rereadMenu() {
1128 for (int i = 0, n = menuTimestamps->count(); i < n; i++) {
1129 MenuTimestamp *ts = menuTimestamps->remove(0);
1133 delete [] ts->filename;
1139 LinkedListIterator<BScreen> it(screenList);
1140 for (BScreen *screen = it.current(); screen; it++, screen = it.current())
1141 screen->rereadMenu();
1145 void Openbox::setStyleFilename(const char *filename) {
1146 if (resource.style_file)
1147 delete [] resource.style_file;
1149 resource.style_file = bstrdup(filename);
1150 config.setValue("session.styleFile", resource.style_file);
1154 void Openbox::setMenuFilename(const char *filename) {
1157 LinkedListIterator<MenuTimestamp> it(menuTimestamps);
1158 for (MenuTimestamp *tmp = it.current(); tmp && (! found);
1159 it++, tmp = it.current()) {
1160 if (! strcmp(tmp->filename, filename)) found = True;
1165 if (! stat(filename, &buf)) {
1166 MenuTimestamp *ts = new MenuTimestamp;
1168 ts->filename = bstrdup(filename);
1169 ts->timestamp = buf.st_ctime;
1171 menuTimestamps->insert(ts);
1177 void Openbox::timeout() {
1178 if (reconfigure_wait)
1181 if (reread_menu_wait)
1184 reconfigure_wait = reread_menu_wait = False;
1188 void Openbox::setFocusedWindow(OpenboxWindow *win) {
1189 BScreen *old_screen = (BScreen *) 0, *screen = (BScreen *) 0;
1190 OpenboxWindow *old_win = (OpenboxWindow *) 0;
1191 Toolbar *old_tbar = (Toolbar *) 0, *tbar = (Toolbar *) 0;
1192 Workspace *old_wkspc = (Workspace *) 0, *wkspc = (Workspace *) 0;
1194 if (focused_window) {
1195 old_win = focused_window;
1196 old_screen = old_win->getScreen();
1197 old_tbar = old_screen->getToolbar();
1198 old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber());
1200 old_win->setFocusFlag(False);
1201 old_wkspc->getMenu()->setItemSelected(old_win->getWindowNumber(), False);
1204 if (win && ! win->isIconic()) {
1205 screen = win->getScreen();
1206 tbar = screen->getToolbar();
1207 wkspc = screen->getWorkspace(win->getWorkspaceNumber());
1209 focused_window = win;
1211 win->setFocusFlag(True);
1212 wkspc->getMenu()->setItemSelected(win->getWindowNumber(), True);
1214 focused_window = (OpenboxWindow *) 0;
1218 tbar->redrawWindowLabel(True);
1220 screen->updateNetizenWindowFocus();
1222 if (old_tbar && old_tbar != tbar)
1223 old_tbar->redrawWindowLabel(True);
1224 if (old_screen && old_screen != screen)
1225 old_screen->updateNetizenWindowFocus();