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 = (char *) 0;
186 resource.titlebar_layout = (char *) NULL;
187 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0;
189 focused_window = masked_window = (OpenboxWindow *) 0;
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;
267 delete menuTimestamps;
269 delete windowSearchList;
270 delete menuSearchList;
271 delete toolbarSearchList;
272 delete groupSearchList;
277 delete slitSearchList;
282 void Openbox::process_event(XEvent *e) {
283 if ((masked == e->xany.window) && masked_window &&
284 (e->type == MotionNotify)) {
285 last_time = e->xmotion.time;
286 masked_window->motionNotifyEvent(&e->xmotion);
293 // strip the lock key modifiers
294 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
296 last_time = e->xbutton.time;
298 OpenboxWindow *win = (OpenboxWindow *) 0;
299 Basemenu *menu = (Basemenu *) 0;
302 Slit *slit = (Slit *) 0;
305 Toolbar *tbar = (Toolbar *) 0;
307 if ((win = searchWindow(e->xbutton.window))) {
308 win->buttonPressEvent(&e->xbutton);
310 if (e->xbutton.button == 1)
311 win->installColormap(True);
312 } else if ((menu = searchMenu(e->xbutton.window))) {
313 menu->buttonPressEvent(&e->xbutton);
316 } else if ((slit = searchSlit(e->xbutton.window))) {
317 slit->buttonPressEvent(&e->xbutton);
320 } else if ((tbar = searchToolbar(e->xbutton.window))) {
321 tbar->buttonPressEvent(&e->xbutton);
323 LinkedListIterator<BScreen> it(screenList);
324 BScreen *screen = it.current();
325 for (; screen; it++, screen = it.current()) {
326 if (e->xbutton.window == screen->getRootWindow()) {
327 if (e->xbutton.button == 1) {
328 if (! screen->isRootColormapInstalled())
329 screen->getImageControl()->installRootColormap();
331 if (screen->getWorkspacemenu()->isVisible())
332 screen->getWorkspacemenu()->hide();
334 if (screen->getRootmenu()->isVisible())
335 screen->getRootmenu()->hide();
336 } else if (e->xbutton.button == 2) {
337 int mx = e->xbutton.x_root -
338 (screen->getWorkspacemenu()->getWidth() / 2);
339 int my = e->xbutton.y_root -
340 (screen->getWorkspacemenu()->getTitleHeight() / 2);
345 if (mx + screen->getWorkspacemenu()->getWidth() >
347 mx = screen->size().w() -
348 screen->getWorkspacemenu()->getWidth() -
349 screen->getBorderWidth();
351 if (my + screen->getWorkspacemenu()->getHeight() >
353 my = screen->size().h() -
354 screen->getWorkspacemenu()->getHeight() -
355 screen->getBorderWidth();
357 screen->getWorkspacemenu()->move(mx, my);
359 if (! screen->getWorkspacemenu()->isVisible()) {
360 screen->getWorkspacemenu()->removeParent();
361 screen->getWorkspacemenu()->show();
363 } else if (e->xbutton.button == 3) {
364 int mx = e->xbutton.x_root -
365 (screen->getRootmenu()->getWidth() / 2);
366 int my = e->xbutton.y_root -
367 (screen->getRootmenu()->getTitleHeight() / 2);
372 if (mx + screen->getRootmenu()->getWidth() > screen->size().w())
373 mx = screen->size().w() -
374 screen->getRootmenu()->getWidth() -
375 screen->getBorderWidth();
377 if (my + screen->getRootmenu()->getHeight() > screen->size().h())
378 my = screen->size().h() -
379 screen->getRootmenu()->getHeight() -
380 screen->getBorderWidth();
382 screen->getRootmenu()->move(mx, my);
384 if (! screen->getRootmenu()->isVisible()) {
386 screen->getRootmenu()->show();
388 } else if (e->xbutton.button == 4) {
389 if ((screen->getCurrentWorkspaceID() + 1) >
390 screen->getWorkspaceCount() - 1)
391 screen->changeWorkspaceID(0);
393 screen->changeWorkspaceID(screen->getCurrentWorkspaceID() + 1);
394 } else if (e->xbutton.button == 5) {
395 if ((screen->getCurrentWorkspaceID() - 1) < 0)
396 screen->changeWorkspaceID(screen->getWorkspaceCount() - 1);
398 screen->changeWorkspaceID(screen->getCurrentWorkspaceID() - 1);
407 case ButtonRelease: {
408 // strip the lock key modifiers
409 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
411 last_time = e->xbutton.time;
413 OpenboxWindow *win = (OpenboxWindow *) 0;
414 Basemenu *menu = (Basemenu *) 0;
415 Toolbar *tbar = (Toolbar *) 0;
417 if ((win = searchWindow(e->xbutton.window)))
418 win->buttonReleaseEvent(&e->xbutton);
419 else if ((menu = searchMenu(e->xbutton.window)))
420 menu->buttonReleaseEvent(&e->xbutton);
421 else if ((tbar = searchToolbar(e->xbutton.window)))
422 tbar->buttonReleaseEvent(&e->xbutton);
427 case ConfigureRequest: {
428 OpenboxWindow *win = (OpenboxWindow *) 0;
431 Slit *slit = (Slit *) 0;
434 if ((win = searchWindow(e->xconfigurerequest.window))) {
435 win->configureRequestEvent(&e->xconfigurerequest);
438 } else if ((slit = searchSlit(e->xconfigurerequest.window))) {
439 slit->configureRequestEvent(&e->xconfigurerequest);
445 if (validateWindow(e->xconfigurerequest.window)) {
448 xwc.x = e->xconfigurerequest.x;
449 xwc.y = e->xconfigurerequest.y;
450 xwc.width = e->xconfigurerequest.width;
451 xwc.height = e->xconfigurerequest.height;
452 xwc.border_width = e->xconfigurerequest.border_width;
453 xwc.sibling = e->xconfigurerequest.above;
454 xwc.stack_mode = e->xconfigurerequest.detail;
456 XConfigureWindow(getXDisplay(), e->xconfigurerequest.window,
457 e->xconfigurerequest.value_mask, &xwc);
469 i18n->getMessage(openboxSet, openboxMapRequest,
470 "Openbox::process_event(): MapRequest for 0x%lx\n"),
471 e->xmaprequest.window);
474 OpenboxWindow *win = searchWindow(e->xmaprequest.window);
477 win = new OpenboxWindow(*this, e->xmaprequest.window);
479 if ((win = searchWindow(e->xmaprequest.window)))
480 win->mapRequestEvent(&e->xmaprequest);
486 OpenboxWindow *win = searchWindow(e->xmap.window);
489 win->mapNotifyEvent(&e->xmap);
495 OpenboxWindow *win = (OpenboxWindow *) 0;
498 Slit *slit = (Slit *) 0;
501 if ((win = searchWindow(e->xunmap.window))) {
502 win->unmapNotifyEvent(&e->xunmap);
503 if (focused_window == win)
504 focused_window = (OpenboxWindow *) 0;
506 } else if ((slit = searchSlit(e->xunmap.window))) {
507 slit->removeClient(e->xunmap.window);
515 case DestroyNotify: {
516 OpenboxWindow *win = (OpenboxWindow *) 0;
519 Slit *slit = (Slit *) 0;
522 if ((win = searchWindow(e->xdestroywindow.window))) {
523 win->destroyNotifyEvent(&e->xdestroywindow);
524 if (focused_window == win)
525 focused_window = (OpenboxWindow *) 0;
527 } else if ((slit = searchSlit(e->xdestroywindow.window))) {
528 slit->removeClient(e->xdestroywindow.window, False);
536 // strip the lock key modifiers
537 e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
539 last_time = e->xmotion.time;
541 OpenboxWindow *win = (OpenboxWindow *) 0;
542 Basemenu *menu = (Basemenu *) 0;
544 if ((win = searchWindow(e->xmotion.window)))
545 win->motionNotifyEvent(&e->xmotion);
546 else if ((menu = searchMenu(e->xmotion.window)))
547 menu->motionNotifyEvent(&e->xmotion);
552 case PropertyNotify: {
553 last_time = e->xproperty.time;
555 if (e->xproperty.state != PropertyDelete) {
556 OpenboxWindow *win = searchWindow(e->xproperty.window);
559 win->propertyNotifyEvent(e->xproperty.atom);
566 last_time = e->xcrossing.time;
568 BScreen *screen = (BScreen *) 0;
569 OpenboxWindow *win = (OpenboxWindow *) 0;
570 Basemenu *menu = (Basemenu *) 0;
571 Toolbar *tbar = (Toolbar *) 0;
574 Slit *slit = (Slit *) 0;
577 if (e->xcrossing.mode == NotifyGrab) break;
581 sa.w = e->xcrossing.window;
582 sa.enter = sa.leave = False;
583 XCheckIfEvent(getXDisplay(), &dummy, queueScanner, (char *) &sa);
585 if ((e->xcrossing.window == e->xcrossing.root) &&
586 (screen = searchScreen(e->xcrossing.window))) {
587 screen->getImageControl()->installRootColormap();
588 } else if ((win = searchWindow(e->xcrossing.window))) {
589 if (win->getScreen()->sloppyFocus() &&
590 (! win->isFocused()) && (! no_focus)) {
593 if (((! sa.leave) || sa.inferior) && win->isVisible() &&
594 win->setInputFocus())
595 win->installColormap(True);
599 } else if ((menu = searchMenu(e->xcrossing.window))) {
600 menu->enterNotifyEvent(&e->xcrossing);
601 } else if ((tbar = searchToolbar(e->xcrossing.window))) {
602 tbar->enterNotifyEvent(&e->xcrossing);
604 } else if ((slit = searchSlit(e->xcrossing.window))) {
605 slit->enterNotifyEvent(&e->xcrossing);
612 last_time = e->xcrossing.time;
614 OpenboxWindow *win = (OpenboxWindow *) 0;
615 Basemenu *menu = (Basemenu *) 0;
616 Toolbar *tbar = (Toolbar *) 0;
619 Slit *slit = (Slit *) 0;
622 if ((menu = searchMenu(e->xcrossing.window)))
623 menu->leaveNotifyEvent(&e->xcrossing);
624 else if ((win = searchWindow(e->xcrossing.window)))
625 win->installColormap(False);
626 else if ((tbar = searchToolbar(e->xcrossing.window)))
627 tbar->leaveNotifyEvent(&e->xcrossing);
629 else if ((slit = searchSlit(e->xcrossing.window)))
630 slit->leaveNotifyEvent(&e->xcrossing);
637 OpenboxWindow *win = (OpenboxWindow *) 0;
638 Basemenu *menu = (Basemenu *) 0;
639 Toolbar *tbar = (Toolbar *) 0;
641 if ((win = searchWindow(e->xexpose.window)))
642 win->exposeEvent(&e->xexpose);
643 else if ((menu = searchMenu(e->xexpose.window)))
644 menu->exposeEvent(&e->xexpose);
645 else if ((tbar = searchToolbar(e->xexpose.window)))
646 tbar->exposeEvent(&e->xexpose);
652 Toolbar *tbar = searchToolbar(e->xkey.window);
654 if (tbar && tbar->isEditing())
655 tbar->keyPressEvent(&e->xkey);
660 case ColormapNotify: {
661 BScreen *screen = searchScreen(e->xcolormap.window);
664 screen->setRootColormapInstalled((e->xcolormap.state ==
665 ColormapInstalled) ? True : False);
671 if (e->xfocus.mode == NotifyUngrab || e->xfocus.detail == NotifyPointer)
674 OpenboxWindow *win = searchWindow(e->xfocus.window);
675 if (win && ! win->isFocused())
676 setFocusedWindow(win);
684 case ClientMessage: {
685 if (e->xclient.format == 32) {
686 if (e->xclient.message_type == getWMChangeStateAtom()) {
687 OpenboxWindow *win = searchWindow(e->xclient.window);
688 if (! win || ! win->validateClient()) return;
690 if (e->xclient.data.l[0] == IconicState)
692 if (e->xclient.data.l[0] == NormalState)
694 } else if (e->xclient.message_type == getOpenboxChangeWorkspaceAtom()) {
695 BScreen *screen = searchScreen(e->xclient.window);
697 if (screen && e->xclient.data.l[0] >= 0 &&
698 e->xclient.data.l[0] < screen->getWorkspaceCount())
699 screen->changeWorkspaceID(e->xclient.data.l[0]);
700 } else if (e->xclient.message_type == getOpenboxChangeWindowFocusAtom()) {
701 OpenboxWindow *win = searchWindow(e->xclient.window);
703 if (win && win->isVisible() && win->setInputFocus())
704 win->installColormap(True);
705 } else if (e->xclient.message_type == getOpenboxCycleWindowFocusAtom()) {
706 BScreen *screen = searchScreen(e->xclient.window);
709 if (! e->xclient.data.l[0])
714 } else if (e->xclient.message_type == getOpenboxChangeAttributesAtom()) {
715 OpenboxWindow *win = searchWindow(e->xclient.window);
717 if (win && win->validateClient()) {
719 net.flags = e->xclient.data.l[0];
720 net.attrib = e->xclient.data.l[1];
721 net.workspace = e->xclient.data.l[2];
722 net.stack = e->xclient.data.l[3];
723 net.decoration = e->xclient.data.l[4];
725 win->changeOpenboxHints(&net);
736 if (e->type == getShapeEventBase()) {
737 XShapeEvent *shape_event = (XShapeEvent *) e;
738 OpenboxWindow *win = (OpenboxWindow *) 0;
740 if ((win = searchWindow(e->xany.window)) ||
741 (shape_event->kind != ShapeBounding))
742 win->shapeEvent(shape_event);
751 Bool Openbox::handleSignal(int sig) {
777 BScreen *Openbox::searchScreen(Window window) {
778 LinkedListIterator<BScreen> it(screenList);
780 for (BScreen *curr = it.current(); curr; it++, curr = it.current()) {
781 if (curr->getRootWindow() == window) {
786 return (BScreen *) 0;
790 OpenboxWindow *Openbox::searchWindow(Window window) {
791 LinkedListIterator<WindowSearch> it(windowSearchList);
793 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
794 if (tmp->getWindow() == window) {
795 return tmp->getData();
799 return (OpenboxWindow *) 0;
803 OpenboxWindow *Openbox::searchGroup(Window window, OpenboxWindow *win) {
804 OpenboxWindow *w = (OpenboxWindow *) 0;
805 LinkedListIterator<WindowSearch> it(groupSearchList);
807 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
808 if (tmp->getWindow() == window) {
810 if (w->getClientWindow() != win->getClientWindow())
815 return (OpenboxWindow *) 0;
819 Basemenu *Openbox::searchMenu(Window window) {
820 LinkedListIterator<MenuSearch> it(menuSearchList);
822 for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
823 if (tmp->getWindow() == window)
824 return tmp->getData();
827 return (Basemenu *) 0;
831 Toolbar *Openbox::searchToolbar(Window window) {
832 LinkedListIterator<ToolbarSearch> it(toolbarSearchList);
834 for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
835 if (tmp->getWindow() == window)
836 return tmp->getData();
839 return (Toolbar *) 0;
844 Slit *Openbox::searchSlit(Window window) {
845 LinkedListIterator<SlitSearch> it(slitSearchList);
847 for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
848 if (tmp->getWindow() == window)
849 return tmp->getData();
857 void Openbox::saveWindowSearch(Window window, OpenboxWindow *data) {
858 windowSearchList->insert(new WindowSearch(window, data));
862 void Openbox::saveGroupSearch(Window window, OpenboxWindow *data) {
863 groupSearchList->insert(new WindowSearch(window, data));
867 void Openbox::saveMenuSearch(Window window, Basemenu *data) {
868 menuSearchList->insert(new MenuSearch(window, data));
872 void Openbox::saveToolbarSearch(Window window, Toolbar *data) {
873 toolbarSearchList->insert(new ToolbarSearch(window, data));
878 void Openbox::saveSlitSearch(Window window, Slit *data) {
879 slitSearchList->insert(new SlitSearch(window, data));
884 void Openbox::removeWindowSearch(Window window) {
885 LinkedListIterator<WindowSearch> it(windowSearchList);
886 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
887 if (tmp->getWindow() == window) {
888 windowSearchList->remove(tmp);
896 void Openbox::removeGroupSearch(Window window) {
897 LinkedListIterator<WindowSearch> it(groupSearchList);
898 for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
899 if (tmp->getWindow() == window) {
900 groupSearchList->remove(tmp);
908 void Openbox::removeMenuSearch(Window window) {
909 LinkedListIterator<MenuSearch> it(menuSearchList);
910 for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
911 if (tmp->getWindow() == window) {
912 menuSearchList->remove(tmp);
920 void Openbox::removeToolbarSearch(Window window) {
921 LinkedListIterator<ToolbarSearch> it(toolbarSearchList);
922 for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
923 if (tmp->getWindow() == window) {
924 toolbarSearchList->remove(tmp);
933 void Openbox::removeSlitSearch(Window window) {
934 LinkedListIterator<SlitSearch> it(slitSearchList);
935 for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) {
936 if (tmp->getWindow() == window) {
937 slitSearchList->remove(tmp);
946 void Openbox::restart(const char *prog) {
950 execlp(prog, prog, NULL);
954 // fall back in case the above execlp doesn't work
955 execvp(argv[0], argv);
956 execvp(basename(argv[0]), argv);
960 void Openbox::shutdown() {
961 BaseDisplay::shutdown();
963 XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime);
965 LinkedListIterator<BScreen> it(screenList);
966 for (BScreen *s = it.current(); s; it++, s = it.current())
969 XSync(getXDisplay(), False);
973 void Openbox::save() {
974 config.setAutoSave(false);
976 // save all values as they are so that the defaults will be written to the rc
979 config.setValue("session.menuFile", getMenuFilename());
980 config.setValue("session.colorsPerChannel",
981 resource.colors_per_channel);
982 config.setValue("session.doubleClickInterval",
983 (long)resource.double_click_interval);
984 config.setValue("session.autoRaiseDelay",
985 ((resource.auto_raise_delay.tv_sec * 1000) +
986 (resource.auto_raise_delay.tv_usec / 1000)));
987 config.setValue("session.cacheLife", (long)resource.cache_life / 60000);
988 config.setValue("session.cacheMax", (long)resource.cache_max);
989 config.setValue("session.styleFile", resource.style_file);
991 LinkedListIterator<BScreen> it(screenList);
992 for (BScreen *s = it.current(); s != NULL; it++, s = it.current()) {
994 s->getToolbar()->save();
995 s->getSlit()->save();
998 config.setAutoSave(true);
1002 void Openbox::load() {
1009 if (resource.menu_file)
1010 delete [] resource.menu_file;
1011 if (config.getValue("session.menuFile", "Session.MenuFile", s))
1012 resource.menu_file = bstrdup(s.c_str());
1014 resource.menu_file = bstrdup(DEFAULTMENU);
1016 if (config.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
1018 resource.colors_per_channel = (l < 2 ? 2 : (l > 6 ? 6 : l)); // >= 2, <= 6
1020 resource.colors_per_channel = 4;
1022 if (resource.style_file)
1023 delete [] resource.style_file;
1024 if (config.getValue("session.styleFile", "Session.StyleFile", s))
1025 resource.style_file = bstrdup(s.c_str());
1027 resource.style_file = bstrdup(DEFAULTSTYLE);
1029 if (resource.titlebar_layout)
1030 delete [] resource.titlebar_layout;
1031 if (config.getValue("session.titlebarLayout", "Session.TitlebarLayout", s))
1032 resource.titlebar_layout = bstrdup(s.c_str());
1034 resource.titlebar_layout = bstrdup("ILMC");
1036 if (config.getValue("session.doubleClickInterval",
1037 "Session.DoubleClickInterval", l))
1038 resource.double_click_interval = l;
1040 resource.double_click_interval = 250;
1042 if (!config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l))
1043 resource.auto_raise_delay.tv_usec = l;
1045 resource.auto_raise_delay.tv_usec = 400;
1046 resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000;
1047 resource.auto_raise_delay.tv_usec -=
1048 (resource.auto_raise_delay.tv_sec * 1000);
1049 resource.auto_raise_delay.tv_usec *= 1000;
1051 if (config.getValue("session.cacheLife", "Session.CacheLife", l))
1052 resource.cache_life = l;
1054 resource.cache_life = 51;
1055 resource.cache_life *= 60000;
1057 if (config.getValue("session.cacheMax", "Session.CacheMax", l))
1058 resource.cache_max = l;
1060 resource.cache_max = 200;
1064 void Openbox::reconfigure() {
1065 reconfigure_wait = True;
1067 if (! timer->isTiming()) timer->start();
1071 void Openbox::real_reconfigure() {
1076 for (int i = 0, n = menuTimestamps->count(); i < n; i++) {
1077 MenuTimestamp *ts = menuTimestamps->remove(0);
1081 delete [] ts->filename;
1087 LinkedListIterator<BScreen> it(screenList);
1088 for (BScreen *screen = it.current(); screen; it++, screen = it.current()) {
1089 screen->reconfigure();
1096 void Openbox::checkMenu() {
1097 Bool reread = False;
1098 LinkedListIterator<MenuTimestamp> it(menuTimestamps);
1099 for (MenuTimestamp *tmp = it.current(); tmp && (! reread);
1100 it++, tmp = it.current()) {
1103 if (! stat(tmp->filename, &buf)) {
1104 if (tmp->timestamp != buf.st_ctime)
1111 if (reread) rereadMenu();
1115 void Openbox::rereadMenu() {
1116 reread_menu_wait = True;
1118 if (! timer->isTiming()) timer->start();
1122 void Openbox::real_rereadMenu() {
1123 for (int i = 0, n = menuTimestamps->count(); i < n; i++) {
1124 MenuTimestamp *ts = menuTimestamps->remove(0);
1128 delete [] ts->filename;
1134 LinkedListIterator<BScreen> it(screenList);
1135 for (BScreen *screen = it.current(); screen; it++, screen = it.current())
1136 screen->rereadMenu();
1140 void Openbox::setStyleFilename(const char *filename) {
1141 if (resource.style_file)
1142 delete [] resource.style_file;
1144 resource.style_file = bstrdup(filename);
1145 config.setValue("session.styleFile", resource.style_file);
1149 void Openbox::setMenuFilename(const char *filename) {
1152 LinkedListIterator<MenuTimestamp> it(menuTimestamps);
1153 for (MenuTimestamp *tmp = it.current(); tmp && (! found);
1154 it++, tmp = it.current()) {
1155 if (! strcmp(tmp->filename, filename)) found = True;
1160 if (! stat(filename, &buf)) {
1161 MenuTimestamp *ts = new MenuTimestamp;
1163 ts->filename = bstrdup(filename);
1164 ts->timestamp = buf.st_ctime;
1166 menuTimestamps->insert(ts);
1172 void Openbox::timeout() {
1173 if (reconfigure_wait)
1176 if (reread_menu_wait)
1179 reconfigure_wait = reread_menu_wait = False;
1183 void Openbox::setFocusedWindow(OpenboxWindow *win) {
1184 BScreen *old_screen = (BScreen *) 0, *screen = (BScreen *) 0;
1185 OpenboxWindow *old_win = (OpenboxWindow *) 0;
1186 Toolbar *old_tbar = (Toolbar *) 0, *tbar = (Toolbar *) 0;
1187 Workspace *old_wkspc = (Workspace *) 0, *wkspc = (Workspace *) 0;
1189 if (focused_window) {
1190 old_win = focused_window;
1191 old_screen = old_win->getScreen();
1192 old_tbar = old_screen->getToolbar();
1193 old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber());
1195 old_win->setFocusFlag(False);
1196 old_wkspc->getMenu()->setItemSelected(old_win->getWindowNumber(), False);
1199 if (win && ! win->isIconic()) {
1200 screen = win->getScreen();
1201 tbar = screen->getToolbar();
1202 wkspc = screen->getWorkspace(win->getWorkspaceNumber());
1204 focused_window = win;
1206 win->setFocusFlag(True);
1207 wkspc->getMenu()->setItemSelected(win->getWindowNumber(), True);
1209 focused_window = (OpenboxWindow *) 0;
1213 tbar->redrawWindowLabel(True);
1215 screen->updateNetizenWindowFocus();
1217 if (old_tbar && old_tbar != tbar)
1218 old_tbar->redrawWindowLabel(True);
1219 if (old_screen && old_screen != screen)
1220 old_screen->updateNetizenWindowFocus();