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 masked_window
= NULL
;
195 openbox_pid
= XInternAtom(getXDisplay(), "_BLACKBOX_PID", False
);
196 #endif // HAVE_GETPID
198 for (int i
= 0; i
< getNumberOfScreens(); i
++) {
199 BScreen
*screen
= new BScreen(*this, i
, config
);
201 if (! screen
->isScreenManaged()) {
206 screenList
.push_back(screen
);
209 if (screenList
.empty()) {
211 i18n
->getMessage(openboxSet
, openboxNoManagableScreens
,
212 "Openbox::Openbox: no managable screens found, aborting.\n"));
215 focused_screen
= screenList
.front();
217 // save current settings and default values
220 XSynchronize(getXDisplay(), False
);
221 XSync(getXDisplay(), False
);
223 reconfigure_wait
= reread_menu_wait
= False
;
225 timer
= new BTimer(*this, *this);
226 timer
->setTimeout(0);
227 timer
->fireOnce(True
);
231 focusWindow((OpenboxWindow
*) 0);
235 Openbox::~Openbox() {
236 for_each(screenList
.begin(), screenList
.end(),
239 for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
242 if (resource
.menu_file
)
243 delete [] resource
.menu_file
;
245 if (resource
.style_file
)
246 delete [] resource
.style_file
;
248 if (resource
.titlebar_layout
)
249 delete [] resource
.titlebar_layout
;
257 void Openbox::process_event(XEvent
*e
) {
258 if ((masked
== e
->xany
.window
&& masked_window
) &&
259 (e
->type
== MotionNotify
)) {
260 last_time
= e
->xmotion
.time
;
261 masked_window
->motionNotifyEvent(&e
->xmotion
);
267 // strip the lock key modifiers
268 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
270 last_time
= e
->xbutton
.time
;
272 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
273 Basemenu
*menu
= (Basemenu
*) 0;
276 Slit
*slit
= (Slit
*) 0;
279 Toolbar
*tbar
= (Toolbar
*) 0;
281 if ((win
= searchWindow(e
->xbutton
.window
))) {
282 win
->buttonPressEvent(&e
->xbutton
);
284 if (e
->xbutton
.button
== 1)
285 win
->installColormap(True
);
286 } else if ((menu
= searchMenu(e
->xbutton
.window
))) {
287 menu
->buttonPressEvent(&e
->xbutton
);
290 } else if ((slit
= searchSlit(e
->xbutton
.window
))) {
291 slit
->buttonPressEvent(&e
->xbutton
);
294 } else if ((tbar
= searchToolbar(e
->xbutton
.window
))) {
295 tbar
->buttonPressEvent(&e
->xbutton
);
297 ScreenList::iterator it
;
298 for (it
= screenList
.begin(); it
!= screenList
.end(); ++it
) {
299 BScreen
*screen
= *it
;
300 if (e
->xbutton
.window
== screen
->getRootWindow()) {
301 if (e
->xbutton
.button
== 1) {
302 if (! screen
->isRootColormapInstalled())
303 screen
->getImageControl()->installRootColormap();
305 if (screen
->getWorkspacemenu()->isVisible())
306 screen
->getWorkspacemenu()->hide();
308 if (screen
->getRootmenu()->isVisible())
309 screen
->getRootmenu()->hide();
310 } else if (e
->xbutton
.button
== 2) {
311 int mx
= e
->xbutton
.x_root
-
312 (screen
->getWorkspacemenu()->getWidth() / 2);
313 int my
= e
->xbutton
.y_root
-
314 (screen
->getWorkspacemenu()->getTitleHeight() / 2);
319 if (mx
+ screen
->getWorkspacemenu()->getWidth() >
321 mx
= screen
->size().w() -
322 screen
->getWorkspacemenu()->getWidth() -
323 screen
->getBorderWidth();
325 if (my
+ screen
->getWorkspacemenu()->getHeight() >
327 my
= screen
->size().h() -
328 screen
->getWorkspacemenu()->getHeight() -
329 screen
->getBorderWidth();
331 screen
->getWorkspacemenu()->move(mx
, my
);
333 if (! screen
->getWorkspacemenu()->isVisible()) {
334 screen
->getWorkspacemenu()->removeParent();
335 screen
->getWorkspacemenu()->show();
337 } else if (e
->xbutton
.button
== 3) {
338 int mx
= e
->xbutton
.x_root
-
339 (screen
->getRootmenu()->getWidth() / 2);
340 int my
= e
->xbutton
.y_root
-
341 (screen
->getRootmenu()->getTitleHeight() / 2);
346 if (mx
+ screen
->getRootmenu()->getWidth() > screen
->size().w())
347 mx
= screen
->size().w() -
348 screen
->getRootmenu()->getWidth() -
349 screen
->getBorderWidth();
351 if (my
+ screen
->getRootmenu()->getHeight() > screen
->size().h())
352 my
= screen
->size().h() -
353 screen
->getRootmenu()->getHeight() -
354 screen
->getBorderWidth();
356 screen
->getRootmenu()->move(mx
, my
);
358 if (! screen
->getRootmenu()->isVisible()) {
360 screen
->getRootmenu()->show();
362 } else if (e
->xbutton
.button
== 4) {
363 if ((screen
->getCurrentWorkspaceID() + 1) >
364 screen
->getWorkspaceCount() - 1)
365 screen
->changeWorkspaceID(0);
367 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() + 1);
368 } else if (e
->xbutton
.button
== 5) {
369 if ((screen
->getCurrentWorkspaceID() - 1) < 0)
370 screen
->changeWorkspaceID(screen
->getWorkspaceCount() - 1);
372 screen
->changeWorkspaceID(screen
->getCurrentWorkspaceID() - 1);
381 case ButtonRelease
: {
382 // strip the lock key modifiers
383 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
385 last_time
= e
->xbutton
.time
;
387 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
388 Basemenu
*menu
= (Basemenu
*) 0;
389 Toolbar
*tbar
= (Toolbar
*) 0;
391 if ((win
= searchWindow(e
->xbutton
.window
)))
392 win
->buttonReleaseEvent(&e
->xbutton
);
393 else if ((menu
= searchMenu(e
->xbutton
.window
)))
394 menu
->buttonReleaseEvent(&e
->xbutton
);
395 else if ((tbar
= searchToolbar(e
->xbutton
.window
)))
396 tbar
->buttonReleaseEvent(&e
->xbutton
);
401 case ConfigureRequest
: {
402 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
405 Slit
*slit
= (Slit
*) 0;
408 if ((win
= searchWindow(e
->xconfigurerequest
.window
))) {
409 win
->configureRequestEvent(&e
->xconfigurerequest
);
412 } else if ((slit
= searchSlit(e
->xconfigurerequest
.window
))) {
413 slit
->configureRequestEvent(&e
->xconfigurerequest
);
419 if (validateWindow(e
->xconfigurerequest
.window
)) {
422 xwc
.x
= e
->xconfigurerequest
.x
;
423 xwc
.y
= e
->xconfigurerequest
.y
;
424 xwc
.width
= e
->xconfigurerequest
.width
;
425 xwc
.height
= e
->xconfigurerequest
.height
;
426 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
427 xwc
.sibling
= e
->xconfigurerequest
.above
;
428 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
430 XConfigureWindow(getXDisplay(), e
->xconfigurerequest
.window
,
431 e
->xconfigurerequest
.value_mask
, &xwc
);
443 i18n
->getMessage(openboxSet
, openboxMapRequest
,
444 "Openbox::process_event(): MapRequest for 0x%lx\n"),
445 e
->xmaprequest
.window
);
448 OpenboxWindow
*win
= searchWindow(e
->xmaprequest
.window
);
451 win
= new OpenboxWindow(*this, e
->xmaprequest
.window
);
453 if ((win
= searchWindow(e
->xmaprequest
.window
)))
454 win
->mapRequestEvent(&e
->xmaprequest
);
460 OpenboxWindow
*win
= searchWindow(e
->xmap
.window
);
463 win
->mapNotifyEvent(&e
->xmap
);
469 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
472 Slit
*slit
= (Slit
*) 0;
475 if ((win
= searchWindow(e
->xunmap
.window
))) {
476 win
->unmapNotifyEvent(&e
->xunmap
);
478 } else if ((slit
= searchSlit(e
->xunmap
.window
))) {
479 slit
->removeClient(e
->xunmap
.window
);
487 case DestroyNotify
: {
488 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
491 Slit
*slit
= (Slit
*) 0;
494 if ((win
= searchWindow(e
->xdestroywindow
.window
))) {
495 win
->destroyNotifyEvent(&e
->xdestroywindow
);
497 } else if ((slit
= searchSlit(e
->xdestroywindow
.window
))) {
498 slit
->removeClient(e
->xdestroywindow
.window
, False
);
506 // strip the lock key modifiers
507 e
->xbutton
.state
&= ~(NumLockMask
| ScrollLockMask
| LockMask
);
509 last_time
= e
->xmotion
.time
;
511 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
512 Basemenu
*menu
= (Basemenu
*) 0;
514 if ((win
= searchWindow(e
->xmotion
.window
)))
515 win
->motionNotifyEvent(&e
->xmotion
);
516 else if ((menu
= searchMenu(e
->xmotion
.window
)))
517 menu
->motionNotifyEvent(&e
->xmotion
);
522 case PropertyNotify
: {
523 last_time
= e
->xproperty
.time
;
525 if (e
->xproperty
.state
!= PropertyDelete
) {
526 OpenboxWindow
*win
= searchWindow(e
->xproperty
.window
);
529 win
->propertyNotifyEvent(e
->xproperty
.atom
);
536 last_time
= e
->xcrossing
.time
;
538 BScreen
*screen
= (BScreen
*) 0;
539 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
540 Basemenu
*menu
= (Basemenu
*) 0;
541 Toolbar
*tbar
= (Toolbar
*) 0;
544 Slit
*slit
= (Slit
*) 0;
547 if (e
->xcrossing
.mode
== NotifyGrab
) break;
551 sa
.w
= e
->xcrossing
.window
;
552 sa
.enter
= sa
.leave
= False
;
553 XCheckIfEvent(getXDisplay(), &dummy
, queueScanner
, (char *) &sa
);
555 if ((e
->xcrossing
.window
== e
->xcrossing
.root
) &&
556 (screen
= searchScreen(e
->xcrossing
.window
))) {
557 screen
->getImageControl()->installRootColormap();
558 } else if ((win
= searchWindow(e
->xcrossing
.window
))) {
559 if (win
->getScreen()->sloppyFocus() &&
560 (! win
->isFocused()) && (! no_focus
)) {
563 if (((! sa
.leave
) || sa
.inferior
) && win
->isVisible() &&
564 win
->setInputFocus())
565 win
->installColormap(True
);
569 } else if ((menu
= searchMenu(e
->xcrossing
.window
))) {
570 menu
->enterNotifyEvent(&e
->xcrossing
);
571 } else if ((tbar
= searchToolbar(e
->xcrossing
.window
))) {
572 tbar
->enterNotifyEvent(&e
->xcrossing
);
574 } else if ((slit
= searchSlit(e
->xcrossing
.window
))) {
575 slit
->enterNotifyEvent(&e
->xcrossing
);
582 last_time
= e
->xcrossing
.time
;
584 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
585 Basemenu
*menu
= (Basemenu
*) 0;
586 Toolbar
*tbar
= (Toolbar
*) 0;
589 Slit
*slit
= (Slit
*) 0;
592 if ((menu
= searchMenu(e
->xcrossing
.window
)))
593 menu
->leaveNotifyEvent(&e
->xcrossing
);
594 else if ((win
= searchWindow(e
->xcrossing
.window
)))
595 win
->installColormap(False
);
596 else if ((tbar
= searchToolbar(e
->xcrossing
.window
)))
597 tbar
->leaveNotifyEvent(&e
->xcrossing
);
599 else if ((slit
= searchSlit(e
->xcrossing
.window
)))
600 slit
->leaveNotifyEvent(&e
->xcrossing
);
607 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
608 Basemenu
*menu
= (Basemenu
*) 0;
609 Toolbar
*tbar
= (Toolbar
*) 0;
611 if ((win
= searchWindow(e
->xexpose
.window
)))
612 win
->exposeEvent(&e
->xexpose
);
613 else if ((menu
= searchMenu(e
->xexpose
.window
)))
614 menu
->exposeEvent(&e
->xexpose
);
615 else if ((tbar
= searchToolbar(e
->xexpose
.window
)))
616 tbar
->exposeEvent(&e
->xexpose
);
622 Toolbar
*tbar
= searchToolbar(e
->xkey
.window
);
624 if (tbar
&& tbar
->isEditing())
625 tbar
->keyPressEvent(&e
->xkey
);
630 case ColormapNotify
: {
631 BScreen
*screen
= searchScreen(e
->xcolormap
.window
);
634 screen
->setRootColormapInstalled((e
->xcolormap
.state
==
635 ColormapInstalled
) ? True
: False
);
641 if (e
->xfocus
.mode
== NotifyUngrab
|| e
->xfocus
.detail
== NotifyPointer
)
644 OpenboxWindow
*win
= searchWindow(e
->xfocus
.window
);
645 if (win
&& !win
->isFocused())
654 case ClientMessage
: {
655 if (e
->xclient
.format
== 32) {
656 if (e
->xclient
.message_type
== getWMChangeStateAtom()) {
657 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
658 if (! win
|| ! win
->validateClient()) return;
660 if (e
->xclient
.data
.l
[0] == IconicState
)
662 if (e
->xclient
.data
.l
[0] == NormalState
)
664 } else if (e
->xclient
.message_type
== getOpenboxChangeWorkspaceAtom()) {
665 BScreen
*screen
= searchScreen(e
->xclient
.window
);
667 if (screen
&& e
->xclient
.data
.l
[0] >= 0 &&
668 e
->xclient
.data
.l
[0] < screen
->getWorkspaceCount())
669 screen
->changeWorkspaceID(e
->xclient
.data
.l
[0]);
670 } else if (e
->xclient
.message_type
== getOpenboxChangeWindowFocusAtom()) {
671 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
673 if (win
&& win
->isVisible() && win
->setInputFocus())
674 win
->installColormap(True
);
675 } else if (e
->xclient
.message_type
== getOpenboxCycleWindowFocusAtom()) {
676 BScreen
*screen
= searchScreen(e
->xclient
.window
);
679 if (! e
->xclient
.data
.l
[0])
684 } else if (e
->xclient
.message_type
== getOpenboxChangeAttributesAtom()) {
685 OpenboxWindow
*win
= searchWindow(e
->xclient
.window
);
687 if (win
&& win
->validateClient()) {
689 net
.flags
= e
->xclient
.data
.l
[0];
690 net
.attrib
= e
->xclient
.data
.l
[1];
691 net
.workspace
= e
->xclient
.data
.l
[2];
692 net
.stack
= e
->xclient
.data
.l
[3];
693 net
.decoration
= e
->xclient
.data
.l
[4];
695 win
->changeOpenboxHints(&net
);
706 if (e
->type
== getShapeEventBase()) {
707 XShapeEvent
*shape_event
= (XShapeEvent
*) e
;
708 OpenboxWindow
*win
= (OpenboxWindow
*) 0;
710 if ((win
= searchWindow(e
->xany
.window
)) ||
711 (shape_event
->kind
!= ShapeBounding
))
712 win
->shapeEvent(shape_event
);
721 Bool
Openbox::handleSignal(int sig
) {
747 BScreen
*Openbox::searchScreen(Window window
) {
748 ScreenList::iterator it
;
749 for (it
= screenList
.begin(); it
!= screenList
.end(); ++it
)
750 if ((*it
)->getRootWindow() == window
)
752 return (BScreen
*) 0;
756 OpenboxWindow
*Openbox::searchWindow(Window window
) {
757 WindowLookup::iterator it
= windowSearchList
.find(window
);
758 if (it
== windowSearchList
.end())
759 return (OpenboxWindow
*) 0;
764 OpenboxWindow
*Openbox::searchGroup(Window window
, OpenboxWindow
*win
) {
765 WindowLookup::iterator it
= groupSearchList
.find(window
);
766 if (it
!= groupSearchList
.end())
767 if (it
->second
->getClientWindow() != win
->getClientWindow())
769 return (OpenboxWindow
*) 0;
773 Basemenu
*Openbox::searchMenu(Window window
) {
774 MenuLookup::iterator it
= menuSearchList
.find(window
);
775 if (it
== menuSearchList
.end())
776 return (Basemenu
*) 0;
781 Toolbar
*Openbox::searchToolbar(Window window
) {
782 ToolbarLookup::iterator it
= toolbarSearchList
.find(window
);
783 if (it
== toolbarSearchList
.end())
784 return (Toolbar
*) 0;
790 Slit
*Openbox::searchSlit(Window window
) {
791 SlitLookup::iterator it
= slitSearchList
.find(window
);
792 if (it
== slitSearchList
.end())
799 void Openbox::saveWindowSearch(Window window
, OpenboxWindow
*data
) {
800 windowSearchList
.insert(WindowLookupPair(window
, data
));
804 void Openbox::saveGroupSearch(Window window
, OpenboxWindow
*data
) {
805 groupSearchList
.insert(WindowLookupPair(window
, data
));
809 void Openbox::saveMenuSearch(Window window
, Basemenu
*data
) {
810 menuSearchList
.insert(MenuLookupPair(window
, data
));
814 void Openbox::saveToolbarSearch(Window window
, Toolbar
*data
) {
815 toolbarSearchList
.insert(ToolbarLookupPair(window
, data
));
820 void Openbox::saveSlitSearch(Window window
, Slit
*data
) {
821 slitSearchList
.insert(SlitLookupPair(window
, data
));
826 void Openbox::removeWindowSearch(Window window
) {
827 windowSearchList
.erase(window
);
831 void Openbox::removeGroupSearch(Window window
) {
832 groupSearchList
.erase(window
);
836 void Openbox::removeMenuSearch(Window window
) {
837 menuSearchList
.erase(window
);
841 void Openbox::removeToolbarSearch(Window window
) {
842 toolbarSearchList
.erase(window
);
847 void Openbox::removeSlitSearch(Window window
) {
848 slitSearchList
.erase(window
);
853 void Openbox::restart(const char *prog
) {
857 execlp(prog
, prog
, NULL
);
861 // fall back in case the above execlp doesn't work
862 execvp(argv
[0], argv
);
863 execvp(basename(argv
[0]), argv
);
867 void Openbox::shutdown() {
868 BaseDisplay::shutdown();
870 focusWindow((OpenboxWindow
*) 0);
872 std::for_each(screenList
.begin(), screenList
.end(),
873 std::mem_fun(&BScreen::shutdown
));
875 XSync(getXDisplay(), False
);
879 void Openbox::save() {
880 config
.setAutoSave(false);
882 // save all values as they are so that the defaults will be written to the rc
885 config
.setValue("session.menuFile", getMenuFilename());
886 config
.setValue("session.colorsPerChannel",
887 resource
.colors_per_channel
);
888 config
.setValue("session.styleFile", resource
.style_file
);
889 config
.setValue("session.titlebarLayout", resource
.titlebar_layout
);
890 config
.setValue("session.doubleClickInterval",
891 (long)resource
.double_click_interval
);
892 config
.setValue("session.autoRaiseDelay",
893 ((resource
.auto_raise_delay
.tv_sec
* 1000) +
894 (resource
.auto_raise_delay
.tv_usec
/ 1000)));
895 config
.setValue("session.cacheLife", (long)resource
.cache_life
/ 60000);
896 config
.setValue("session.cacheMax", (long)resource
.cache_max
);
898 std::for_each(screenList
.begin(), screenList
.end(),
899 std::mem_fun(&BScreen::save
));
901 config
.setAutoSave(true);
905 void Openbox::load() {
912 if (resource
.menu_file
)
913 delete [] resource
.menu_file
;
914 if (config
.getValue("session.menuFile", "Session.MenuFile", s
))
915 resource
.menu_file
= bstrdup(s
.c_str());
917 resource
.menu_file
= bstrdup(DEFAULTMENU
);
919 if (config
.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
921 resource
.colors_per_channel
= (l
< 2 ? 2 : (l
> 6 ? 6 : l
)); // >= 2, <= 6
923 resource
.colors_per_channel
= 4;
925 if (resource
.style_file
)
926 delete [] resource
.style_file
;
927 if (config
.getValue("session.styleFile", "Session.StyleFile", s
))
928 resource
.style_file
= bstrdup(s
.c_str());
930 resource
.style_file
= bstrdup(DEFAULTSTYLE
);
932 if (resource
.titlebar_layout
)
933 delete [] resource
.titlebar_layout
;
934 if (config
.getValue("session.titlebarLayout", "Session.TitlebarLayout", s
))
935 resource
.titlebar_layout
= bstrdup(s
.c_str());
937 resource
.titlebar_layout
= bstrdup("ILMC");
939 if (config
.getValue("session.doubleClickInterval",
940 "Session.DoubleClickInterval", l
))
941 resource
.double_click_interval
= l
;
943 resource
.double_click_interval
= 250;
945 if (!config
.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l
))
946 resource
.auto_raise_delay
.tv_usec
= l
;
948 resource
.auto_raise_delay
.tv_usec
= 400;
949 resource
.auto_raise_delay
.tv_sec
= resource
.auto_raise_delay
.tv_usec
/ 1000;
950 resource
.auto_raise_delay
.tv_usec
-=
951 (resource
.auto_raise_delay
.tv_sec
* 1000);
952 resource
.auto_raise_delay
.tv_usec
*= 1000;
954 if (config
.getValue("session.cacheLife", "Session.CacheLife", l
))
955 resource
.cache_life
= l
;
957 resource
.cache_life
= 51;
958 resource
.cache_life
*= 60000;
960 if (config
.getValue("session.cacheMax", "Session.CacheMax", l
))
961 resource
.cache_max
= l
;
963 resource
.cache_max
= 200;
967 void Openbox::reconfigure() {
968 reconfigure_wait
= True
;
970 if (! timer
->isTiming()) timer
->start();
974 void Openbox::real_reconfigure() {
979 for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
981 menuTimestamps
.clear();
983 std::for_each(screenList
.begin(), screenList
.end(),
984 std::mem_fun(&BScreen::reconfigure
));
990 void Openbox::checkMenu() {
991 MenuTimestampList::iterator it
;
992 for (it
= menuTimestamps
.begin(); it
!= menuTimestamps
.end(); ++it
) {
995 if (stat((*it
)->filename
, &buf
) || (*it
)->timestamp
!= buf
.st_ctime
) {
1003 void Openbox::rereadMenu() {
1004 reread_menu_wait
= True
;
1006 if (! timer
->isTiming()) timer
->start();
1010 void Openbox::real_rereadMenu() {
1011 std::for_each(menuTimestamps
.begin(), menuTimestamps
.end(),
1013 menuTimestamps
.clear();
1015 std::for_each(screenList
.begin(), screenList
.end(),
1016 std::mem_fun(&BScreen::rereadMenu
));
1020 void Openbox::setStyleFilename(const char *filename
) {
1021 if (resource
.style_file
)
1022 delete [] resource
.style_file
;
1024 resource
.style_file
= bstrdup(filename
);
1025 config
.setValue("session.styleFile", resource
.style_file
);
1029 void Openbox::setMenuFilename(const char *filename
) {
1032 MenuTimestampList::iterator it
;
1033 for (it
= menuTimestamps
.begin(); it
!= menuTimestamps
.end(); ++it
)
1034 if (! strcmp((*it
)->filename
, filename
)) {
1041 if (! stat(filename
, &buf
)) {
1042 MenuTimestamp
*ts
= new MenuTimestamp
;
1044 ts
->filename
= bstrdup(filename
);
1045 ts
->timestamp
= buf
.st_ctime
;
1047 menuTimestamps
.push_back(ts
);
1053 void Openbox::timeout() {
1054 if (reconfigure_wait
)
1057 if (reread_menu_wait
)
1060 reconfigure_wait
= reread_menu_wait
= False
;
1064 OpenboxWindow
*Openbox::focusedWindow() {
1065 if (focused_screen
== (BScreen
*) 0)
1066 return (OpenboxWindow
*) 0;
1067 Workspace
*w
= focused_screen
->getCurrentWorkspace();
1068 if (w
== (Workspace
*) 0)
1069 return (OpenboxWindow
*) 0;
1070 return w
->focusedWindow();
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 focused_screen
= win
->getScreen();
1091 tbar
= focused_screen
->getToolbar();
1092 wkspc
= focused_screen
->getWorkspace(win
->getWorkspaceNumber());
1093 win
->setFocusFlag(true);
1094 wkspc
->focusWindow(win
);
1097 tbar
->redrawWindowLabel(true);
1098 focused_screen
->updateNetizenWindowFocus();
1100 ASSERT(focused_screen
!= (BScreen
*) 0);
1101 XSetInputFocus(getXDisplay(), focused_screen
->getRootWindow(),
1105 if (old_tbar
&& old_tbar
!= tbar
)
1106 old_tbar
->redrawWindowLabel(true);
1107 if (old_screen
&& old_screen
!= focused_screen
)
1108 old_screen
->updateNetizenWindowFocus();